Skip to content

Commit 89bce18

Browse files
authored
Switch to golangci-lint v2 (#2440)
* Switch to `golangci-lint` v2 v1 is deprecated, and `golangci/golangci-lint-action@v8` requires v2.1+. Use `golangci-lint migrate` to switch to v2 settings and remove outdated/deprecated settings. Ignore `nil` pointer lints for tests, since the linter doesn't handle `t.Fatal` appropriately. Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> * Fix linter errors Various new lint issues, mostly staticcheck quick fixes (via `golangci-ling --fix`): - embedded field selector - simplify conditionals via De Morgan - replace `strings.Replace(_, _, _, -1)` with `strings.ReplaceAll()` - switch `if/else-if` to `switch` - move conditional into infinite `for` loops - omit unnecessary type declaration Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com> --------- Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
1 parent 5ebc1c5 commit 89bce18

File tree

31 files changed

+223
-234
lines changed

31 files changed

+223
-234
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ jobs:
3434
cache: false
3535

3636
- name: Run golangci-lint
37-
uses: golangci/golangci-lint-action@v6
37+
uses: golangci/golangci-lint-action@v8
3838
with:
39-
version: v1.64
39+
version: v2.1
4040
args: >-
4141
--verbose
4242
--max-issues-per-linter=0

.golangci.yml

Lines changed: 153 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,165 @@
1+
version: "2"
2+
13
run:
2-
timeout: 8m
3-
tests: true
44
build-tags:
55
- admin
66
- functional
77
- integration
8+
tests: true
89

910
linters:
1011
enable:
11-
# defaults:
12-
# - errcheck
13-
# - gosimple
14-
# - govet
15-
# - ineffassign
16-
# - staticcheck
17-
# - typecheck
18-
# - unused
19-
2012
- errorlint # error wrapping (eg, not using `errors.Is`, using `%s` instead of `%w` in `fmt.Errorf`)
21-
- gofmt # whether code was gofmt-ed
22-
- govet # enabled by default, but just to be sure
2313
- nolintlint # ill-formed or insufficient nolint directives
24-
- stylecheck # golint replacement
2514
- thelper # test helpers without t.Helper()
2615

27-
linters-settings:
28-
govet:
29-
enable-all: true
30-
disable:
31-
# struct order is often for Win32 compat
32-
# also, ignore pointer bytes/GC issues for now until performance becomes an issue
33-
- fieldalignment
34-
35-
stylecheck:
36-
# https://staticcheck.io/docs/checks
37-
checks: ["all"]
38-
39-
issues:
40-
exclude-dirs:
41-
# paths are relative to module root
42-
- cri-containerd/test-images
43-
exclude-rules:
44-
# err is very often shadowed in nested scopes
45-
- linters:
46-
- govet
47-
text: '^shadow: declaration of "err" shadows declaration'
48-
49-
# path is relative to module root, which is ./test/
50-
- path: cri-containerd
51-
linters:
52-
- stylecheck
53-
text: "^ST1003: should not use underscores in package names$"
54-
source: "^package cri_containerd$"
55-
56-
# don't bother with propper error wrapping in test code
57-
- path: cri-containerd
58-
linters:
59-
- errorlint
60-
text: "non-wrapping format verb for fmt.Errorf"
61-
62-
# This repo has a LOT of generated schema files, operating system bindings, and other
63-
# things that ST1003 from stylecheck won't like (screaming case Windows api constants for example).
64-
# There's also some structs that we *could* change the initialisms to be Go friendly
65-
# (Id -> ID) but they're exported and it would be a breaking change.
66-
# This makes it so that most new code, code that isn't supposed to be a pretty faithful
67-
# mapping to an OS call/constants, or non-generated code still checks if we're following idioms,
68-
# while ignoring the things that are just noise or would be more of a hassle than it'd be worth to change.
69-
- path: layer.go
70-
linters:
71-
- stylecheck
72-
text: "ST1003:"
73-
74-
- path: hcsshim.go
75-
linters:
76-
- stylecheck
77-
text: "ST1003:"
78-
79-
- path: cmd\\ncproxy\\nodenetsvc\\
80-
linters:
81-
- stylecheck
82-
text: "ST1003:"
83-
84-
- path: cmd\\ncproxy_mock\\
85-
linters:
86-
- stylecheck
87-
text: "ST1003:"
88-
89-
- path: internal\\hcs\\schema2\\
90-
linters:
91-
- stylecheck
92-
- gofmt
93-
94-
- path: internal\\wclayer\\
95-
linters:
96-
- stylecheck
97-
text: "ST1003:"
98-
99-
- path: hcn\\
100-
linters:
101-
- stylecheck
102-
text: "ST1003:"
103-
104-
- path: internal\\hcs\\schema1\\
105-
linters:
106-
- stylecheck
107-
text: "ST1003:"
108-
109-
- path: internal\\hns\\
110-
linters:
111-
- stylecheck
112-
text: "ST1003:"
113-
114-
- path: ext4\\internal\\compactext4\\
115-
linters:
116-
- stylecheck
117-
text: "ST1003:"
118-
119-
- path: ext4\\internal\\format\\
120-
linters:
121-
- stylecheck
122-
text: "ST1003:"
123-
124-
- path: internal\\guestrequest\\
125-
linters:
126-
- stylecheck
127-
text: "ST1003:"
128-
129-
- path: internal\\guest\\prot\\
130-
linters:
131-
- stylecheck
132-
text: "ST1003:"
133-
134-
- path: internal\\windevice\\
135-
linters:
136-
- stylecheck
137-
text: "ST1003:"
138-
139-
- path: internal\\winapi\\
140-
linters:
141-
- stylecheck
142-
text: "ST1003:"
143-
144-
- path: internal\\vmcompute\\
145-
linters:
146-
- stylecheck
147-
text: "ST1003:"
148-
149-
- path: internal\\regstate\\
150-
linters:
151-
- stylecheck
152-
text: "ST1003:"
153-
154-
- path: internal\\hcserror\\
155-
linters:
156-
- stylecheck
157-
text: "ST1003:"
158-
159-
# v0 APIs are deprecated, but still retained for backwards compatability
160-
- path: cmd\\ncproxy\\
161-
linters:
162-
- staticcheck
163-
text: "^SA1019: .*(ncproxygrpc|nodenetsvc)[/]?v0"
164-
165-
- path: internal\\tools\\networkagent
166-
linters:
167-
- staticcheck
168-
text: "^SA1019: .*nodenetsvc[/]?v0"
169-
170-
- path: internal\\vhdx\\info
171-
linters:
172-
- stylecheck
173-
text: "ST1003:"
16+
settings:
17+
govet:
18+
disable:
19+
# struct order is often for Win32 compat
20+
# also, ignore pointer bytes/GC issues for now until performance becomes an issue
21+
- fieldalignment
22+
enable-all: true
23+
24+
staticcheck:
25+
# https://staticcheck.io/docs/checks
26+
checks:
27+
- all
28+
29+
exclusions:
30+
generated: lax
31+
presets:
32+
- comments
33+
- common-false-positives
34+
- legacy
35+
- std-error-handling
36+
rules:
37+
# err is very often shadowed in nested scopes
38+
- linters:
39+
- govet
40+
text: '^shadow: declaration of "err" shadows declaration'
41+
42+
# path is relative to module root, which is ./test/
43+
- linters:
44+
- staticcheck
45+
path: cri-containerd
46+
text: "^ST1003: should not use underscores in package names$"
47+
source: ^package cri_containerd$
48+
49+
# don't bother with propper error wrapping in test code
50+
- linters:
51+
- errorlint
52+
path: cri-containerd
53+
text: non-wrapping format verb for fmt.Errorf
54+
55+
# static check doesn't recognize `t.Fatal[f]?` when checking for potential `nil` pointer dereference
56+
- linters:
57+
- staticcheck
58+
path: ".*_test.go$"
59+
text: "^SA5011"
60+
61+
# This repo has a LOT of generated schema files, operating system bindings, and other
62+
# things that ST1003 from stylecheck won't like (screaming case Windows api constants for example).
63+
# There's also some structs that we *could* change the initialisms to be Go friendly
64+
# (Id -> ID) but they're exported and it would be a breaking change.
65+
# This makes it so that most new code, code that isn't supposed to be a pretty faithful
66+
# mapping to an OS call/constants, or non-generated code still checks if we're following idioms,
67+
# while ignoring the things that are just noise or would be more of a hassle than it'd be worth to change.
68+
- linters:
69+
- staticcheck
70+
path: layer.go
71+
text: "ST1003:"
72+
- linters:
73+
- staticcheck
74+
path: hcsshim.go
75+
text: "ST1003:"
76+
- linters:
77+
- staticcheck
78+
path: cmd/ncproxy/nodenetsvc/
79+
text: "ST1003:"
80+
- linters:
81+
- staticcheck
82+
path: cmd/ncproxy_mock/
83+
text: "ST1003:"
84+
- linters:
85+
- staticcheck
86+
path: internal/hcs/schema2/
87+
- linters:
88+
- staticcheck
89+
path: internal/wclayer/
90+
text: "ST1003:"
91+
- linters:
92+
- staticcheck
93+
path: hcn/
94+
text: "ST1003:"
95+
- linters:
96+
- staticcheck
97+
path: internal/hcs/schema1/
98+
text: "ST1003:"
99+
- linters:
100+
- staticcheck
101+
path: internal/hns/
102+
text: "ST1003:"
103+
- linters:
104+
- staticcheck
105+
path: ext4/internal/compactext4/
106+
text: "ST1003:"
107+
- linters:
108+
- staticcheck
109+
path: ext4/internal/format/
110+
text: "ST1003:"
111+
- linters:
112+
- staticcheck
113+
path: internal/guestrequest/
114+
text: "ST1003:"
115+
- linters:
116+
- staticcheck
117+
path: internal/guest/prot/
118+
text: "ST1003:"
119+
- linters:
120+
- staticcheck
121+
path: internal/windevice/
122+
text: "ST1003:"
123+
- linters:
124+
- staticcheck
125+
path: internal/winapi/
126+
text: "ST1003:"
127+
- linters:
128+
- staticcheck
129+
path: internal/vmcompute/
130+
text: "ST1003:"
131+
- linters:
132+
- staticcheck
133+
path: internal/regstate/
134+
text: "ST1003:"
135+
- linters:
136+
- staticcheck
137+
path: internal/hcserror/
138+
text: "ST1003:"
139+
140+
# v0 APIs are deprecated, but still retained for backwards compatability
141+
- linters:
142+
- staticcheck
143+
path: cmd/ncproxy/
144+
text: "^SA1019: .*(ncproxygrpc|nodenetsvc)[/]?v0"
145+
- linters:
146+
- staticcheck
147+
path: internal/tools/networkagent
148+
text: "^SA1019: .*nodenetsvc[/]?v0"
149+
- linters:
150+
- staticcheck
151+
path: internal/vhdx/info
152+
text: "ST1003:"
153+
154+
paths:
155+
# paths are relative to module root
156+
- cri-containerd/test-images
157+
158+
formatters:
159+
enable:
160+
- gofmt
161+
exclusions:
162+
generated: lax
163+
paths:
164+
- cri-containerd/test-images
165+
- internal/hcs/schema2/

hcn/hcnerrors.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,7 @@ var (
2323
)
2424

2525
func checkForErrors(methodName string, hr error, resultBuffer *uint16) error {
26-
errorFound := false
27-
28-
if hr != nil {
29-
errorFound = true
30-
}
26+
errorFound := hr != nil
3127

3228
result := ""
3329
if resultBuffer != nil {

internal/cmd/io_npipe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (nprw *nPipeRetryWriter) Write(p []byte) (n int, err error) {
114114
}).Error("Named pipe disconnected, retrying dial")
115115

116116
// Close the old conn first.
117-
nprw.Conn.Close()
117+
nprw.Close()
118118
newConn, retryErr := nprw.retryDialPipe()
119119
if retryErr == nil {
120120
log.G(nprw.ctx).WithField("address", nprw.pipePath).Info("Succeeded in reconnecting to named pipe")

internal/exec/exec.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (e *Exec) Start() error {
113113
pi := new(windows.ProcessInformation)
114114

115115
// Need EXTENDED_STARTUPINFO_PRESENT as we're making use of the attribute list field.
116-
flags := uint32(windows.CREATE_UNICODE_ENVIRONMENT) | windows.EXTENDED_STARTUPINFO_PRESENT | e.execConfig.processFlags
116+
flags := uint32(windows.CREATE_UNICODE_ENVIRONMENT) | windows.EXTENDED_STARTUPINFO_PRESENT | e.processFlags
117117

118118
// Allocate an attribute list that's large enough to do the operations we care about
119119
// 1. Assigning to a job object at creation time
@@ -177,9 +177,9 @@ func (e *Exec) Start() error {
177177

178178
siEx.ProcThreadAttributeList = attrList.List()
179179
siEx.Cb = uint32(unsafe.Sizeof(*siEx))
180-
if e.execConfig.token != 0 {
180+
if e.token != 0 {
181181
err = windows.CreateProcessAsUser(
182-
e.execConfig.token,
182+
e.token,
183183
argv0p,
184184
argvp,
185185
pSec,

internal/guest/network/netns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func configureLink(ctx context.Context,
247247

248248
// dst will be nil when setting default gateways
249249
var dst *net.IPNet
250-
if !(r.DestinationPrefix == ipv4GwDestination || r.DestinationPrefix == ipv6GwDestination) {
250+
if r.DestinationPrefix != ipv4GwDestination && r.DestinationPrefix != ipv6GwDestination {
251251
dstIP, dstAddr, err := net.ParseCIDR(r.DestinationPrefix)
252252
if err != nil {
253253
return fmt.Errorf("parsing route dst address %s failed: %w", r.DestinationPrefix, err)

0 commit comments

Comments
 (0)