Skip to content

Commit 18f95ce

Browse files
authored
chore: Upgrade golangci-lint to v2 (#3303)
* chore: Upgrade golangci-lint to v2 - Migrate the configuration file - Update the tooling version and CI - Apply auto-fixes Signed-off-by: Kemal Akkoyun <[email protected]> * chore: Upgrade golangci-lint to v2 - Migrate the configuration file - Update the tooling version and CI - Apply auto-fixes Signed-off-by: Kemal Akkoyun <[email protected]> --------- Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent 5fcd80a commit 18f95ce

File tree

6 files changed

+48
-31
lines changed

6 files changed

+48
-31
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: sudo apt-get update && sudo apt-get -y install libsnmp-dev
3434
if: github.repository == 'prometheus/snmp_exporter'
3535
- name: Lint
36-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
36+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
3737
with:
3838
args: --verbose
39-
version: v1.64.6
39+
version: v2.0.2

.golangci.yml

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,48 @@
1+
version: "2"
12
linters:
23
enable:
34
- depguard
4-
- goimports
55
- misspell
66
- revive
7-
8-
issues:
9-
exclude-rules:
10-
- path: _test.go
11-
linters:
12-
- errcheck
13-
14-
linters-settings:
15-
depguard:
16-
rules:
17-
no_exec_policy:
18-
files:
19-
- "!$test"
20-
deny:
21-
- pkg: "os/exec"
22-
desc: "Using os/exec to run sub processes it not allowed by policy"
23-
errcheck:
24-
exclude-functions:
7+
settings:
8+
depguard:
9+
rules:
10+
no_exec_policy:
11+
files:
12+
- '!$test'
13+
deny:
14+
- pkg: os/exec
15+
desc: Using os/exec to run sub processes it not allowed by policy
16+
errcheck:
2517
# Used in HTTP handlers, any error is handled by the server itself.
26-
- (net/http.ResponseWriter).Write
27-
revive:
18+
exclude-functions:
19+
- (net/http.ResponseWriter).Write
20+
revive:
21+
rules:
22+
- name: unused-parameter
23+
severity: warning
24+
disabled: true
25+
exclusions:
26+
generated: lax
27+
presets:
28+
- comments
29+
- common-false-positives
30+
- legacy
31+
- std-error-handling
2832
rules:
29-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
30-
- name: unused-parameter
31-
severity: warning
32-
disabled: true
33+
- linters:
34+
- errcheck
35+
path: _test.go
36+
paths:
37+
- third_party$
38+
- builtin$
39+
- examples$
40+
formatters:
41+
enable:
42+
- goimports
43+
exclusions:
44+
generated: lax
45+
paths:
46+
- third_party$
47+
- builtin$
48+
- examples$

Makefile.common

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_
6161
SKIP_GOLANGCI_LINT :=
6262
GOLANGCI_LINT :=
6363
GOLANGCI_LINT_OPTS ?=
64-
GOLANGCI_LINT_VERSION ?= v1.64.6
64+
GOLANGCI_LINT_VERSION ?= v2.0.2
6565
# golangci-lint only supports linux, darwin and windows platforms on i386/amd64/arm64.
6666
# windows isn't included here because of the path separator being different.
6767
ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))

collector/boot_time_bsd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
package collector
1919

2020
import (
21+
"log/slog"
22+
2123
"github.com/prometheus/client_golang/prometheus"
2224
"golang.org/x/sys/unix"
23-
"log/slog"
2425
)
2526

2627
type bootTimeCollector struct {

collector/cpu_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func NewCPUCollector(logger *slog.Logger) (Collector, error) {
8989
if !os.IsNotExist(err) {
9090
return nil, fmt.Errorf("unable to get isolated cpus: %w", err)
9191
}
92-
logger.Debug("Could not open isolated file", "error", err)
92+
logger.Debug("couldn't open isolated file", "error", err)
9393
}
9494

9595
c := &cpuCollector{

collector/perf_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func canTestPerf(t *testing.T) {
3636
paranoidStr := strings.ReplaceAll(string(paranoidBytes), "\n", "")
3737
paranoid, err := strconv.Atoi(paranoidStr)
3838
if err != nil {
39-
t.Fatalf("Expected perf_event_paranoid to be an int, got: %s", paranoidStr)
39+
t.Fatalf("expected perf_event_paranoid to be an int, got: %s", paranoidStr)
4040
}
4141
if paranoid >= 1 {
4242
t.Skip("Skipping perf tests, set perf_event_paranoid to 0")

0 commit comments

Comments
 (0)