Skip to content

Commit 67f32ef

Browse files
authored
chore: Upgrade golangci-lint to v2 (#715)
- Migrate the configuration file - Update the tooling version and CI - Apply auto-fixes Signed-off-by: Kemal Akkoyun <[email protected]>
1 parent 6c7a481 commit 67f32ef

19 files changed

+369
-348
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: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
1-
---
1+
version: "2"
22
linters:
33
enable:
4-
- errcheck
5-
- forbidigo
6-
- godot
7-
- gofmt
8-
- goimports
9-
- gosimple
10-
- govet
11-
- ineffassign
12-
- misspell
13-
- revive
14-
- staticcheck
15-
- testifylint
16-
- unused
17-
18-
linters-settings:
19-
forbidigo:
20-
forbid:
21-
- p: ^fmt\.Print.*$
22-
msg: Do not commit print statements.
23-
godot:
24-
capital: true
25-
exclude:
26-
# Ignore "See: URL"
27-
- 'See:'
28-
goimports:
29-
local-prefixes: github.com/prometheus/procfs
30-
misspell:
31-
locale: US
4+
- forbidigo
5+
- godot
6+
- misspell
7+
- revive
8+
- testifylint
9+
settings:
10+
forbidigo:
11+
forbid:
12+
- pattern: ^fmt\.Print.*$
13+
msg: Do not commit print statements.
14+
godot:
15+
exclude:
16+
# Ignore "See: URL".
17+
- 'See:'
18+
capital: true
19+
misspell:
20+
locale: US
21+
exclusions:
22+
generated: lax
23+
presets:
24+
- comments
25+
- common-false-positives
26+
- legacy
27+
- std-error-handling
28+
paths:
29+
- third_party$
30+
- builtin$
31+
- examples$
32+
formatters:
33+
enable:
34+
- gofmt
35+
- goimports
36+
settings:
37+
goimports:
38+
local-prefixes:
39+
- github.com/prometheus/procfs
40+
exclusions:
41+
generated: lax
42+
paths:
43+
- third_party$
44+
- builtin$
45+
- examples$

Makefile.common

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ GOHOSTOS ?= $(shell $(GO) env GOHOSTOS)
3333
GOHOSTARCH ?= $(shell $(GO) env GOHOSTARCH)
3434

3535
GO_VERSION ?= $(shell $(GO) version)
36-
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))
36+
GO_VERSION_NUMBER ?= $(word 3, $(GO_VERSION))Error Parsing File
3737
PRE_GO_111 ?= $(shell echo $(GO_VERSION_NUMBER) | grep -E 'go1\.(10|[0-9])\.')
3838

3939
PROMU := $(FIRST_GOPATH)/bin/promu
@@ -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))

buddyinfo_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Node 0, zone
5252
if err == nil {
5353
t.Fatalf("expected error, but none occurred")
5454
}
55-
if want, got := "Error Parsing File: Invalid number of fields, found: [Node 0, zone]", err.Error(); want != got {
56-
t.Fatalf("Error Parsing File: Invalid number of fields, found: [Node %q, %q]", want, got)
55+
if want, got := "error parsing file: Invalid number of fields, found: [Node 0, zone]", err.Error(); want != got {
56+
t.Fatalf("error parsing file: Invalid number of fields, found: [Node %q, %q]", want, got)
5757
}
5858
}
5959

@@ -68,7 +68,7 @@ Node 0, zone Normal 4381 1093 185 1530 567 102 4 0
6868
if err == nil {
6969
t.Fatalf("expected error, but none occurred")
7070
}
71-
if want, got := "Error Parsing File: mismatch in number of buddyinfo buckets, previous count 11, new count 12", err.Error(); !strings.HasPrefix(got, want) {
72-
t.Fatalf("Error Parsing File: mismatch in number of buddyinfo buckets, previous count %q, new count %q", want, got)
71+
if want, got := "error parsing file: mismatch in number of buddyinfo buckets, previous count 11, new count 12", err.Error(); !strings.HasPrefix(got, want) {
72+
t.Fatalf("error parsing file: mismatch in number of buddyinfo buckets, previous count %q, new count %q", want, got)
7373
}
7474
}

