From 0cc90f2492aa9b630edad39dd2b3e12ac42b9c65 Mon Sep 17 00:00:00 2001 From: Diego Augusto Molina Date: Tue, 8 Oct 2024 12:47:33 +0000 Subject: [PATCH] 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 --- Makefile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Makefile b/Makefile index 6f61e20a974..9346e4b9b10 100644 --- a/Makefile +++ b/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.