Skip to content

Commit 1674753

Browse files
committed
upgrade to golangci-lint v2 and fix all warnings
1 parent a68777d commit 1674753

File tree

8 files changed

+173
-186
lines changed

8 files changed

+173
-186
lines changed

.github/workflows/pullrequests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
with:
1818
go-version: 1.24
1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v6.5.0
20+
uses: golangci/golangci-lint-action@v8.0.0
2121
with:
22-
version: v1.64.6
22+
version: v2.2.1
2323

2424
test:
2525
name: test

.golangci.yml

Lines changed: 159 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
1+
version: "2"
2+
run:
3+
build-tags:
4+
- e2e
5+
allow-parallel-runners: true
16
linters:
2-
disable-all: true
7+
default: none
38
enable:
49
- asciicheck
510
- bodyclose
611
- containedctx
12+
- copyloopvar
713
- dogsled
814
- errcheck
9-
- copyloopvar
10-
- gci
1115
- ginkgolinter
1216
- goconst
1317
- gocritic
1418
- godot
15-
- gofmt
16-
- goimports
1719
- goprintffuncname
1820
- gosec
19-
- gosimple
2021
- govet
2122
- importas
2223
- ineffassign
@@ -30,175 +31,162 @@ linters:
3031
- revive
3132
- rowserrcheck
3233
- staticcheck
33-
- stylecheck
3434
- thelper
35-
- typecheck
3635
- unconvert
3736
- unparam
3837
- unused
3938
- whitespace
40-
41-
linters-settings:
42-
godot:
43-
# declarations - for top level declaration comments (default);
44-
# toplevel - for top level comments;
45-
# all - for all comments.
46-
scope: toplevel
47-
exclude:
48-
- '^ \+.*'
49-
- '^ ANCHOR.*'
50-
importas:
51-
no-unaliased: true
52-
alias:
53-
# Kubernetes
54-
- pkg: k8s.io/api/core/v1
55-
alias: corev1
56-
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
57-
alias: apiextensionsv1
58-
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
59-
alias: metav1
60-
- pkg: k8s.io/apimachinery/pkg/api/errors
61-
alias: apierrors
62-
- pkg: k8s.io/apimachinery/pkg/util/errors
63-
alias: kerrors
64-
# Controller Runtime
65-
- pkg: sigs.k8s.io/controller-runtime
66-
alias: ctrl
67-
# CAPI
68-
- pkg: sigs.k8s.io/cluster-api/api/v1alpha3
69-
alias: clusterv1alpha3
70-
- pkg: sigs.k8s.io/cluster-api/api/v1alpha4
71-
alias: clusterv1alpha4
72-
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
73-
alias: clusterv1
74-
# CAPI exp IPAM
75-
- pkg: sigs.k8s.io/cluster-api/exp/ipamapi/v1alpha1
76-
alias: ipamv1
77-
nolintlint:
78-
allow-unused: false
79-
require-specific: true
80-
gosec:
81-
excludes:
82-
- G307 # Deferring unsafe method "Close" on type "\*os.File"
83-
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
84-
gocritic:
85-
enabled-tags:
86-
- experimental
87-
disabled-checks:
88-
- appendAssign
89-
- dupImport # https://github.com/go-critic/go-critic/issues/845
90-
- evalOrder
91-
- ifElseChain
92-
- octalLiteral
93-
- regexpSimplify
94-
- sloppyReassign
95-
- truncateCmp
96-
- typeDefFirst
97-
- unnamedResult
98-
- unnecessaryDefer
99-
- whyNoLint
100-
- wrapperFunc
39+
settings:
40+
gocritic:
41+
disabled-checks:
42+
- appendAssign
43+
- dupImport
44+
- evalOrder
45+
- ifElseChain
46+
- octalLiteral
47+
- regexpSimplify
48+
- sloppyReassign
49+
- truncateCmp
50+
- typeDefFirst
51+
- unnamedResult
52+
- unnecessaryDefer
53+
- whyNoLint
54+
- wrapperFunc
55+
enabled-tags:
56+
- experimental
57+
godot:
58+
scope: toplevel
59+
exclude:
60+
- ^ \+.*
61+
- ^ ANCHOR.*
62+
gosec:
63+
excludes:
64+
- G307
65+
- G108
66+
importas:
67+
alias:
68+
- pkg: k8s.io/api/core/v1
69+
alias: corev1
70+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
71+
alias: apiextensionsv1
72+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
73+
alias: metav1
74+
- pkg: k8s.io/apimachinery/pkg/api/errors
75+
alias: apierrors
76+
- pkg: k8s.io/apimachinery/pkg/util/errors
77+
alias: kerrors
78+
- pkg: sigs.k8s.io/controller-runtime
79+
alias: ctrl
80+
- pkg: sigs.k8s.io/cluster-api/api/v1alpha3
81+
alias: clusterv1alpha3
82+
- pkg: sigs.k8s.io/cluster-api/api/v1alpha4
83+
alias: clusterv1alpha4
84+
- pkg: sigs.k8s.io/cluster-api/api/v1beta1
85+
alias: clusterv1
86+
- pkg: sigs.k8s.io/cluster-api/exp/ipamapi/v1alpha1
87+
alias: ipamv1
88+
no-unaliased: true
89+
nolintlint:
90+
require-specific: true
91+
allow-unused: false
92+
exclusions:
93+
generated: lax
94+
rules:
95+
- linters:
96+
- revive
97+
text: 'exported: exported method .*\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported'
98+
- linters:
99+
- errcheck
100+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
101+
- linters:
102+
- revive
103+
text: exported (method|function|type|const) (.+) should have comment or be unexported
104+
source: (func|type).*Fake.*
105+
- linters:
106+
- revive
107+
path: fake_\.go
108+
text: exported (method|function|type|const) (.+) should have comment or be unexported
109+
- linters:
110+
- revive
111+
path: cmd/clusterctl/internal/test/providers.*.go
112+
text: exported (method|function|type|const) (.+) should have comment or be unexported
113+
- linters:
114+
- revive
115+
path: (framework|e2e)/.*.go
116+
text: exported (method|function|type|const) (.+) should have comment or be unexported
117+
- linters:
118+
- unparam
119+
text: always receives
120+
- path: _test\.go
121+
text: should not use dot imports
122+
- path: (framework|e2e)/.*.go
123+
text: should not use dot imports
124+
- path: _test\.go
125+
text: cyclomatic complexity
126+
- linters:
127+
- gocritic
128+
text: 'appendAssign: append result not assigned to the same slice'
129+
- linters:
130+
- ifshort
131+
path: controllers/mdutil/util.go
132+
text: variable .* is only used in the if-statement
133+
- linters:
134+
- staticcheck
135+
path: .*(api|types)\/.*\/conversion.*\.go$
136+
text: 'SA1019: in.(.+) is deprecated'
137+
- linters:
138+
- revive
139+
path: .*(api|types|test)\/.*\/conversion.*\.go$
140+
text: exported (method|function|type|const) (.+) should have comment or be unexported
141+
- linters:
142+
- revive
143+
path: .*(api|types|test)\/.*\/conversion.*\.go$
144+
text: 'var-naming: don''t use underscores in Go names;'
145+
- linters:
146+
- revive
147+
path: .*(api|types)\/.*\/conversion.*\.go$
148+
text: 'receiver-naming: receiver name'
149+
- linters:
150+
- staticcheck
151+
path: .*(api|types|test)\/.*\/conversion.*\.go$
152+
text: 'ST1003: should not use underscores in Go names;'
153+
- linters:
154+
- staticcheck
155+
path: .*(api|types)\/.*\/conversion.*\.go$
156+
text: 'ST1016: methods on the same type should have the same receiver name'
157+
- linters:
158+
- ifshort
159+
path: ^internal/controllers/machine/machine_controller\.go$
160+
text: variable 'isDeleteNodeAllowed' is only used in the if-statement.*
161+
- linters:
162+
- ifshort
163+
path: ^controlplane/kubeadm/internal/workload_cluster_conditions\.go$
164+
text: variable 'kcpMachinesWithErrors' is only used in the if-statement.*
165+
- linters:
166+
- gocritic
167+
path: _test\.go
168+
text: 'deferInLoop: Possible resource leak, ''defer'' is called in the ''for'' loop'
169+
paths:
170+
- third_party$
171+
- builtin$
172+
- examples$
101173
issues:
102-
max-same-issues: 0
103174
max-issues-per-linter: 0
104-
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
105-
# changes in PRs and avoid nitpicking.
106-
exclude-use-default: false
107-
exclude-rules:
108-
- linters:
109-
- revive
110-
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
111-
- linters:
112-
- errcheck
113-
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
114-
# Exclude some packages or code to require comments, for example test code, or fake clients.
115-
- linters:
116-
- revive
117-
text: exported (method|function|type|const) (.+) should have comment or be unexported
118-
source: (func|type).*Fake.*
119-
- linters:
120-
- revive
121-
text: exported (method|function|type|const) (.+) should have comment or be unexported
122-
path: fake_\.go
123-
- linters:
124-
- revive
125-
text: exported (method|function|type|const) (.+) should have comment or be unexported
126-
path: cmd/clusterctl/internal/test/providers.*.go
127-
- linters:
128-
- revive
129-
text: exported (method|function|type|const) (.+) should have comment or be unexported
130-
path: "(framework|e2e)/.*.go"
131-
# Disable unparam "always receives" which might not be really
132-
# useful when building libraries.
133-
- linters:
134-
- unparam
135-
text: always receives
136-
# Dot imports for gomega or ginkgo are allowed
137-
# within test files.
138-
- path: _test\.go
139-
text: should not use dot imports
140-
- path: (framework|e2e)/.*.go
141-
text: should not use dot imports
142-
- path: _test\.go
143-
text: cyclomatic complexity
144-
# Append should be able to assign to a different var/slice.
145-
- linters:
146-
- gocritic
147-
text: "appendAssign: append result not assigned to the same slice"
148-
# ifshort flags variables that are only used in the if-statement even though there is
149-
# already a SimpleStmt being used in the if-statement in question.
150-
- linters:
151-
- ifshort
152-
text: "variable .* is only used in the if-statement"
153-
path: controllers/mdutil/util.go
154-
# Disable linters for conversion
155-
- linters:
156-
- staticcheck
157-
text: "SA1019: in.(.+) is deprecated"
158-
path: .*(api|types)\/.*\/conversion.*\.go$
159-
- linters:
160-
- revive
161-
text: exported (method|function|type|const) (.+) should have comment or be unexported
162-
path: .*(api|types|test)\/.*\/conversion.*\.go$
163-
- linters:
164-
- revive
165-
text: "var-naming: don't use underscores in Go names;"
166-
path: .*(api|types|test)\/.*\/conversion.*\.go$
167-
- linters:
168-
- revive
169-
text: "receiver-naming: receiver name"
170-
path: .*(api|types)\/.*\/conversion.*\.go$
171-
- linters:
172-
- stylecheck
173-
text: "ST1003: should not use underscores in Go names;"
174-
path: .*(api|types|test)\/.*\/conversion.*\.go$
175-
- linters:
176-
- stylecheck
177-
text: "ST1016: methods on the same type should have the same receiver name"
178-
path: .*(api|types)\/.*\/conversion.*\.go$
179-
# TODO(sbueringer) Ignore ifshort false positive: https://github.com/esimonov/ifshort/issues/23
180-
- linters:
181-
- ifshort
182-
text: "variable 'isDeleteNodeAllowed' is only used in the if-statement.*"
183-
path: ^internal/controllers/machine/machine_controller\.go$
184-
- linters:
185-
- ifshort
186-
text: "variable 'kcpMachinesWithErrors' is only used in the if-statement.*"
187-
path: ^controlplane/kubeadm/internal/workload_cluster_conditions\.go$
188-
# We don't care about defer in for loops in test files.
189-
- linters:
190-
- gocritic
191-
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
192-
path: _test\.go
193-
194-
run:
195-
timeout: 10m
196-
build-tags:
197-
- e2e
198-
# skip-files:
199-
# - "zz_generated.*\\.go$"
200-
# - "vendored_openapi\\.go$"
201-
# - "api/.*/conversion\\.go$"
202-
# skip-dirs:
203-
# - third_party
204-
allow-parallel-runners: true
175+
max-same-issues: 0
176+
formatters:
177+
enable:
178+
- gci
179+
- gofmt
180+
- goimports
181+
settings:
182+
gci:
183+
sections:
184+
- standard
185+
- default
186+
custom-order: true
187+
exclusions:
188+
generated: lax
189+
paths:
190+
- third_party$
191+
- builtin$
192+
- examples$

internal/controllers/infobloxinstance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636

3737
// InfobloxInstanceReconciler reconciles a InfobloxInstance object.
3838
type InfobloxInstanceReconciler struct {
39-
client.Client
39+
Client client.Client
4040
Scheme *runtime.Scheme
4141

4242
OperatorNamespace string

internal/controllers/infobloxippool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545

4646
// InfobloxIPPoolReconciler reconciles a InfobloxIPPool object.
4747
type InfobloxIPPoolReconciler struct {
48-
client.Client
48+
Client client.Client
4949
Scheme *runtime.Scheme
5050

5151
OperatorNamespace string

internal/controllers/ipaddressclaim.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var _ ipamutil.ProviderAdapter = &InfobloxProviderAdapter{}
5959

6060
// InfobloxClaimHandler handles infoblox claims.
6161
type InfobloxClaimHandler struct {
62-
client.Client
62+
Client client.Client
6363
claim *ipamv1.IPAddressClaim
6464
pool *v1alpha1.InfobloxIPPool
6565
newInfobloxClientFunc func(config infoblox.Config) (infoblox.Client, error)

0 commit comments

Comments
 (0)