diff --git a/.circleci/config.yml b/.circleci/config.yml index 5d4f78d5c..97f9319a6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -71,6 +71,14 @@ commands: paths: - 'dist' jobs: + linter: + executor: go-1_15 + steps: + - checkout + - restore_cache: + key: go-mod-v1-{{ checksum "go.sum" }} + - run: wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.37.0 + - run: make lint deps: executor: go-1_15 steps: @@ -178,6 +186,7 @@ workflows: version: 2 check: jobs: + - 'linter' - 'macdeps': filters: tags: @@ -246,6 +255,7 @@ workflows: - 'release' nightly: jobs: + - 'linter' - 'deps' - 'macdeps' - 'test-go-1_14': diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 000000000..fa95d656f --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,44 @@ +linters: + enable: + - revive + +linters-settings: + revive: + rules: + - name: blank-imports + - name: context-as-argument + - name: context-keys-type + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: var-declaration + - name: package-comments + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + - name: indent-error-flow + - name: errorf + - name: empty-block + - name: superfluous-else + - name: unused-parameter + - name: unreachable-code + - name: redefines-builtin-id + +run: + skip-dirs: + - scripts + - docs + - etc + skip-files: + - plugins/parsers/influx/machine.go* + +issues: + exclude: + - don't use an underscore in package name + - exported.*should have comment.*or be unexported diff --git a/Makefile b/Makefile index 06b0cd7b4..3c6e5f029 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,7 @@ help: @echo ' test - run short unit tests' @echo ' fmt - format source files' @echo ' tidy - tidy go modules' + @echo ' lint - run linter' @echo ' check-deps - check docs/LICENSE_OF_DEPENDENCIES.md' @echo ' clean - delete build artifacts' @echo '' @@ -130,6 +131,15 @@ vet: exit 1; \ fi +.PHONY: lint +lint: +ifeq (, $(shell which golangci-lint)) + $(info golangci-lint can't be found, please install it: https://golangci-lint.run/usage/install/) + exit 1 +endif + + golangci-lint run --timeout 5m0s --issues-exit-code 0 + .PHONY: tidy tidy: go mod verify