From 682e4747eb8b40fb6bdf921fc4c6af425f51c9ce Mon Sep 17 00:00:00 2001 From: Christoph Mewes Date: Tue, 3 May 2022 16:02:25 +0200 Subject: [PATCH] permanently enable the linters Signed-off-by: Christoph Mewes --- .golangci.yml | 18 +++++++++++++++++- api/prometheus/v1/api_test.go | 10 +++++++--- prometheus/process_collector.go | 4 ++-- prometheus/promhttp/instrument_server_test.go | 1 - prometheus/registry.go | 4 +++- prometheus/registry_test.go | 2 +- 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index bedb09e6a..7e1953030 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -8,10 +8,26 @@ output: linters: enable: + - deadcode + - depguard + - durationcheck + - errorlint + - exportloopref + - gofmt - gofumpt - goimports - - revive + - gosimple + - ineffassign - misspell + - nolintlint + - predeclared + - revive + - staticcheck + - structcheck + - unconvert + - unused + - varcheck + - wastedassign issues: max-same-issues: 0 diff --git a/api/prometheus/v1/api_test.go b/api/prometheus/v1/api_test.go index a82a02314..2bc85918f 100644 --- a/api/prometheus/v1/api_test.go +++ b/api/prometheus/v1/api_test.go @@ -1455,9 +1455,13 @@ func TestAPIClientDo(t *testing.T) { } if test.expectedErr.Detail != "" { - apiErr := err.(*Error) - if apiErr.Detail != test.expectedErr.Detail { - t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail) + apiErr := &Error{} + if errors.As(err, &apiErr) { + if apiErr.Detail != test.expectedErr.Detail { + t.Fatalf("expected error detail :%v, but got:%v", apiErr.Detail, test.expectedErr.Detail) + } + } else { + t.Fatalf("expected v1.Error instance, but got:%T", err) } } diff --git a/prometheus/process_collector.go b/prometheus/process_collector.go index 5bfe0ff5b..27c519406 100644 --- a/prometheus/process_collector.go +++ b/prometheus/process_collector.go @@ -154,11 +154,11 @@ func NewPidFileFn(pidFilePath string) func() (int, error) { return func() (int, error) { content, err := ioutil.ReadFile(pidFilePath) if err != nil { - return 0, fmt.Errorf("can't read pid file %q: %+v", pidFilePath, err) + return 0, fmt.Errorf("can't read pid file %q: %w", pidFilePath, err) } pid, err := strconv.Atoi(strings.TrimSpace(string(content))) if err != nil { - return 0, fmt.Errorf("can't parse pid file %q: %+v", pidFilePath, err) + return 0, fmt.Errorf("can't parse pid file %q: %w", pidFilePath, err) } return pid, nil diff --git a/prometheus/promhttp/instrument_server_test.go b/prometheus/promhttp/instrument_server_test.go index a3720c2ec..17c7edc8f 100644 --- a/prometheus/promhttp/instrument_server_test.go +++ b/prometheus/promhttp/instrument_server_test.go @@ -145,7 +145,6 @@ func TestLabelCheck(t *testing.T) { }, append(sc.varLabels, sc.curriedLabels...), )) - //nolint:typecheck // Ignore declared but unused error. for _, l := range sc.curriedLabels { c = c.MustCurryWith(prometheus.Labels{l: "dummy"}) o = o.MustCurryWith(prometheus.Labels{l: "dummy"}) diff --git a/prometheus/registry.go b/prometheus/registry.go index 1e176f641..deb6a4ee9 100644 --- a/prometheus/registry.go +++ b/prometheus/registry.go @@ -15,6 +15,7 @@ package prometheus import ( "bytes" + "errors" "fmt" "io/ioutil" "os" @@ -725,7 +726,8 @@ func (gs Gatherers) Gather() ([]*dto.MetricFamily, error) { for i, g := range gs { mfs, err := g.Gather() if err != nil { - if multiErr, ok := err.(MultiError); ok { + multiErr := MultiError{} + if errors.As(err, &multiErr) { for _, err := range multiErr { errs = append(errs, fmt.Errorf("[from Gatherer #%d] %w", i+1, err)) } diff --git a/prometheus/registry_test.go b/prometheus/registry_test.go index 8425fa7e3..6112395a9 100644 --- a/prometheus/registry_test.go +++ b/prometheus/registry_test.go @@ -1242,7 +1242,7 @@ func TestNewMultiTRegistry(t *testing.T) { t.Run("two registries, one with error", func(t *testing.T) { m := prometheus.NewMultiTRegistry(prometheus.ToTransactionalGatherer(reg), treg) ret, done, err := m.Gather() - if err != treg.err { + if !errors.Is(err, treg.err) { t.Error("unexpected error:", err) } done()