From 3be92856b5810cfc4df981a489e34ed0c43bb2a5 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 26 Oct 2019 12:42:07 +0530 Subject: [PATCH] MM-19172: Add golangci-lint to the CI pipeline (#12909) To start off with, we are using the new-from-rev=HEAD~ option which just checks the current commit. This allows us to quickly integrate golangci-lint and not spend time in fixing all the outstanding issues. Things pending: - Slowly fix the existing issues. To test them, just uncomment the "new-from-rev: HEAD~" line from .golangci.yml and have at it. - There are a number of unused functions and methods which are only invoked from enterprise code. We are ignoring them for now because removing them will stop enterprise build from working. The correct solution here is to use a build tag to separate TE and EE code. As a long term goal, we would want to use that build tag throughout the EE codebase and remove the TE_PACKAGES and EE_PACKAGES variables in the Makefile and just use the build tag. That makes things a lot cleaner and avoids the need to spawn a "go list" every time to get the correct list of packages. --- .golangci.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 13 +++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000000..0f14da58b6 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +run: + timeout: 5m + modules-download-mode: vendor + +linters-settings: + govet: + check-shadowing: true + +linters: + disable-all: true + enable: + - deadcode + - gofmt + - gosimple + - govet + - ineffassign + - structcheck + - unconvert + - unused + - varcheck + # TODO: enable this later + # - errcheck + +issues: + exclude-rules: + - linters: + # ignore unused warnings from enterprise code + # add more as required. + - unused + text: "RedisSupplier|LocalCacheSupplier|Enterprise" diff --git a/Makefile b/Makefile index f799b8e966..5b159471d0 100644 --- a/Makefile +++ b/Makefile @@ -173,6 +173,18 @@ gofmt: ## Runs gofmt against all packages. done @echo "gofmt success"; \ +golangci-lint: +# https://stackoverflow.com/a/677212/1027058 (check if a command exists or not) +# https://github.com/golangci/golangci-lint#binary-release +# It is recommended to NOT use go get, but instead use a binary release pinned to a version. + @if ! [ -x "$$(command -v golangci-lint)" ]; then \ + echo "golangci-lint is not installed. Please run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $(GOPATH)/bin v1.21.0"; \ + exit 1; \ + fi; \ + + @echo Running golangci-lint + $(GOPATH)/bin/golangci-lint run + megacheck: ## Run megacheck on codebasis env GO111MODULE=off go get -u honnef.co/go/tools/cmd/megacheck $(GOPATH)/bin/megacheck $(TE_PACKAGES) @@ -219,6 +231,7 @@ check-licenses: ## Checks license status. check-prereqs: ## Checks prerequisite software status. ./scripts/prereq-check.sh +# TODO: remove govet and gofmt checks once golangci-lint is being enforced. check-style: govet gofmt check-licenses ## Runs govet and gofmt against all packages. test-te-race: ## Checks for race conditions in the team edition.