ipvs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func TestParseIPPort(t *testing.T) {
181181
if err != nil {
182182
t.Fatal(err)
183183
}
184-
if !(gotIP.Equal(ip) && port == gotPort) {
184+
if !gotIP.Equal(ip) || port != gotPort {
185185
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
186186
}
187187
}
@@ -211,7 +211,7 @@ func TestParseIPPortIPv6(t *testing.T) {
211211
if err != nil {
212212
t.Fatal(err)
213213
}
214-
if !(gotIP.Equal(ip) && port == gotPort) {
214+
if !gotIP.Equal(ip) || port != gotPort {
215215
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
216216
}
217217
}

iscsi/get_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ func TestGetStats(t *testing.T) {
159159
if !reflect.DeepEqual(readTests[i].iops, iops) {
160160
t.Errorf("unexpected iSCSI iops data :\nwant:\n%v\nhave:\n%v", readTests[i].iops, iops)
161161
}
162-
if stat.Tpgt[0].Luns[0].Backstore == "rd_mcp" {
162+
switch stat.Tpgt[0].Luns[0].Backstore {
163+
case "rd_mcp":
163164
haveRdmcp, err := sysconfigfs.GetRDMCPPath("119", "ramdisk_lio_1G")
164165
if err != nil {
165166
t.Errorf("fail rdmcp error %v", err)
@@ -170,7 +171,7 @@ func TestGetStats(t *testing.T) {
170171
if !reflect.DeepEqual(wantRdmcp, haveRdmcp) {
171172
t.Errorf("unexpected rdmcp data :\nwant:\n%v\nhave:\n%v", wantRdmcp, haveRdmcp)
172173
}
173-
} else if stat.Tpgt[0].Luns[0].Backstore == "iblock" {
174+
case "iblock":
174175
haveIblock, err := sysconfigfs.GetIblockUdev("0", "block_lio_rbd1")
175176
if err != nil {
176177
t.Errorf("fail iblock error %v", err)
@@ -180,7 +181,7 @@ func TestGetStats(t *testing.T) {
180181
if !reflect.DeepEqual(wantIblock, haveIblock) {
181182
t.Errorf("unexpected iblock data :\nwant:\n%v\nhave:\n%v", wantIblock, haveIblock)
182183
}
183-
} else if stat.Tpgt[0].Luns[0].Backstore == "fileio" {
184+
case "fileio":
184185
haveFileIO, err := sysconfigfs.GetFileioUdev("1", "file_lio_1G")
185186
if err != nil {
186187
t.Errorf("fail fileio error %v", err)
@@ -190,7 +191,7 @@ func TestGetStats(t *testing.T) {
190191
if !reflect.DeepEqual(wantFileIO, haveFileIO) {
191192
t.Errorf("unexpected fileio data :\nwant:\n%v\nhave:\n%v", wantFileIO, haveFileIO)
192193
}
193-
} else if stat.Tpgt[0].Luns[0].Backstore == "rbd" {
194+
case "rbd":
194195
haveRBD, err := sysconfigfs.GetRBDMatch("0", "iscsi-images-demo")
195196
if err != nil {
196197
t.Errorf("fail rbd error %v", err)

mountstats.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -601,25 +601,27 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats
601601
switch statVersion {
602602
case statVersion10:
603603
var expectedLength int
604-
if protocol == "tcp" {
604+
switch protocol {
605+
case "tcp":
605606
expectedLength = fieldTransport10TCPLen
606-
} else if protocol == "udp" {
607+
case "udp":
607608
expectedLength = fieldTransport10UDPLen
608-
} else {
609+
default:
609610
return nil, fmt.Errorf("%w: Invalid NFS protocol \"%s\" in stats 1.0 statement: %v", ErrFileParse, protocol, ss)
610611
}
611612
if len(ss) != expectedLength {
612613
return nil, fmt.Errorf("%w: Invalid NFS transport stats 1.0 statement: %v", ErrFileParse, ss)
613614
}
614615
case statVersion11:
615616
var expectedLength int
616-
if protocol == "tcp" {
617+
switch protocol {
618+
case "tcp":
617619
expectedLength = fieldTransport11TCPLen
618-
} else if protocol == "udp" {
620+
case "udp":
619621
expectedLength = fieldTransport11UDPLen
620-
} else if protocol == "rdma" {
622+
case "rdma":
621623
expectedLength = fieldTransport11RDMAMinLen
622-
} else {
624+
default:
623625
return nil, fmt.Errorf("%w: invalid NFS protocol \"%s\" in stats 1.1 statement: %v", ErrFileParse, protocol, ss)
624626
}
625627
if (len(ss) != expectedLength && (protocol == "tcp" || protocol == "udp")) ||
@@ -655,11 +657,12 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats
655657
// For the udp RPC transport there is no connection count, connect idle time,
656658
// or idle time (fields #3, #4, and #5); all other fields are the same. So
657659
// we set them to 0 here.
658-
if protocol == "udp" {
660+
switch protocol {
661+
case "udp":
659662
ns = append(ns[:2], append(make([]uint64, 3), ns[2:]...)...)
660-
} else if protocol == "tcp" {
663+
case "tcp":
661664
ns = append(ns[:fieldTransport11TCPLen], make([]uint64, fieldTransport11RDMAMaxLen-fieldTransport11TCPLen+3)...)
662-
} else if protocol == "rdma" {
665+
case "rdma":
663666
ns = append(ns[:fieldTransport10TCPLen], append(make([]uint64, 3), ns[fieldTransport10TCPLen:]...)...)
664667
}
665668

net_protocols.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,24 @@ func (ps NetProtocolStats) parseLine(rawLine string) (*NetProtocolStatLine, erro
115115
if err != nil {
116116
return nil, err
117117
}
118-
if fields[4] == enabled {
118+
switch fields[4] {
119+
case enabled:
119120
line.Pressure = 1
120-
} else if fields[4] == disabled {
121+
case disabled:
121122
line.Pressure = 0
122-
} else {
123+
default:
123124
line.Pressure = -1
124125
}
125126
line.MaxHeader, err = strconv.ParseUint(fields[5], 10, 64)
126127
if err != nil {
127128
return nil, err
128129
}
129-
if fields[6] == enabled {
130+
switch fields[6] {
131+
case enabled:
130132
line.Slab = true
131-
} else if fields[6] == disabled {
133+
case disabled:
132134
line.Slab = false
133-
} else {
135+
default:
134136
return nil, fmt.Errorf("%w: capability for protocol: %s", ErrFileParse, line.Name)
135137
}
136138
line.ModuleName = fields[7]
@@ -168,11 +170,12 @@ func (pc *NetProtocolCapabilities) parseCapabilities(capabilities []string) erro
168170
}
169171

170172
for i := 0; i < len(capabilities); i++ {
171-
if capabilities[i] == "y" {
173+
switch capabilities[i] {
174+
case "y":
172175
*capabilityFields[i] = true
173-
} else if capabilities[i] == "n" {
176+
case "n":
174177
*capabilityFields[i] = false
175-
} else {
178+
default:
176179
return fmt.Errorf("%w: capability block for protocol: position %d", ErrFileParse, i)
177180
}
178181
}

proc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ type Proc struct {
3737
type Procs []Proc
3838

3939
var (
40-
ErrFileParse = errors.New("Error Parsing File")
41-
ErrFileRead = errors.New("Error Reading File")
42-
ErrMountPoint = errors.New("Error Accessing Mount point")
40+
ErrFileParse = errors.New("error parsing file")
41+
ErrFileRead = errors.New("error reading file")
42+
ErrMountPoint = errors.New("error accessing mount point")
4343
)
4444

4545
func (p Procs) Len() int { return len(p) }
@@ -79,7 +79,7 @@ func (fs FS) Self() (Proc, error) {
7979
if err != nil {
8080
return Proc{}, err
8181
}
82-
pid, err := strconv.Atoi(strings.Replace(p, string(fs.proc), "", -1))
82+
pid, err := strconv.Atoi(strings.ReplaceAll(p, string(fs.proc), ""))
8383
if err != nil {
8484
return Proc{}, err
8585
}

0 commit comments

Comments
 (0)