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,54 +1,87 @@
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$ enable:
skip-dirs: # - gci
# Copied it from a different source # - gofumpt
- storage/remote/otlptranslator/prometheusremotewrite - goimports
- storage/remote/otlptranslator/prometheus settings:
gci:
sections:
- standard
- default
- prefix(github.com/prometheus/prometheus)
gofumpt:
extra-rules: true
goimports:
local-prefixes:
- github.com/prometheus/prometheus
output: issues:
sort-results: true max-issues-per-linter: 0
max-same-issues: 0
linters: linters:
# Keep this list sorted alphabetically
enable: enable:
- depguard - depguard
- errorlint - errorlint
- exptostd
- gocritic - gocritic
- godot
- gofumpt
- goimports
- misspell - misspell
- nolintlint - nilnesserr
- perfsprint # TODO(bwplotka): Enable once https://github.com/golangci/golangci-lint/issues/3228 is fixed.
- predeclared # - nolintlint
- revive - sloglint
- testifylint
- unconvert - unconvert
- unused - unused
- usestdlibvars # NOTE(bwplotka): For an old LTS, it's not feasable to apply new lints, skipping.
- whitespace # - testifylint
# - whitespace
# - usestdlibvars
# - staticcheck
# - revive
# - predeclared
# - perfsprint
# - godot
# - loggercheck
disable:
- staticcheck
- errcheck
issues: exclusions:
max-same-issues: 0 paths:
exclude-rules: # Skip autogenerated files.
- ^.*\.(pb|y)\.go$
rules:
- 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: - 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: warn-unused: true
- perfsprint settings:
text: "fmt.Sprintf can be replaced with string concatenation"
linters-settings:
depguard: depguard:
rules: rules:
main: main:
@ -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:
local-prefixes: github.com/prometheus/prometheus
gofumpt:
extra-rules: true
perfsprint: perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: true
# Optimizes `fmt.Errorf`. # Optimizes `fmt.Errorf`.
errorf: false errorf: true
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: true
# Optimizes into strings concatenation.
strconcat: false
revive: revive:
# By default, revive will enable only the linting rules that are named in the configuration file. # By default, revive will enable only the linting rules that are named in the configuration file.
# So, it's needed to explicitly set in configuration all required rules. # So, it's needed to explicitly enable all required rules here.
# The following configuration enables all the rules from the defaults.toml
# https://github.com/mgechev/revive/blob/master/defaults.toml
rules: 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))