Upgrade golangci-lint due to timeouts for v1 version.

Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
bwplotka 2025-06-27 10:30:22 +01:00
parent ddb9f4c70a
commit 488a420b6e
3 changed files with 132 additions and 90 deletions

View File

@ -161,20 +161,22 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with: with:
go-version: 1.23.x persist-credentials: false
- name: Install Go
uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: 1.24.x
- name: Install snmp_exporter/generator dependencies - name: Install snmp_exporter/generator dependencies
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@a4f60bb28d35aeee14e6880718e0c85ff1882e64 # v6.0.1 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.59.0 version: v2.1.5
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,58 +1,91 @@
run: # NOTE(bwplotka): Pulled config from 44f78bb3c8fd3d2cdb89ffec9eeb585cd12991bd as
timeout: 15m # old golangci-lint was timing out.
skip-files: # For an old LTS, it's not feasable to apply new lints and formatters, so some are commented.
# Skip autogenerated files. formatters:
- ^.*\.(pb|y)\.go$
skip-dirs:
# Copied it from a different source
- storage/remote/otlptranslator/prometheusremotewrite
- storage/remote/otlptranslator/prometheus
output:
sort-results: true
linters:
enable: enable:
- depguard # - gci
- errorlint # - gofumpt
- gocritic - goimports
- godot settings:
- gofumpt gci:
- goimports sections:
- misspell - standard
- nolintlint - default
- perfsprint - prefix(github.com/prometheus/prometheus)
- predeclared gofumpt:
- revive extra-rules: true
- testifylint goimports:
- unconvert local-prefixes:
- unused - github.com/prometheus/prometheus
- usestdlibvars
- whitespace
issues: issues:
max-issues-per-linter: 0
max-same-issues: 0 max-same-issues: 0
exclude-rules:
- linters: linters:
- gocritic # Keep this list sorted alphabetically
text: "appendAssign" enable:
- path: _test.go - depguard
linters: - errorlint
- errcheck - exptostd
- path: "tsdb/head_wal.go" - gocritic
linters: - misspell
- errorlint - nilnesserr
- linters: # TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed.
- godot # - nolintlint
source: "^// ===" - sloglint
- linters: - unconvert
- perfsprint - unused
text: "fmt.Sprintf can be replaced with string concatenation" # NOTE(bwplotka): For an old LTS, it's not feasable to apply new lints, skipping.
linters-settings: # - testifylint
depguard: # - whitespace
# - usestdlibvars
# - staticcheck
# - revive
# - predeclared
# - perfsprint
# - godot
# - loggercheck
disable:
- staticcheck
- errcheck
exclusions:
paths:
# Skip autogenerated files.
- ^.*\.(pb|y)\.go$
rules: rules:
main: - linters:
deny: - 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: "^// ==="
warn-unused: true
settings:
depguard:
rules:
main:
deny:
- pkg: "sync/atomic" - pkg: "sync/atomic"
desc: "Use go.uber.org/atomic instead of sync/atomic" desc: "Use go.uber.org/atomic instead of sync/atomic"
- pkg: "github.com/stretchr/testify/assert" - pkg: "github.com/stretchr/testify/assert"
@ -71,8 +104,8 @@ linters-settings:
desc: "Use github.com/klauspost/compress instead of zlib" desc: "Use github.com/klauspost/compress instead of zlib"
- pkg: "golang.org/x/exp/slices" - pkg: "golang.org/x/exp/slices"
desc: "Use 'slices' instead." desc: "Use 'slices' instead."
errcheck: errcheck:
exclude-functions: exclude-functions:
# Don't flag lines such as "io.Copy(io.Discard, resp.Body)". # Don't flag lines such as "io.Copy(io.Discard, resp.Body)".
- io.Copy - io.Copy
# The next two are used in HTTP handlers, any error is handled by the server itself. # The next two are used in HTTP handlers, any error is handled by the server itself.
@ -80,31 +113,35 @@ linters-settings:
- (net/http.ResponseWriter).Write - (net/http.ResponseWriter).Write
# No need to check for errors on server's shutdown. # No need to check for errors on server's shutdown.
- (*net/http.Server).Shutdown - (*net/http.Server).Shutdown
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
# 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
goimports: perfsprint:
local-prefixes: github.com/prometheus/prometheus # Optimizes even if it requires an int or uint type cast.
gofumpt: int-conversion: true
extra-rules: true # Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
perfsprint: err-error: true
# Optimizes `fmt.Errorf`. # Optimizes `fmt.Errorf`.
errorf: false errorf: true
revive: # Optimizes `fmt.Sprintf` with only one argument.
# By default, revive will enable only the linting rules that are named in the configuration file. sprintf1: true
# So, it's needed to explicitly set in configuration all required rules. # Optimizes into strings concatenation.
# The following configuration enables all the rules from the defaults.toml strconcat: false
# https://github.com/mgechev/revive/blob/master/defaults.toml revive:
rules: # 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 # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
- name: blank-imports - name: blank-imports
- name: comment-spacings
- 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
arguments:
- "preserveScope"
# A lot of false positives: incorrectly identifies channel draining as "empty code block". # A lot of false positives: incorrectly identifies channel draining as "empty code block".
# See https://github.com/mgechev/revive/issues/386 # See https://github.com/mgechev/revive/issues/386
- name: empty-block - name: empty-block
@ -116,30 +153,33 @@ linters-settings:
- name: exported - name: exported
- name: increment-decrement - name: increment-decrement
- name: indent-error-flow - name: indent-error-flow
arguments:
- "preserveScope"
- name: package-comments - 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: range
- name: receiver-naming - name: receiver-naming
- name: redefines-builtin-id - name: redefines-builtin-id
- name: superfluous-else - name: superfluous-else
arguments:
- "preserveScope"
- name: time-naming - name: time-naming
- name: unexported-return - name: unexported-return
- name: unreachable-code - name: unreachable-code
- name: unused-parameter - name: unused-parameter
disabled: true
- name: var-declaration - name: var-declaration
- name: var-naming - name: var-naming
testifylint: testifylint:
disable: disable:
- float-compare - float-compare
- go-require - go-require
enable: enable-all: true
- bool-compare
- compares output:
- empty show-stats: false
- error-is-as
- error-nil run:
- expected-actual timeout: 15m
- len
- require-error version: "2"
- suite-dont-use-pkg
- suite-extra-assert-call

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.59.0 GOLANGCI_LINT_VERSION ?= v2.1.6
# 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))