mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 22:27:17 +02:00
ci: update golangci-lint to v2.0.2 and adjust configuration (#16356)
* ci: update golangci-lint to v2.0.2 and adjust configuration --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
6bfaaa0fee
commit
08aa5e3f97
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -202,11 +202,11 @@ jobs:
|
|||||||
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
||||||
if: github.repository == 'prometheus/snmp_exporter'
|
if: github.repository == 'prometheus/snmp_exporter'
|
||||||
- name: Lint
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
|
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
|
||||||
with:
|
with:
|
||||||
args: --verbose
|
args: --verbose
|
||||||
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
|
# Make sure to sync this with Makefile.common and scripts/golangci-lint.yml.
|
||||||
version: v1.64.6
|
version: v2.0.2
|
||||||
fuzzing:
|
fuzzing:
|
||||||
uses: ./.github/workflows/fuzzing.yml
|
uses: ./.github/workflows/fuzzing.yml
|
||||||
if: github.event_name == 'pull_request'
|
if: github.event_name == 'pull_request'
|
||||||
|
307
.golangci.yml
307
.golangci.yml
@ -1,8 +1,23 @@
|
|||||||
run:
|
formatters:
|
||||||
timeout: 15m
|
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:
|
issues:
|
||||||
sort-results: true
|
max-issues-per-linter: 0
|
||||||
|
max-same-issues: 0
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
# Keep this list sorted alphabetically
|
# Keep this list sorted alphabetically
|
||||||
@ -10,10 +25,8 @@ linters:
|
|||||||
- depguard
|
- depguard
|
||||||
- errorlint
|
- errorlint
|
||||||
- exptostd
|
- exptostd
|
||||||
- gci
|
|
||||||
- gocritic
|
- gocritic
|
||||||
- godot
|
- godot
|
||||||
- gofumpt
|
|
||||||
- loggercheck
|
- loggercheck
|
||||||
- misspell
|
- misspell
|
||||||
- nilnesserr
|
- nilnesserr
|
||||||
@ -29,136 +42,154 @@ linters:
|
|||||||
- usestdlibvars
|
- usestdlibvars
|
||||||
- whitespace
|
- whitespace
|
||||||
|
|
||||||
issues:
|
exclusions:
|
||||||
max-issues-per-linter: 0
|
paths:
|
||||||
max-same-issues: 0
|
# Skip autogenerated files.
|
||||||
# The default exclusions are too aggressive. For one, they
|
- ^.*\.(pb|y)\.go$
|
||||||
# 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:
|
|
||||||
rules:
|
rules:
|
||||||
main:
|
- linters:
|
||||||
deny:
|
- errcheck
|
||||||
- pkg: "sync/atomic"
|
# Taken from the default exclusions in v1.
|
||||||
desc: "Use go.uber.org/atomic instead of sync/atomic"
|
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
|
||||||
- pkg: "github.com/stretchr/testify/assert"
|
- linters:
|
||||||
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
|
- govet
|
||||||
- pkg: "github.com/go-kit/kit/log"
|
# We use many Seek methods that do not follow the usual pattern.
|
||||||
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
|
text: "stdmethods: method Seek.* should have signature Seek"
|
||||||
- pkg: "io/ioutil"
|
- linters:
|
||||||
desc: "Use corresponding 'os' or 'io' functions instead."
|
- revive
|
||||||
- pkg: "regexp"
|
# We have stopped at some point to write doc comments on exported symbols.
|
||||||
desc: "Use github.com/grafana/regexp instead of regexp"
|
# TODO(beorn7): Maybe we should enforce this again? There are ~500 offenders right now.
|
||||||
- pkg: "github.com/pkg/errors"
|
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
|
||||||
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
|
- linters:
|
||||||
- pkg: "gzip"
|
- gocritic
|
||||||
desc: "Use github.com/klauspost/compress instead of gzip"
|
text: "appendAssign"
|
||||||
- pkg: "zlib"
|
- linters:
|
||||||
desc: "Use github.com/klauspost/compress instead of zlib"
|
- errcheck
|
||||||
- pkg: "golang.org/x/exp/slices"
|
path: _test.go
|
||||||
desc: "Use 'slices' instead."
|
- linters:
|
||||||
errcheck:
|
- errorlint
|
||||||
exclude-functions:
|
path: "tsdb/head_wal.go"
|
||||||
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
|
- linters:
|
||||||
- io.Copy
|
- godot
|
||||||
# The next two are used in HTTP handlers, any error is handled by the server itself.
|
source: "^// ==="
|
||||||
- io.WriteString
|
- linters:
|
||||||
- (net/http.ResponseWriter).Write
|
- perfsprint
|
||||||
# No need to check for errors on server's shutdown.
|
text: "fmt.Sprintf can be replaced with string concatenation"
|
||||||
- (*net/http.Server).Shutdown
|
settings:
|
||||||
# Never check for rollback errors as Rollback() is called when a previous error was detected.
|
depguard:
|
||||||
- (github.com/prometheus/prometheus/storage.Appender).Rollback
|
rules:
|
||||||
gci:
|
main:
|
||||||
sections:
|
deny:
|
||||||
- standard
|
- pkg: "sync/atomic"
|
||||||
- default
|
desc: "Use go.uber.org/atomic instead of sync/atomic"
|
||||||
- prefix(github.com/prometheus/prometheus)
|
- pkg: "github.com/stretchr/testify/assert"
|
||||||
gofumpt:
|
desc: "Use github.com/stretchr/testify/require instead of github.com/stretchr/testify/assert"
|
||||||
extra-rules: true
|
- pkg: "github.com/go-kit/kit/log"
|
||||||
perfsprint:
|
desc: "Use github.com/go-kit/log instead of github.com/go-kit/kit/log"
|
||||||
# Optimizes `fmt.Errorf`.
|
- pkg: "io/ioutil"
|
||||||
errorf: true
|
desc: "Use corresponding 'os' or 'io' functions instead."
|
||||||
revive:
|
- pkg: "regexp"
|
||||||
# By default, revive will enable only the linting rules that are named in the configuration file.
|
desc: "Use github.com/grafana/regexp instead of regexp"
|
||||||
# So, it's needed to explicitly enable all required rules here.
|
- pkg: "github.com/pkg/errors"
|
||||||
rules:
|
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
|
||||||
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
- pkg: "gzip"
|
||||||
- name: blank-imports
|
desc: "Use github.com/klauspost/compress instead of gzip"
|
||||||
- name: comment-spacings
|
- pkg: "zlib"
|
||||||
- name: context-as-argument
|
desc: "Use github.com/klauspost/compress instead of zlib"
|
||||||
arguments:
|
- pkg: "golang.org/x/exp/slices"
|
||||||
# Allow functions with test or bench signatures.
|
desc: "Use 'slices' instead."
|
||||||
- allowTypesBefore: "*testing.T,testing.TB"
|
errcheck:
|
||||||
- name: context-keys-type
|
exclude-functions:
|
||||||
- name: dot-imports
|
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
|
||||||
- name: early-return
|
- io.Copy
|
||||||
arguments:
|
# The next two are used in HTTP handlers, any error is handled by the server itself.
|
||||||
- "preserveScope"
|
- io.WriteString
|
||||||
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
|
- (net/http.ResponseWriter).Write
|
||||||
# See https://github.com/mgechev/revive/issues/386
|
# No need to check for errors on server's shutdown.
|
||||||
- name: empty-block
|
- (*net/http.Server).Shutdown
|
||||||
disabled: true
|
# Never check for rollback errors as Rollback() is called when a previous error was detected.
|
||||||
- name: error-naming
|
- (github.com/prometheus/prometheus/storage.Appender).Rollback
|
||||||
- name: error-return
|
perfsprint:
|
||||||
- name: error-strings
|
# Optimizes `fmt.Errorf`.
|
||||||
- name: errorf
|
errorf: true
|
||||||
- name: exported
|
revive:
|
||||||
- name: increment-decrement
|
# By default, revive will enable only the linting rules that are named in the configuration file.
|
||||||
- name: indent-error-flow
|
# So, it's needed to explicitly enable all required rules here.
|
||||||
arguments:
|
rules:
|
||||||
- "preserveScope"
|
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
|
||||||
- name: package-comments
|
- name: blank-imports
|
||||||
# TODO(beorn7): Currently, we have a lot of missing package doc comments. Maybe we should have them.
|
- name: comment-spacings
|
||||||
disabled: true
|
- name: context-as-argument
|
||||||
- name: range
|
arguments:
|
||||||
- name: receiver-naming
|
# Allow functions with test or bench signatures.
|
||||||
- name: redefines-builtin-id
|
- allowTypesBefore: '*testing.T,testing.TB'
|
||||||
- name: superfluous-else
|
- name: context-keys-type
|
||||||
arguments:
|
- name: dot-imports
|
||||||
- "preserveScope"
|
- name: early-return
|
||||||
- name: time-naming
|
arguments:
|
||||||
- name: unexported-return
|
- "preserveScope"
|
||||||
- name: unreachable-code
|
# A lot of false positives: incorrectly identifies channel draining as "empty code block".
|
||||||
- name: unused-parameter
|
# See https://github.com/mgechev/revive/issues/386
|
||||||
- name: var-declaration
|
- name: empty-block
|
||||||
- name: var-naming
|
disabled: true
|
||||||
testifylint:
|
- name: error-naming
|
||||||
disable:
|
- name: error-return
|
||||||
- float-compare
|
- name: error-strings
|
||||||
- go-require
|
- name: errorf
|
||||||
enable-all: true
|
- 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"
|
||||||
|
@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
|
|||||||
SKIP_GOLANGCI_LINT :=
|
SKIP_GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT :=
|
GOLANGCI_LINT :=
|
||||||
GOLANGCI_LINT_OPTS ?=
|
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.
|
# 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.
|
# windows isn't included here because of the path separator being different.
|
||||||
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
|
||||||
|
@ -33,7 +33,7 @@ jobs:
|
|||||||
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
|
||||||
if: github.repository == 'prometheus/snmp_exporter'
|
if: github.repository == 'prometheus/snmp_exporter'
|
||||||
- name: Lint
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
|
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
|
||||||
with:
|
with:
|
||||||
args: --verbose
|
args: --verbose
|
||||||
version: v1.64.6
|
version: v2.0.2
|
||||||
|
Loading…
Reference in New Issue
Block a user