Skip to content

Commit 9afcb7d

Browse files
committed
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]>
1 parent 38d32a3 commit 9afcb7d

File tree

6 files changed

+48
-32
lines changed

6 files changed

+48
-32
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 & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
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:
25-
# Used in HTTP handlers, any error is handled by the server itself.
26-
- (net/http.ResponseWriter).Write
27-
revive:
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:
17+
exclude-functions:
18+
- (net/http.ResponseWriter).Write
19+
revive:
20+
rules:
21+
- name: unused-parameter
22+
severity: warning
23+
disabled: true
24+
exclusions:
25+
generated: lax
26+
presets:
27+
- comments
28+
- common-false-positives
29+
- legacy
30+
- std-error-handling
2831
rules:
29-
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter
30-
- name: unused-parameter
31-
severity: warning
32-
disabled: true
32+
- linters:
33+
- errcheck
34+
path: _test.go
35+
paths:
36+
- third_party$
37+
- builtin$
38+
- examples$
39+
formatters:
40+
enable:
41+
- goimports
42+
exclusions:
43+
generated: lax
44+
paths:
45+
- third_party$
46+
- builtin$
47+
- 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/meminfo_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
5252
&infoCount,
5353
)
5454
if ret != C.KERN_SUCCESS {
55-
return nil, fmt.Errorf("Couldn't get memory statistics, host_statistics returned %d", ret)
55+
return nil, fmt.Errorf("couldn't get memory statistics, host_statistics returned %d", ret)
5656
}
5757
totalb, err := unix.Sysctl("hw.memsize")
5858
if err != nil {

node_exporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
112112
if err != nil {
113113
h.logger.Warn("Couldn't create filtered metrics handler:", "err", err)
114114
w.WriteHeader(http.StatusBadRequest)
115-
w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err)))
115+
fmt.Fprintf(w, "Couldn't create filtered metrics handler: %s", err)
116116
return
117117
}
118118
filteredHandler.ServeHTTP(w, r)

0 commit comments

Comments
 (0)