forked from kubernetes-sigs/cluster-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.golangci.yml
More file actions
428 lines (428 loc) · 17.5 KB
/
.golangci.yml
File metadata and controls
428 lines (428 loc) · 17.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
version: "2"
run:
timeout: 10m
go: "1.25"
build-tags:
- tools
- e2e
allow-parallel-runners: true
linters:
default: none
enable:
- asasalint # warns about passing []any to func(...any) without expanding it
- asciicheck # non ascii symbols
- bidichk # dangerous unicode sequences
- bodyclose # unclosed http bodies
- containedctx # context.Context nested in a struct
- copyloopvar # copying loop variables
- dogsled # too many blank identifiers in assignments
- dupword # duplicate words
- durationcheck # multiplying two durations
- errcheck # unchecked errors
- errchkjson # invalid types passed to json encoder
- forbidigo # allows to block usage of funcs
- ginkgolinter # ginkgo and gomega
- gocritic # bugs, performance, style (we could add custom ones to this one)
- godot # checks that comments end in a period
- godox # block FIXMEs
- goprintffuncname # printft-like functions should be named with f at the end
- gosec # potential security problems
- govet # basically 'go vet'
- importas # consistent import aliases
- ineffassign # ineffectual assignments
- intrange # suggest using integer range in for loops
- loggercheck # check for even key/value pairs in logger calls
- misspell # spelling
- nakedret # naked returns (named return parameters and an empty return)
- nilerr # returning nil after checking err is not nil
- noctx # http requests without context.Context
- nolintlint # badly formatted nolint directives
- nosprintfhostport # using sprintf to construct host:port in a URL
- prealloc # suggest preallocating slices
- predeclared # shadowing predeclared identifiers
- revive # better version of golint
- staticcheck # some of staticcheck's rules
- thelper # test helpers not starting with t.Helper()
- unconvert # unnecessary type conversions
- unparam # unused function parameters
- unused # unused constants, variables,functions, types
- usestdlibvars # using variables/constants from the standard library
- usetesting # report function to be replace by testing
- whitespace # unnecessary newlines
disable:
# TODO: It will be dropped when the Go version migration is done.
- usetesting
settings:
forbidigo:
forbid:
- pattern: ctrl.NewControllerManagedBy
msg: Use capicontrollerutil.NewControllerManagedBy instead
ginkgolinter:
forbid-focus-container: true
gocritic:
disabled-checks:
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
- rangeValCopy
- hugeParam
enabled-tags:
- diagnostic
- experimental
- performance
godot:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
scope: toplevel
exclude:
- ^ \+.*
- ^ ANCHOR.*
- '^ (alpha|beta|GA): v.*'
godox:
keywords:
- FIXME # FIXME's should be removed before merging PRs
gosec:
excludes:
# integer overflow conversion int -> int32
- G115
importas:
alias:
# Kubernetes
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
alias: apiextensionsv1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: apierrors
- pkg: k8s.io/apimachinery/pkg/util/errors
alias: kerrors
- pkg: k8s.io/component-base/logs/api/v1
alias: logsv1
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# CABPK
- pkg: sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta1
alias: bootstrapv1beta1
- pkg: sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2
alias: bootstrapv1
# KCP
- pkg: sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta1
alias: controlplanev1beta1
- pkg: sigs.k8s.io/cluster-api/api/controlplane/kubeadm/v1beta2
alias: controlplanev1
# CAPI
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta1
alias: clusterv1beta1
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta2
alias: clusterv1
# CAPI exp addons
- pkg: sigs.k8s.io/cluster-api/api/addons/v1beta1
alias: addonsv1beta1
- pkg: sigs.k8s.io/cluster-api/api/addons/v1beta2
alias: addonsv1
# CAPI exp IPAM
- pkg: sigs.k8s.io/cluster-api/api/ipam/v1beta1
alias: ipamv1beta1
- pkg: sigs.k8s.io/cluster-api/api/ipam/v1beta2
alias: ipamv1
# CAPI exp runtime
- pkg: sigs.k8s.io/cluster-api/api/runtime/v1alpha1
alias: runtimev1alpha1
- pkg: sigs.k8s.io/cluster-api/api/runtime/v1beta2
alias: runtimev1
- pkg: sigs.k8s.io/cluster-api/api/runtime/hooks/v1alpha1
alias: runtimehooksv1
- pkg: sigs.k8s.io/cluster-api/exp/runtime/controllers
alias: runtimecontrollers
- pkg: sigs.k8s.io/cluster-api/exp/runtime/catalog
alias: runtimecatalog
- pkg: sigs.k8s.io/cluster-api/internal/runtime/client
alias: internalruntimeclient
- pkg: sigs.k8s.io/cluster-api/exp/runtime/client
alias: runtimeclient
- pkg: sigs.k8s.io/cluster-api/internal/runtime/registry
alias: runtimeregistry
- pkg: sigs.k8s.io/cluster-api/internal/webhooks/runtime
alias: runtimewebhooks
# CAPI utils
- pkg: sigs.k8s.io/cluster-api/util/conditions/deprecated/v1beta1
alias: v1beta1conditions
- pkg: sigs.k8s.io/cluster-api/util/conditions
alias: ""
- pkg: sigs.k8s.io/cluster-api/util/patch
alias: ""
- pkg: sigs.k8s.io/cluster-api/internal/topology/names
alias: topologynames
- pkg: sigs.k8s.io/cluster-api/internal/util/client
alias: "clientutil"
- pkg: sigs.k8s.io/cluster-api/util/controller
alias: "capicontrollerutil"
# CAPD
- pkg: sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta1
alias: infrav1beta1
- pkg: sigs.k8s.io/cluster-api/test/infrastructure/docker/api/v1beta2
alias: infrav1
# CAPD exp
- pkg: sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta1
alias: infraexpv1beta1
- pkg: sigs.k8s.io/cluster-api/test/infrastructure/docker/exp/api/v1beta2
alias: infraexpv1
no-unaliased: true
nolintlint:
require-specific: true
allow-unused: false
revive:
rules:
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id
#
# Rules in addition to the recommended configuration above.
#
- name: bool-literal-in-expr
- name: constant-logical-expr
exclusions:
generated: strict
paths:
- zz_generated.*\.go$
- vendored_openapi\.go$
rules:
# Specific exclude rules for deprecated fields that are still part of the codebase. These
# should be removed as the referenced deprecated item is removed from the project.
- linters:
- staticcheck
text: 'SA1019: (bootstrapv1.ClusterStatus|DockerMachine.Spec.Bootstrapped|machineStatus.Bootstrapped|dockerMachine.Spec.Backend.Docker.Bootstrapped|dockerMachine.Spec.Bootstrapped|devMachine.Spec.Backend.Docker.Bootstrapped|clusterv1.ClusterClassVariableMetadata|(variable|currentDefinition|specVar|newVariableDefinition|statusVarDefinition|out).DeprecatedV1Beta1Metadata) is deprecated'
# Deprecations for MHC MaxUnhealthy, UnhealthyRange
- linters:
- staticcheck
text: 'SA1019: (mhc|m)(.Spec.MaxUnhealthy|.Spec.UnhealthyRange) is deprecated'
# Specific exclude rules for deprecated packages that are still part of the codebase. These
# should be removed as the referenced deprecated packages are removed from the project.
- linters:
- staticcheck
text: 'SA1019: .* is deprecated: This package will be removed in one of the next releases.'
- linters:
- staticcheck
text: 'SA1019: .* is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
# Specific exclude rules for deprecated types that are still part of the codebase. These
# should be removed as the referenced deprecated types are removed from the project.
# v1Beta1 deprecated fields/types
- linters:
- staticcheck
text: 'SA1019: .*\.Deprecated\.V1Beta1.* is deprecated'
- linters:
- staticcheck
text: 'SA1019: clusterv1\.(Condition|Conditions|ConditionSeverity|ConditionType) is deprecated'
# TODO: var-naming: avoid meaningless package names by revive
# * test/infrastructure/docker/internal/docker/types/
# * bootstrap/kubeadm/types/
# * internal/webhooks/util/
# * util/
# * exp/util/
# * controlplane/kubeadm/internal/etcd/util/
# * cmd/clusterctl/internal/util/
# * bootstrap/util/
- linters:
- revive
text: 'var-naming: avoid meaningless package names'
path: test/infrastructure/docker/internal/docker/types/.*\.go$|bootstrap/kubeadm/types/.*\.go$|internal/webhooks/util/.*\.go$|util/.*\.go$|exp/util/.*\.go$|controlplane/kubeadm/internal/etcd/util/.*\.go$|cmd/clusterctl/internal/util/.*\.go$|bootstrap/util/.*\.go$
- linters:
- revive
text: 'exported: exported method .*\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported'
- linters:
- errcheck
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
# deprecated feature gates
- linters:
- staticcheck
text: 'SA1019: feature.MachineWaitForVolumeDetachConsiderVolumeAttachments is deprecated'
# v1beta1 deprecated util packages
- linters:
- staticcheck
text: 'SA1019: .* is deprecated'
path: util/deprecated/v1beta1/.*\.go$
- linters:
- staticcheck
text: "QF1001: could apply De Morgan's law"
path: util/deprecated/v1beta1/.*\.go$
- linters:
- importas
text: 'imported as ".*" but must be ".*" according to config'
path: util/deprecated/v1beta1/.*\.go$
# Excludes for controller-runtime deprecations that we should migrate away from sooner or later
- linters:
- staticcheck
text: 'SA1019: (env|mgr).GetEventRecorderFor is deprecated'
# Exclude some packages or code to require comments, for example test code, or fake clients.
- linters:
- revive
text: exported (method|function|type|const) (.+) should have comment or be unexported
source: (func|type).*Fake.*
- linters:
- revive
path: fake_\.go
text: exported (method|function|type|const) (.+) should have comment or be unexported
- linters:
- revive
path: cmd/clusterctl/internal/test/providers.*.go
text: exported (method|function|type|const) (.+) should have comment or be unexported
- linters:
- revive
path: (framework|e2e)/.*.go
text: exported (method|function|type|const) (.+) should have comment or be unexported
# Disable unparam "always receives" which might not be really
# useful when building libraries.
- linters:
- unparam
text: always receives
# Dot imports for gomega and ginkgo are allowed
# within test files and test utils.
- linters:
- revive
- staticcheck
path: _test\.go
text: should not use dot imports
- linters:
- revive
- staticcheck
path: (framework|e2e)/.*.go
text: should not use dot imports
# Large parts of this file are duplicate from k/k. Let's ignore "emptyStringTest" to reduce the noise in diffs
# and to avoid making mistakes by diverging from upstream just because of this purely stylistic linter finding.
- linters:
- gocritic
path: internal/topology/variables/clusterclass_variable_validation.go
text: emptyStringTest
# Append should be able to assign to a different var/slice.
- linters:
- gocritic
text: 'appendAssign: append result not assigned to the same slice'
# Disable linters for conversion
- linters:
- staticcheck
path: .*(api|types)\/.*\/conversion.*\.go$
text: 'SA1019: in.(.+) is deprecated'
- linters:
- revive
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
# Checking if an error is nil to just after return the error or nil is redundant
text: 'if-return: redundant if ...; err != nil check, just return error instead'
- linters:
- revive
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
# Exported function and methods should have comments. This warns on undocumented exported functions and methods.
text: exported (method|function|type|const) (.+) should have comment or be unexported
- linters:
- revive
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
# This rule warns when initialism, variable or package naming conventions are not followed.
text: 'var-naming: don''t use underscores in Go names;'
- linters:
- revive
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
# By convention, receiver names in a method should reflect their identity.
text: 'receiver-naming: receiver name'
- linters:
- staticcheck
path: .*(api|types|test)\/.*\/conversion.*\.go$
text: 'ST1003: should not use underscores in Go names;'
- linters:
- staticcheck
path: .*(api|types)\/.*\/conversion.*\.go$
text: 'ST1016: methods on the same type should have the same receiver name'
# We don't care about defer in for loops in test files.
- linters:
- gocritic
path: _test\.go
text: 'deferInLoop: Possible resource leak, ''defer'' is called in the ''for'' loop'
# Ignore non-constant format string in call to condition utils
- linters:
- govet
text: non-constant format string in call to sigs\.k8s\.io\/cluster-api\/util\/conditions\.
- linters:
- govet
text: non-constant format string in call to sigs\.k8s\.io\/cluster-api\/util\/deprecated\/v1beta1\/conditions\.
- linters:
- goconst
path: (.+)_test\.go
# It's clearer to see that a field gets accessed or func gets called on the embedded objects
- linters:
- staticcheck
path: (.+)\.go$
text: 'QF1008: could remove embedded field'
- linters:
- revive
path: errors/.*\.go$
text: 'var-naming: avoid package names that conflict with Go standard library package names'
- linters:
- revive
path: internal/util/hash/.*\.go$
text: 'var-naming: avoid package names that conflict with Go standard library package names'
- linters:
- revive
path: internal/controllers/topology/cluster/patches/api/.*\.go$
text: 'var-naming: avoid meaningless package names'
- linters:
- revive
path: test/infrastructure/inmemory/pkg/server/api/.*\.go$
text: 'var-naming: avoid meaningless package names'
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gci # ensures imports are organized
- gofmt # warns about incorrect use of fmt functions
- goimports # import formatting
settings:
gci:
sections:
- standard # Standard section: captures all standard packages.
- default # Default section: contains all imports that could not be matched to another section type.
- prefix(sigs.k8s.io/cluster-api) # Custom section: groups all imports with the specified Prefix.
custom-order: true
exclusions:
generated: strict
paths:
- zz_generated.*\.go$
- vendored_openapi\.go$