diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5560ab4a3..f2263689a3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -202,11 +202,11 @@ jobs: run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: args: --verbose # Make sure to sync this with Makefile.common and scripts/golangci-lint.yml. - version: v1.64.6 + version: v2.0.2 fuzzing: uses: ./.github/workflows/fuzzing.yml if: github.event_name == 'pull_request' diff --git a/.golangci.yml b/.golangci.yml index fec430cf08..8cd1b51545 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,8 +1,23 @@ -run: - timeout: 15m +formatters: + enable: + - gci + - gofumpt + settings: + gci: + sections: + - standard + - default + - prefix(github.com/prometheus/prometheus) + gofumpt: + extra-rules: true + exclusions: + paths: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ -output: - sort-results: true +issues: + max-issues-per-linter: 0 + max-same-issues: 0 linters: # Keep this list sorted alphabetically @@ -10,10 +25,8 @@ linters: - depguard - errorlint - exptostd - - gci - gocritic - godot - - gofumpt - loggercheck - misspell - nilnesserr @@ -29,136 +42,154 @@ linters: - usestdlibvars - whitespace -issues: - max-issues-per-linter: 0 - max-same-issues: 0 - # The default exclusions are too aggressive. For one, they - # essentially disable any linting on doc comments. We disable - # default exclusions here and add exclusions fitting our codebase - # further down. - exclude-use-default: false - exclude-files: - # Skip autogenerated files. - - ^.*\.(pb|y)\.go$ - exclude-rules: - - linters: - - errcheck - # Taken from the default exclusions (that are otherwise disabled above). - text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked - - linters: - - govet - # We use many Seek methods that do not follow the usual pattern. - text: "stdmethods: method Seek.* should have signature Seek" - - linters: - - revive - # We have stopped at some point to write doc comments on exported symbols. - # TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now. - text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported - - linters: - - gocritic - text: "appendAssign" - - path: _test.go - linters: - - errcheck - - path: "tsdb/head_wal.go" - linters: - - errorlint - - linters: - - godot - source: "^// ===" - - linters: - - perfsprint - text: "fmt.Sprintf can be replaced with string concatenation" -linters-settings: - depguard: + exclusions: + paths: + # Skip autogenerated files. + - ^.*\.(pb|y)\.go$ rules: - main: - deny: - - pkg: "sync/atomic" - desc: "Use go.uber.org/atomic instead of sync/atomic" - - pkg: "github.com/stretchr/testify/assert" - desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" - - pkg: "github.com/go-kit/kit/log" - desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" - - pkg: "io/ioutil" - desc: "Use corresponding 'os' or 'io' functions instead." - - pkg: "regexp" - desc: "Use github.com/grafana/regexp instead of regexp" - - pkg: "github.com/pkg/errors" - desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" - - pkg: "gzip" - desc: "Use github.com/klauspost/compress instead of gzip" - - pkg: "zlib" - desc: "Use github.com/klauspost/compress instead of zlib" - - pkg: "golang.org/x/exp/slices" - desc: "Use 'slices' instead." - errcheck: - exclude-functions: - # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". - - io.Copy - # The next two are used in HTTP handlers, any error is handled by the server itself. - - io.WriteString - - (net/http.ResponseWriter).Write - # No need to check for errors on server's shutdown. - - (*net/http.Server).Shutdown - # Never check for rollback errors as Rollback() is called when a previous error was detected. - - (github.com/prometheus/prometheus/storage.Appender).Rollback - gci: - sections: - - standard - - default - - prefix(github.com/prometheus/prometheus) - gofumpt: - extra-rules: true - perfsprint: - # Optimizes `fmt.Errorf`. - errorf: true - revive: - # By default, revive will enable only the linting rules that are named in the configuration file. - # So, it's needed to explicitly enable all required rules here. - rules: - # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md - - name: blank-imports - - name: comment-spacings - - name: context-as-argument - arguments: - # Allow functions with test or bench signatures. - - allowTypesBefore: "*testing.T,testing.TB" - - name: context-keys-type - - name: dot-imports - - name: early-return - arguments: - - "preserveScope" - # A lot of false positives: incorrectly identifies channel draining as "empty code block". - # See https://github.com/mgechev/revive/issues/386 - - name: empty-block - disabled: true - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: exported - - name: increment-decrement - - name: indent-error-flow - arguments: - - "preserveScope" - - name: package-comments - # TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them. - disabled: true - - name: range - - name: receiver-naming - - name: redefines-builtin-id - - name: superfluous-else - arguments: - - "preserveScope" - - name: time-naming - - name: unexported-return - - name: unreachable-code - - name: unused-parameter - - name: var-declaration - - name: var-naming - testifylint: - disable: - - float-compare - - go-require - enable-all: true + - linters: + - errcheck + # Taken from the default exclusions in v1. + text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked + - linters: + - govet + # We use many Seek methods that do not follow the usual pattern. + text: "stdmethods: method Seek.* should have signature Seek" + - linters: + - revive + # We have stopped at some point to write doc comments on exported symbols. + # TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now. + text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported + - linters: + - gocritic + text: "appendAssign" + - linters: + - errcheck + path: _test.go + - linters: + - errorlint + path: "tsdb/head_wal.go" + - linters: + - godot + source: "^// ===" + - linters: + - perfsprint + text: "fmt.Sprintf can be replaced with string concatenation" + settings: + depguard: + rules: + main: + deny: + - pkg: "sync/atomic" + desc: "Use go.uber.org/atomic instead of sync/atomic" + - pkg: "github.com/stretchr/testify/assert" + desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert" + - pkg: "github.com/go-kit/kit/log" + desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log" + - pkg: "io/ioutil" + desc: "Use corresponding 'os' or 'io' functions instead." + - pkg: "regexp" + desc: "Use github.com/grafana/regexp instead of regexp" + - pkg: "github.com/pkg/errors" + desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors" + - pkg: "gzip" + desc: "Use github.com/klauspost/compress instead of gzip" + - pkg: "zlib" + desc: "Use github.com/klauspost/compress instead of zlib" + - pkg: "golang.org/x/exp/slices" + desc: "Use 'slices' instead." + errcheck: + exclude-functions: + # Don't flag lines such as "io.Copy(io.Discard, resp.Body)". + - io.Copy + # The next two are used in HTTP handlers, any error is handled by the server itself. + - io.WriteString + - (net/http.ResponseWriter).Write + # No need to check for errors on server's shutdown. + - (*net/http.Server).Shutdown + # Never check for rollback errors as Rollback() is called when a previous error was detected. + - (github.com/prometheus/prometheus/storage.Appender).Rollback + perfsprint: + # Optimizes `fmt.Errorf`. + errorf: true + revive: + # By default, revive will enable only the linting rules that are named in the configuration file. + # So, it's needed to explicitly enable all required rules here. + rules: + # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md + - name: blank-imports + - name: comment-spacings + - name: context-as-argument + arguments: + # Allow functions with test or bench signatures. + - allowTypesBefore: '*testing.T,testing.TB' + - name: context-keys-type + - name: dot-imports + - name: early-return + arguments: + - "preserveScope" + # A lot of false positives: incorrectly identifies channel draining as "empty code block". + # See https://github.com/mgechev/revive/issues/386 + - name: empty-block + disabled: true + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: exported + - name: increment-decrement + - name: indent-error-flow + arguments: + - "preserveScope" + - name: package-comments + # TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them. + disabled: true + - name: range + - name: receiver-naming + - name: redefines-builtin-id + - name: superfluous-else + arguments: + - "preserveScope" + - name: time-naming + - name: unexported-return + - name: unreachable-code + - name: unused-parameter + - name: var-declaration + - name: var-naming + staticcheck: + checks: + - all # Enable all checks. + # FIXME: We should enable this check once we have fixed all the issues. + - -QF1001 + - -QF1002 + - -QF1003 + - -QF1006 + - -QF1007 + - -QF1008 + - -QF1009 + - -QF1010 + - -QF1012 + - -ST1000 + - -ST1003 + - -ST1005 + - -ST1012 + - -ST1016 + - -ST1020 + testifylint: + disable: + - empty # FIXME + - equal-values # FIXME + - float-compare + - formatter # FIXME + - go-require + - len # FIXME + - useless-assert # FIXME: wait for golangci-lint > v2.0.2 + enable-all: true + +output: + show-stats: false + +run: + timeout: 15m + +version: "2" diff --git a/Makefile.common b/Makefile.common index 8cb3838598..81bad5f42d 100644 --- a/Makefile.common +++ b/Makefile.common @@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_ SKIP_GOLANGCI_LINT := GOLANGCI_LINT := GOLANGCI_LINT_OPTS ?= -GOLANGCI_LINT_VERSION ?= v1.64.6 +GOLANGCI_LINT_VERSION ?= v2.0.2 # golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64. # windows isn't included here because of the path separator being different. ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) diff --git a/scripts/golangci-lint.yml b/scripts/golangci-lint.yml index 5342cbe086..3893ef86b1 100644 --- a/scripts/golangci-lint.yml +++ b/scripts/golangci-lint.yml @@ -33,7 +33,7 @@ jobs: run: sudo apt-get update && sudo apt-get -y install libsnmp-dev if: github.repository == 'prometheus/snmp_exporter' - name: Lint - uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2 + uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0 with: args: --verbose - version: v1.64.6 + version: v2.0.2