Browse Source

*: enable golangci-lint (#5437)

* *: enable golangci-lint

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Remove freebsd from supported platforms for lint

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Update CONTRIBUTING.md

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Update CONTRIBUTING.md

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* Add common-staticcheck for compatibility

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
pull/5502/head
Simon Pasquier 6 years ago committed by GitHub
parent
commit
f5d54e5be6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .circleci/config.yml
  2. 1
      .gitignore
  3. 8
      .golangci.yml
  4. 2
      .travis.yml
  5. 2
      CONTRIBUTING.md
  6. 4
      Makefile
  7. 36
      Makefile.common

2
.circleci/config.yml

@ -15,7 +15,7 @@ jobs:
steps: steps:
- checkout - checkout
- run: make promu - run: make promu
- run: make check_license style unused staticcheck build check_assets - run: make check_license style unused lint build check_assets
- run: - run:
command: | command: |
curl -s -L https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip > /tmp/protoc.zip curl -s -L https://github.com/protocolbuffers/protobuf/releases/download/v3.5.1/protoc-3.5.1-linux-x86_64.zip > /tmp/protoc.zip

1
.gitignore vendored

@ -13,5 +13,6 @@ benchmark.txt
!/.travis.yml !/.travis.yml
!/.promu.yml !/.promu.yml
!/.golangci.yml
/documentation/examples/remote_storage/remote_storage_adapter/remote_storage_adapter /documentation/examples/remote_storage/remote_storage_adapter/remote_storage_adapter
/documentation/examples/remote_storage/example_write_adapter/example_writer_adapter /documentation/examples/remote_storage/example_write_adapter/example_writer_adapter

8
.golangci.yml

@ -0,0 +1,8 @@
run:
modules-download-mode: vendor
# Run only staticcheck for now. Additional linters will be enabled one-by-one.
linters:
enable:
- staticcheck
disable-all: true

2
.travis.yml

@ -14,5 +14,5 @@ before_install:
- travis_retry make deps - travis_retry make deps
script: script:
- make check_license style unused test staticcheck check_assets - make check_license style unused test lint check_assets
- git diff --exit-code - git diff --exit-code

2
CONTRIBUTING.md

@ -40,6 +40,8 @@ go build ./cmd/prometheus/
make test # Make sure all the tests pass before you commit and push :) make test # Make sure all the tests pass before you commit and push :)
``` ```
We use `golangci-lint`[https://github.com/golangci/golangci-lint] for linting the code. If it reports an issue and you think that the warning needs to be disregarded or is a false-positive, you can add a special comment `//nolint:linter1[,linter2,...]` before the offending line. Use this sparingly though, fixing the code to comply with the linter's recommendation is in general the preferred course of action.
All our issues are regularly tagged so that you can also filter down the issues involving the components you want to work on. For our labeling policy refer [the wiki page](https://github.com/prometheus/prometheus/wiki/Label-Names-and-Descriptions). All our issues are regularly tagged so that you can also filter down the issues involving the components you want to work on. For our labeling policy refer [the wiki page](https://github.com/prometheus/prometheus/wiki/Label-Names-and-Descriptions).
## Pull Request Checklist ## Pull Request Checklist

4
Makefile

@ -16,10 +16,6 @@ DOCKER_ARCHS ?= amd64 armv7 arm64
include Makefile.common include Makefile.common
STATICCHECK_IGNORE = \
github.com/prometheus/prometheus/pkg/textparse/promlex.l.go:SA4006 \
github.com/prometheus/prometheus/pkg/textparse/openmetricslex.l.go:SA4006
DOCKER_IMAGE_NAME ?= prometheus DOCKER_IMAGE_NAME ?= prometheus
.PHONY: assets .PHONY: assets

36
Makefile.common

@ -72,14 +72,13 @@ endif
PROMU_VERSION ?= 0.3.0 PROMU_VERSION ?= 0.3.0
PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
STATICCHECK := GOLANGCI_LINT :=
# staticcheck only supports linux, freebsd, darwin and windows platforms on i386/amd64 GOLANGCI_LINT_VERSION ?= v1.16.0
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
# windows isn't included here because of the path separator being different. # windows isn't included here because of the path separator being different.
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin)) ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386)) ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386))
STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint
STATICCHECK_VERSION ?= 2019.1
STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH)
endif endif
endif endif
@ -107,7 +106,7 @@ endif
%: common-% ; %: common-% ;
.PHONY: common-all .PHONY: common-all
common-all: precheck style check_license staticcheck unused build test common-all: precheck style check_license lint unused build test
.PHONY: common-style .PHONY: common-style
common-style: common-style:
@ -159,21 +158,24 @@ common-vet:
@echo ">> vetting code" @echo ">> vetting code"
GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs) GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs)
.PHONY: common-staticcheck .PHONY: common-lint
common-staticcheck: $(STATICCHECK) common-lint: $(GOLANGCI_LINT)
ifdef STATICCHECK ifdef GOLANGCI_LINT
@echo ">> running staticcheck" @echo ">> running golangci-lint"
chmod +x $(STATICCHECK)
ifdef GO111MODULE ifdef GO111MODULE
# 'go list' needs to be executed before staticcheck to prepopulate the modules cache. # 'go list' needs to be executed before staticcheck to prepopulate the modules cache.
# Otherwise staticcheck might fail randomly for some reason not yet explained. # Otherwise staticcheck might fail randomly for some reason not yet explained.
GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null GO111MODULE=$(GO111MODULE) $(GO) list -e -compiled -test=true -export=false -deps=true -find=false -tags= -- ./... > /dev/null
GO111MODULE=$(GO111MODULE) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(pkgs)
else else
$(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) $(GOLANGCI_LINT) run $(pkgs)
endif endif
endif endif
# For backward-compatibility.
.PHONY: common-staticcheck
common-staticcheck: lint
.PHONY: common-unused .PHONY: common-unused
common-unused: $(GOVENDOR) common-unused: $(GOVENDOR)
ifdef GOVENDOR ifdef GOVENDOR
@ -241,10 +243,10 @@ proto:
@echo ">> generating code from proto files" @echo ">> generating code from proto files"
@./scripts/genproto.sh @./scripts/genproto.sh
ifdef STATICCHECK ifdef GOLANGCI_LINT
$(STATICCHECK): $(GOLANGCI_LINT):
mkdir -p $(FIRST_GOPATH)/bin mkdir -p $(FIRST_GOPATH)/bin
curl -s -L $(STATICCHECK_URL) > $(STATICCHECK) curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(FIRST_GOPATH)/bin $(GOLANGCI_LINT_VERSION)
endif endif
ifdef GOVENDOR ifdef GOVENDOR

Loading…
Cancel
Save