Chore: Add Makefile target to efficiently lint only locally changed Go files (#94228)

* add Makefile target to efficiently lint only locally changed files

* fix xargs usage; only run if Go files changed
pull/94405/head
Diego Augusto Molina 7 months ago committed by GitHub
parent 84554735b0
commit 0cc90f2492
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      Makefile

@ -18,6 +18,9 @@ GO_BUILD_FLAGS += $(if $(GO_BUILD_DEV),-dev)
GO_BUILD_FLAGS += $(if $(GO_BUILD_TAGS),-build-tags=$(GO_BUILD_TAGS))
GO_BUILD_FLAGS += $(GO_RACE_FLAG)
# GNU xargs has flag -r, and BSD xargs (e.g. MacOS) has that behaviour by default
XARGSR = $(shell xargs --version 2>&1 | grep -q GNU && echo xargs -r || echo xargs)
targets := $(shell echo '$(sources)' | tr "," " ")
GO_INTEGRATION_TESTS := $(shell find ./pkg -type f -name '*_test.go' -exec grep -l '^func TestIntegration' '{}' '+' | grep -o '\(.*\)/' | sort -u)
@ -303,6 +306,15 @@ golangci-lint: $(GOLANGCI_LINT)
.PHONY: lint-go
lint-go: golangci-lint ## Run all code checks for backend. You can use GO_LINT_FILES to specify exact files to check
.PHONY: lint-go-diff
lint-go-diff: $(GOLANGCI_LINT)
git diff --name-only remotes/origin/main | \
grep '\.go$$' | \
$(XARGSR) dirname | \
sort -u | \
sed 's,^,./,' | \
$(XARGSR) $(GOLANGCI_LINT) run --config .golangci.toml
# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts
.PHONY: shellcheck
shellcheck: $(SH_FILES) ## Run checks for shell scripts.

Loading…
Cancel
Save