mirror of https://github.com/status-im/consul.git
ci: Use golangci-lint for linting
Using golangci-lint has a number of advantages: - adding new linters becomes much easier, its a couple lines of yaml config instead of more bash scripting - it enables whitelisting of issues using inline comments or regex - when running multiple linters less work is done. The parsed source can be reused by multiple linters - linters are run in parallel to reduce CI runtime.
This commit is contained in:
parent
5c7b3762e3
commit
3f8578f1e1
|
@ -33,30 +33,30 @@ jobs:
|
||||||
- checkout
|
- checkout
|
||||||
- run: go get -u github.com/hashicorp/lint-consul-retry && lint-consul-retry
|
- run: go get -u github.com/hashicorp/lint-consul-retry && lint-consul-retry
|
||||||
|
|
||||||
# Runs go fmt and go vet
|
# Runs Go linters
|
||||||
go-fmt-and-vet:
|
lint:
|
||||||
docker:
|
docker:
|
||||||
- image: *GOLANG_IMAGE
|
- image: *GOLANG_IMAGE
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run:
|
- run:
|
||||||
command: go mod download
|
name: Install golangci-lint
|
||||||
- run:
|
|
||||||
name: check go fmt
|
|
||||||
command: |
|
command: |
|
||||||
files="$(go fmt ./... ; (cd api && go fmt ./... | sed 's@^@api/@') ; (cd sdk && go fmt ./... | sed 's@^@sdk/@'))"
|
download=https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh
|
||||||
if [ -n "$files" ]; then
|
wget -O- -q $download | sh -s -- -b /go/bin/ v1.23.6
|
||||||
echo "The following file(s) do not conform to go fmt:"
|
- run: go mod download
|
||||||
echo "$files"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
- run:
|
- run:
|
||||||
command: |
|
name: lint
|
||||||
go vet ./... && \
|
command: &lintcmd |
|
||||||
(cd api && go vet ./...) && \
|
golangci-lint run -v --concurrency 2
|
||||||
(cd sdk && go vet ./...)
|
- run:
|
||||||
environment:
|
name: lint api
|
||||||
<<: *ENVIRONMENT
|
working_directory: api
|
||||||
|
command: *lintcmd
|
||||||
|
- run:
|
||||||
|
name: lint sdk
|
||||||
|
working_directory: sdk
|
||||||
|
command: *lintcmd
|
||||||
|
|
||||||
# checks vendor directory is correct
|
# checks vendor directory is correct
|
||||||
check-vendor:
|
check-vendor:
|
||||||
|
@ -619,15 +619,13 @@ workflows:
|
||||||
- stable-website
|
- stable-website
|
||||||
- /^docs\/.*/
|
- /^docs\/.*/
|
||||||
- /^ui\/.*/
|
- /^ui\/.*/
|
||||||
- go-fmt-and-vet:
|
- lint
|
||||||
requires:
|
- dev-build
|
||||||
- check-vendor
|
|
||||||
- dev-build:
|
|
||||||
requires:
|
|
||||||
- go-fmt-and-vet
|
|
||||||
- go-test: &go-test
|
- go-test: &go-test
|
||||||
requires:
|
requires:
|
||||||
- dev-build
|
- dev-build
|
||||||
|
- lint
|
||||||
|
- check-vendor
|
||||||
- go-test-api: *go-test
|
- go-test-api: *go-test
|
||||||
- go-test-sdk: *go-test
|
- go-test-sdk: *go-test
|
||||||
- coverage-merge:
|
- coverage-merge:
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- gofmt
|
||||||
|
- govet
|
||||||
|
|
||||||
|
issues:
|
||||||
|
# Disable the default exclude list so that all excludes are explicitly
|
||||||
|
# defined in this file.
|
||||||
|
exclude-use-default: false
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
gofmt:
|
||||||
|
simplify: false
|
|
@ -7,7 +7,8 @@ GOTOOLS = \
|
||||||
golang.org/x/tools/cmd/stringer \
|
golang.org/x/tools/cmd/stringer \
|
||||||
github.com/gogo/protobuf/protoc-gen-gofast@$(GOGOVERSION) \
|
github.com/gogo/protobuf/protoc-gen-gofast@$(GOGOVERSION) \
|
||||||
github.com/hashicorp/protoc-gen-go-binary \
|
github.com/hashicorp/protoc-gen-go-binary \
|
||||||
github.com/vektra/mockery/cmd/mockery
|
github.com/vektra/mockery/cmd/mockery \
|
||||||
|
github.com/golangci/golangci-lint/cmd/golangci-lint@v1.23.6
|
||||||
|
|
||||||
GOTAGS ?=
|
GOTAGS ?=
|
||||||
GOOS?=$(shell go env GOOS)
|
GOOS?=$(shell go env GOOS)
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../.golangci.yml
|
|
@ -0,0 +1 @@
|
||||||
|
../.golangci.yml
|
Loading…
Reference in New Issue