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.
Этот коммит содержится в:
Agniva De Sarker
2019-10-26 12:42:07 +05:30
коммит произвёл Ben Schumacher
родитель 37e0424977
Коммит 3be92856b5
2 изменённых файлов: 43 добавлений и 0 удалений

30
.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"

Просмотреть файл

@@ -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.