Skip to content

Commit f140ab6

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 f140ab6

14 files changed

+67
-47
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/btrfs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error {
6969

7070
for _, s := range stats {
7171
// match up procfs and ioctl info by filesystem UUID (without dashes)
72-
var fsUUID = strings.Replace(s.UUID, "-", "", -1)
72+
var fsUUID = strings.ReplaceAll(s.UUID, "-", "")
7373
ioctlStats := ioctlStatsMap[fsUUID]
7474
c.updateBtrfsStats(ch, s, ioctlStats)
7575
}

collector/cpu_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ func NewCPUCollector(logger *slog.Logger) (Collector, error) {
8787
isolcpus, err := sfs.IsolatedCPUs()
8888
if err != nil {
8989
if !os.IsNotExist(err) {
90-
return nil, fmt.Errorf("Unable to get isolated cpus: %w", err)
90+
return nil, fmt.Errorf("couldn't 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/ethtool_linux_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,16 +212,18 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) {
212212

213213
items := strings.Split(line, ": ")
214214
if items[0] == "Supported pause frame use" {
215-
if items[1] == "Symmetric" {
215+
switch items[1] {
216+
case "Symmetric":
216217
res.Supported |= (1 << unix.ETHTOOL_LINK_MODE_Pause_BIT)
217-
} else if items[1] == "Receive-only" {
218+
case "Receive-only":
218219
res.Supported |= (1 << unix.ETHTOOL_LINK_MODE_Asym_Pause_BIT)
219220
}
220221
}
221222
if items[0] == "Advertised pause frame use" {
222-
if items[1] == "Symmetric" {
223+
switch items[1] {
224+
case "Symmetric":
223225
res.Advertising |= (1 << unix.ETHTOOL_LINK_MODE_Pause_BIT)
224-
} else if items[1] == "Receive-only" {
226+
case "Receive-only":
225227
res.Advertising |= (1 << unix.ETHTOOL_LINK_MODE_Asym_Pause_BIT)
226228
}
227229
}

collector/filesystem_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ func parseFilesystemLabels(r io.Reader) ([]filesystemLabels, error) {
215215

216216
// Ensure we handle the translation of \040 and \011
217217
// as per fstab(5).
218-
parts[4] = strings.Replace(parts[4], "\\040", " ", -1)
219-
parts[4] = strings.Replace(parts[4], "\\011", "\t", -1)
218+
parts[4] = strings.ReplaceAll(parts[4], "\\040", " ")
219+
parts[4] = strings.ReplaceAll(parts[4], "\\011", "\t")
220220

221221
filesystems = append(filesystems, filesystemLabels{
222222
device: parts[m+3],

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 {

collector/meminfo_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func NewMeminfoCollector(logger *slog.Logger) (Collector, error) {
4444
func (c *meminfoCollector) getMemInfo() (map[string]float64, error) {
4545
meminfo, err := c.fs.Meminfo()
4646
if err != nil {
47-
return nil, fmt.Errorf("Failed to get memory info: %s", err)
47+
return nil, fmt.Errorf("failed to get memory info: %s", err)
4848
}
4949

5050
metrics := make(map[string]float64)

collector/perf_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ func canTestPerf(t *testing.T) {
3333
if err != nil {
3434
t.Skip("Procfs not mounted, skipping perf tests")
3535
}
36-
paranoidStr := strings.Replace(string(paranoidBytes), "\n", "", -1)
36+
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")

collector/systemd_linux_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ func TestSystemdSummary(t *testing.T) {
122122
summary := summarizeUnits(fixtures[0])
123123

124124
for _, state := range unitStatesName {
125-
if state == "inactive" {
125+
switch state {
126+
case "inactive":
126127
testSummaryHelper(t, state, summary[state], 3.0)
127-
} else if state == "active" {
128+
case "active":
128129
testSummaryHelper(t, state, summary[state], 1.0)
129-
} else {
130+
default:
130131
testSummaryHelper(t, state, summary[state], 0.0)
131132
}
132133
}

collector/zfs_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,5 +435,5 @@ type zfsSysctl string
435435

436436
func (s zfsSysctl) metricName() string {
437437
parts := strings.Split(string(s), ".")
438-
return strings.Replace(parts[len(parts)-1], "-", "_", -1)
438+
return strings.ReplaceAll(parts[len(parts)-1], "-", "_")
439439
}

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)