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:
Matthieu MOREL 2025-04-02 13:05:30 +02:00 committed by GitHub
parent 6bfaaa0fee
commit 08aa5e3f97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 174 additions and 143 deletions

View File

@ -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'

View File

@ -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,21 +42,14 @@ linters:
- usestdlibvars - usestdlibvars
- whitespace - whitespace
issues: exclusions:
max-issues-per-linter: 0 paths:
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. # Skip autogenerated files.
- ^.*\.(pb|y)\.go$ - ^.*\.(pb|y)\.go$
exclude-rules: rules:
- linters: - linters:
- errcheck - errcheck
# Taken from the default exclusions (that are otherwise disabled above). # 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 text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
- linters: - linters:
- govet - govet
@ -57,19 +63,19 @@ issues:
- linters: - linters:
- gocritic - gocritic
text: "appendAssign" text: "appendAssign"
- path: _test.go - linters:
linters:
- errcheck - errcheck
- path: "tsdb/head_wal.go" path: _test.go
linters: - linters:
- errorlint - errorlint
path: "tsdb/head_wal.go"
- linters: - linters:
- godot - godot
source: "^// ===" source: "^// ==="
- linters: - linters:
- perfsprint - perfsprint
text: "fmt.Sprintf can be replaced with string concatenation" text: "fmt.Sprintf can be replaced with string concatenation"
linters-settings: settings:
depguard: depguard:
rules: rules:
main: main:
@ -103,13 +109,6 @@ linters-settings:
- (*net/http.Server).Shutdown - (*net/http.Server).Shutdown
# Never check for rollback errors as Rollback() is called when a previous error was detected. # Never check for rollback errors as Rollback() is called when a previous error was detected.
- (github.com/prometheus/prometheus/storage.Appender).Rollback - (github.com/prometheus/prometheus/storage.Appender).Rollback
gci:
sections:
- standard
- default
- prefix(github.com/prometheus/prometheus)
gofumpt:
extra-rules: true
perfsprint: perfsprint:
# Optimizes `fmt.Errorf`. # Optimizes `fmt.Errorf`.
errorf: true errorf: true
@ -123,7 +122,7 @@ linters-settings:
- name: context-as-argument - name: context-as-argument
arguments: arguments:
# Allow functions with test or bench signatures. # Allow functions with test or bench signatures.
- allowTypesBefore: "*testing.T,testing.TB" - allowTypesBefore: '*testing.T,testing.TB'
- name: context-keys-type - name: context-keys-type
- name: dot-imports - name: dot-imports
- name: early-return - name: early-return
@ -157,8 +156,40 @@ linters-settings:
- name: unused-parameter - name: unused-parameter
- name: var-declaration - name: var-declaration
- name: var-naming - 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: testifylint:
disable: disable:
- empty # FIXME
- equal-values # FIXME
- float-compare - float-compare
- formatter # FIXME
- go-require - go-require
- len # FIXME
- useless-assert # FIXME: wait for golangci-lint > v2.0.2
enable-all: true enable-all: true
output:
show-stats: false
run:
timeout: 15m
version: "2"

View File

@ -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))

View File

@ -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