Build: use golangci-lint as a make command (#17739)

* Build: use golangci-lint as a make command

* Since gometalinter was deprecated in favor of golangci-lint so it was
  replaced by it. Responsibilities held by the gometalinter was moved to
  golangci-lint

* There was some changes in implementation (that was also mentioned in
  the code comment) between the tools, which uncovered couple errors
  in the code. Those issues were either solved or disabled by
  the inline comments

* Introduce the golangci-lint config, to make their
  configuration more manageable

* Build: replace backend-lint.sh script with make
This commit is contained in:
Oleg Gaidarenko
2019-07-02 16:06:59 +03:00
committed by GitHub
parent 364f1f2e55
commit caa1314f44
20 changed files with 278 additions and 85 deletions

View File

@@ -1,6 +1,6 @@
-include local/Makefile
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go test-go test-js test run clean gosec revive devenv devenv-down revive-alerting
.PHONY: all deps-go deps-js deps build-go build-server build-cli build-js build build-docker-dev build-docker-full lint-go gosec revive golangci-lint go-vet test-go test-js test run clean devenv devenv-down revive-alerting
GO := GO111MODULE=on go
GO_FILES := ./pkg/...
@@ -43,10 +43,6 @@ build-docker-full:
@echo "build docker container"
docker build --tag grafana/grafana:dev .
lint-go:
@echo "lint go source"
scripts/backend-lint.sh
test-go:
@echo "test backend"
GO111MODULE=on go test -v ./pkg/...
@@ -78,27 +74,46 @@ scripts/go/bin/bra: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/bra github.com/Unknwon/bra
scripts/go/bin/golangci-lint: scripts/go/go.mod
@cd scripts/go; \
$(GO) build -o ./bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
revive: scripts/go/bin/revive
@echo "lint via revive"
@scripts/go/bin/revive \
-formatter stylish \
-config ./scripts/go/configs/revive.toml \
$(GO_FILES)
revive-alerting: scripts/go/bin/revive
@echo "lint alerting via revive"
@scripts/go/bin/revive \
-formatter stylish \
./pkg/services/alerting/...
run: scripts/go/bin/bra
@scripts/go/bin/bra run
# TODO recheck the rules and leave only necessary exclusions
gosec: scripts/go/bin/gosec
@echo "lint via gosec"
@scripts/go/bin/gosec -quiet \
-exclude=G104,G107,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json \
$(GO_FILES)
golangci-lint: scripts/go/bin/golangci-lint
@echo "lint via golangci-lint"
@scripts/go/bin/golangci-lint run \
--config ./scripts/go/configs/.golangci.yml \
$(GO_FILES)
go-vet:
@echo "lint via go vet"
@go vet $(GO_FILES)
lint-go: go-vet golangci-lint revive revive-alerting gosec
run: scripts/go/bin/bra
@scripts/go/bin/bra run
# create docker-compose file with provided sources and start them
# example: make devenv sources=postgres,openldap
ifeq ($(sources),)