diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d9efa75 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,5 @@ +# Run only staticcheck for now. Additional linters will be enabled one-by-one. +linters: + enable: + - staticcheck + disable-all: true diff --git a/.travis.yml b/.travis.yml index 502935d..ec1220d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,6 @@ go: script: - make check_license unused test-short - - if [[ ! $TRAVIS_GO_VERSION =~ ^1\.(7|8|9)\.[x0-9]+$ ]]; then make staticcheck; fi + - if [[ ! $TRAVIS_GO_VERSION =~ ^1\.(7|8|9)\.[x0-9]+$ ]]; then make lint; fi # style is only checked against the latest supported Go version. - if [[ $TRAVIS_GO_VERSION =~ ^1\.(12)\. ]]; then make style; fi diff --git a/Makefile.common b/Makefile.common index 873964f..73052b3 100644 --- a/Makefile.common +++ b/Makefile.common @@ -72,14 +72,13 @@ endif 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 -STATICCHECK := -# staticcheck only supports linux, freebsd, darwin and windows platforms on i386/amd64 +GOLANGCI_LINT := +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. -ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux freebsd darwin)) +ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) ifeq ($(GOHOSTARCH),$(filter $(GOHOSTARCH),amd64 i386)) - STATICCHECK := $(FIRST_GOPATH)/bin/staticcheck - STATICCHECK_VERSION ?= 2019.1 - STATICCHECK_URL := https://github.com/dominikh/go-tools/releases/download/$(STATICCHECK_VERSION)/staticcheck_$(GOHOSTOS)_$(GOHOSTARCH) + GOLANGCI_LINT := $(FIRST_GOPATH)/bin/golangci-lint endif endif @@ -107,7 +106,7 @@ endif %: common-% ; .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 common-style: @@ -159,21 +158,24 @@ common-vet: @echo ">> vetting code" GO111MODULE=$(GO111MODULE) $(GO) vet $(GOOPTS) $(pkgs) -.PHONY: common-staticcheck -common-staticcheck: $(STATICCHECK) -ifdef STATICCHECK - @echo ">> running staticcheck" - chmod +x $(STATICCHECK) +.PHONY: common-lint +common-lint: $(GOLANGCI_LINT) +ifdef GOLANGCI_LINT + @echo ">> running golangci-lint" ifdef GO111MODULE # 'go list' needs to be executed before staticcheck to prepopulate the modules cache. # 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) $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) + GO111MODULE=$(GO111MODULE) $(GOLANGCI_LINT) run $(pkgs) else - $(STATICCHECK) -ignore "$(STATICCHECK_IGNORE)" $(pkgs) + $(GOLANGCI_LINT) run $(pkgs) endif endif +# For backward-compatibility. +.PHONY: common-staticcheck +common-staticcheck: lint + .PHONY: common-unused common-unused: $(GOVENDOR) ifdef GOVENDOR @@ -241,10 +243,10 @@ proto: @echo ">> generating code from proto files" @./scripts/genproto.sh -ifdef STATICCHECK -$(STATICCHECK): +ifdef GOLANGCI_LINT +$(GOLANGCI_LINT): 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 ifdef GOVENDOR diff --git a/prometheus/http.go b/prometheus/http.go index 0fa339a..19a3e8f 100644 --- a/prometheus/http.go +++ b/prometheus/http.go @@ -330,6 +330,8 @@ type fancyResponseWriterDelegator struct { } func (f *fancyResponseWriterDelegator) CloseNotify() <-chan bool { + //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to + //remove support from client_golang yet. return f.ResponseWriter.(http.CloseNotifier).CloseNotify() } diff --git a/prometheus/promhttp/delegator.go b/prometheus/promhttp/delegator.go index 5de5bbc..1f38090 100644 --- a/prometheus/promhttp/delegator.go +++ b/prometheus/promhttp/delegator.go @@ -76,6 +76,8 @@ type hijackerDelegator struct{ *responseWriterDelegator } type readerFromDelegator struct{ *responseWriterDelegator } func (d closeNotifierDelegator) CloseNotify() <-chan bool { + //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to + //remove support from client_golang yet. return d.ResponseWriter.(http.CloseNotifier).CloseNotify() } func (d flusherDelegator) Flush() { diff --git a/prometheus/promhttp/delegator_1_8.go b/prometheus/promhttp/delegator_1_8.go index 31a7069..79dbd20 100644 --- a/prometheus/promhttp/delegator_1_8.go +++ b/prometheus/promhttp/delegator_1_8.go @@ -161,6 +161,8 @@ func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) deleg } id := 0 + //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to + //remove support from client_golang yet. if _, ok := w.(http.CloseNotifier); ok { id += closeNotifier } diff --git a/prometheus/promhttp/instrument_server_test.go b/prometheus/promhttp/instrument_server_test.go index 716c6f4..11e42f2 100644 --- a/prometheus/promhttp/instrument_server_test.go +++ b/prometheus/promhttp/instrument_server_test.go @@ -294,6 +294,8 @@ func (t *testFlusher) Flush() { t.flushCalled = true } func TestInterfaceUpgrade(t *testing.T) { w := &testResponseWriter{} d := newDelegator(w, nil) + //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to + //remove support from client_golang yet. d.(http.CloseNotifier).CloseNotify() if !w.closeNotifyCalled { t.Error("CloseNotify not called") @@ -312,6 +314,8 @@ func TestInterfaceUpgrade(t *testing.T) { f := &testFlusher{} d = newDelegator(f, nil) + //lint:ignore SA1019 http.CloseNotifier is deprecated but we don't want to + //remove support from client_golang yet. if _, ok := d.(http.CloseNotifier); ok { t.Error("delegator unexpectedly implements http.CloseNotifier") }