github.com/newrelic/newrelic-client-go@v1.1.0/build/lint.mk (about) 1 # 2 # Makefile fragment for Linting 3 # 4 5 GO ?= go 6 MISSPELL ?= misspell 7 GOFMT ?= gofmt 8 GOIMPORTS ?= goimports 9 10 COMMIT_LINT_CMD ?= go-gitlint 11 COMMIT_LINT_REGEX ?= "(chore|docs|feat|fix|refactor|tests?)(\([^\)]+\))?!?: .*" 12 COMMIT_LINT_START ?= "2020-06-17" 13 14 GOLINTER = golangci-lint 15 16 EXCLUDEDIR ?= .git 17 SRCDIR ?= . 18 GO_PKGS ?= $(shell ${GO} list ./... | grep -v -e "/vendor/" -e "/example") 19 FILES ?= $(shell find ${SRCDIR} -type f | grep -v -e '.git/' -e '/vendor/' -e 'go.sum') 20 GO_FILES ?= $(shell find $(SRCDIR) -type f -name "*.go" | grep -v -e ".git/" -e '/vendor/' -e '/example/') 21 PROJECT_MODULE ?= $(shell $(GO) list -m) 22 23 GO_MOD_OUTDATED ?= go-mod-outdated 24 25 lint: deps spell-check gofmt lint-commit golangci goimports outdated 26 lint-fix: deps spell-check-fix gofmt-fix goimports 27 28 # 29 # Check spelling on all the files, not just source code 30 # 31 spell-check: deps 32 @echo "=== $(PROJECT_NAME) === [ spell-check ]: Checking for spelling mistakes with $(MISSPELL)..." 33 @$(MISSPELL) -source text $(FILES) 34 35 spell-check-fix: deps 36 @echo "=== $(PROJECT_NAME) === [ spell-check-fix ]: Fixing spelling mistakes with $(MISSPELL)..." 37 @$(MISSPELL) -source text -w $(FILES) 38 39 gofmt: deps 40 @echo "=== $(PROJECT_NAME) === [ gofmt ]: Checking file format with $(GOFMT)..." 41 @find . -path "$(EXCLUDEDIR)" -prune -print0 | xargs -0 $(GOFMT) -e -l -s -d ${SRCDIR} 42 43 gofmt-fix: deps 44 @echo "=== $(PROJECT_NAME) === [ gofmt-fix ]: Fixing file format with $(GOFMT)..." 45 @find . -path "$(EXCLUDEDIR)" -prune -print0 | xargs -0 $(GOFMT) -e -l -s -w ${SRCDIR} 46 47 goimports: deps 48 @echo "=== $(PROJECT_NAME) === [ goimports ]: Checking imports with $(GOIMPORTS)..." 49 @$(GOIMPORTS) -w -local $(PROJECT_MODULE) $(GO_FILES) 50 51 lint-commit: deps 52 @echo "=== $(PROJECT_NAME) === [ lint-commit ]: Checking that commit messages are properly formatted ($(COMMIT_LINT_CMD))..." 53 @$(COMMIT_LINT_CMD) --since=$(COMMIT_LINT_START) --subject-minlen=10 --subject-maxlen=120 --subject-regex=$(COMMIT_LINT_REGEX) 54 55 golangci: deps 56 @echo "=== $(PROJECT_NAME) === [ golangci-lint ]: Linting using $(GOLINTER) ($(COMMIT_LINT_CMD))..." 57 @$(GOLINTER) run 58 59 outdated: deps tools-outdated 60 @echo "=== $(PROJECT_NAME) === [ outdated ]: Finding outdated deps with $(GO_MOD_OUTDATED)..." 61 @$(GO) list -u -m -json all | $(GO_MOD_OUTDATED) -direct -update 62 63 .PHONY: lint spell-check spell-check-fix gofmt gofmt-fix lint-fix lint-commit outdated goimports