-
Notifications
You must be signed in to change notification settings - Fork 485
Expand file tree
/
Copy path.golangci.yml
More file actions
414 lines (414 loc) · 17 KB
/
Copy path.golangci.yml
File metadata and controls
414 lines (414 loc) · 17 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
# NOTE: When updating shared linter settings, keep test/.golangci.yml in sync.
# The test config excludes kubeapilinter (which requires a custom-built binary).
version: "2"
run:
build-tags:
- e2e
allow-parallel-runners: true
linters:
default: none
enable:
- asasalint # warns about passing []any to func(...any) without expanding it
- kubeapilinter # validates Kubernetes API types against API conventions
- 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
- exhaustruct # checks if all structure fields are initialized
- ginkgolinter # ginkgo and gomega
- goconst # strings that can be replaced by constants
- gocritic # bugs, performance, style (we could add custom ones to this one)
- godot # checks that comments end in a period
- 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
# We don't want to use this one: https://github.com/kubernetes-sigs/cluster-api-provider-azure/pull/4703
# - 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 # reports uses of functions with replacement inside the testing package
- whitespace # unnecessary newlines
settings:
goconst:
# goconst now counts occurrences package-wide. Ignore common strings that
# are intentionally not constants to avoid noise from this newer behavior.
ignore-string-values: '^(1\.0|true|1\.28\.12|cncf-upstream|containerd|Cluster|vmss|azure\.json|AzureManagedMachinePool|MachinePool|test-cluster|custom-vnet|my-vnet|spec|name)$'
exhaustruct:
include:
# Hub ASO agent pools should be fully defined to prevent unnecessary updates
- .*storage\..*AgentPoolProfile$
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
enabled-tags:
- experimental
godot:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
scope: toplevel
exclude:
- ^ \+.*
- ^ ANCHOR.*
gosec:
excludes:
- G307 # Deferring unsafe method "Close" on type "\*os.File"
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
- G115 # integer overflow conversion int -> int32
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
# Controller Runtime
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
# CAPI
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta2
alias: clusterv1
- pkg: sigs.k8s.io/cluster-api/api/core/v1beta1
alias: clusterv1beta1
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions
alias: v1beta1conditions
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/conditions/v1beta2
alias: v1beta2conditions
- pkg: sigs.k8s.io/cluster-api/util/deprecated/v1beta1/patch
alias: v1beta1patch
# CAPBK
- pkg: sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta2
alias: bootstrapv1
- pkg: sigs.k8s.io/cluster-api/api/bootstrap/kubeadm/v1beta1
alias: bootstrapv1beta1
# CAPZ
- pkg: sigs.k8s.io/cluster-api-provider-azure/api/v1beta1
alias: infrav1
# CAPZ exp
- pkg: sigs.k8s.io/cluster-api-provider-azure/exp/api/v1beta1
alias: infrav1exp
- pkg: sigs.k8s.io/cluster-api-provider-azure/util/webhook
alias: webhookutils
# Azure
- pkg: github.com/Azure/go-autorest/autorest/azure
alias: azureautorest
# ASO
- pkg: github.com/Azure/azure-service-operator/v2/api/resources/v1api20200601
alias: asoresourcesv1
# Azureutil
- pkg: sigs.k8s.io/cluster-api-provider-azure/util/azure
alias: azureutil
# Deprecated
- pkg: github.com/Azure/go-autorest/autorest/to
alias: deprecated-use-k8s.io-utils-pointer
no-unaliased: true
nolintlint:
require-specific: true
allow-unused: false
custom:
kubeapilinter:
type: module
path: sigs.k8s.io/kube-api-linter
description: Kube API Linter validates Kubernetes API types against API conventions
settings:
linters:
# Disable all linters by default and enable only specific ones.
# This allows gradual adoption of API conventions.
disable:
- "*"
enable:
# Enable linters with low/zero issue counts that enforce critical conventions
- duplicatemarkers # Removes duplicate markers (1 issue, has auto-fix)
- jsontags # Ensures proper JSON tag formatting
- nofloats # Prevents float type usage
- nomaps # Restricts map usage
- nonullable # Prevents usage of the nullable marker
- nophase # Prevents Phase field usage
- notimestamp # Prevents TimeStamp field usage
lintersConfig: {}
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: 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
- name: exported
arguments:
- disableStutteringCheck
exclusions:
generated: lax
rules:
# Only run kubeapilinter on API type files (not tests, webhooks, validation, conversion, defaults)
- linters:
- kubeapilinter
path-except: "^api/.*_types\\.go$|^exp/api/.*_types\\.go$|^api/.*/types\\.go$|^api/.*/types_.*\\.go$|^api/.*/consts\\.go$"
- path: (\w*)conversion.go
text: use underscores in Go names|receiver name (.+) should be consistent|methods on the same type should have the same receiver name
- path: mock(\w+)/doc.go$
text: use underscores in package names|don't use an underscore in package name
- linters:
- dogsled
- exhaustruct
- goconst
- godot
path: (^test/|_test.go$)
- path: (^test/|_test.go$)
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
- text: should not use dot imports
source: \"github.com/onsi/(ginkgo/v2|gomega)\"
- 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
# Dot imports for gomega and ginkgo are allowed
# within test files and test utils.
- linters:
- revive
path: _test\.go
text: should not use dot imports
# Exclude some packages or code to require comments, for example test code, or fake clients.
- 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)\/.*\/conversion.*\.go$
# By convention, receiver names in a method should reflect their identity.
text: 'receiver-naming: receiver name'
- linters:
- staticcheck
# Ignoring stylistic checks for generated code
path: .*(api|types)\/.*\/conversion.*\.go$
text: 'ST1016: methods on the same type should have the same receiver name'
- linters:
- staticcheck
text: 'QF1008: could remove embedded field'
- linters:
- staticcheck
text: 'QF1012:'
# The govet "inline" analyzer only emits informational notes; ignore them.
- linters:
- govet
text: 'cannot inline'
# gosec credential/taint rules: false positives in test fixtures.
- linters:
- gosec
path: _test\.go
text: '(G101|G705):'
- linters:
- gosec
path: ^test/
text: 'G703:'
- linters:
- gosec
path: ^test/e2e/
text: 'G204:'
# images.go is a version-to-image data map; goconst noise on map values.
- linters:
- goconst
path: azure/services/virtualmachineimages/images\.go$
# 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\.
# for i = x; i < y; i++ {} is already optimal; Ignore this linter message
- linters:
- intrange
text: for loop can be changed to use an integer range
# Ignore the return value of below functions in test files
- linters:
- errcheck
path: (^test\/e2e\/.*\.go$|.*_test\.go$)
text: Error return value of (`os.Setenv`|`fmt.Fprintf`|`resp.Body.Close`|`os.Unsetenv`|`fmt.Fprintln`|`[\w\.]+\.Close`|`[\w\.]+\.Flush`|`[\w\.]+\.RemoveAll`) is not checked
# Do not validate file paths in tests
- linters:
- gosec
path: ^test\/e2e\/.*\.go$
text: 'G304: Potential file inclusion via variable'
# Ignore the elevated access that "others" have for dirs/files created in tests with 0755 permissions
- linters:
- gosec
path: ^test\/e2e\/.*\.go$
text: 'G301: Expect directory permissions to be 0750 or less'
# Ignore the elevated access that "group" and "others" have for dirs/files opened in tests with 0644 permissions
- linters:
- gosec
path: ^test\/e2e\/.*\.go$
text: 'G302: Expect file permissions to be 0600 or less'
# # Ignore unhandled errors in test files when using os.Setenv
# - linters:
# - gosec
# path: ^test\/e2e\/.*\.go$
# text: 'G104: Errors unhandled.'
# # Ignore the unhandled errors on using os.Setenv in test files
# - linters:
# - gosec
# path: .*_test\.go$
# text: 'G104: Errors unhandled.'
# Ignore unused parameters in test files
- linters:
- revive
path: .*(_test|test)\.go$
text: '^unused-parameter: parameter ''.*'' seems to be unused, consider removing or renaming it as _$'
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- revive
path: .*\.go$
text: '^package-comments: package comment should be of the form ".*"$'
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- revive
path: .*\.go$
text: 'package-comments: should have a package comment'
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- staticcheck
path: .*\.go$
text: 'ST1000: at least one file in a package should have a package comment'
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- staticcheck
path: .*\.go$
text: 'ST1000: package comment should be of the form ".*"$'
- linters:
- goconst
path: (.+)_test\.go
# Ignore Cluster API v1beta1 deprecations.
- linters:
- staticcheck
path: .*\.go$
text: 'SA1019: "sigs.k8s.io\/cluster-api/api/core/v1beta1" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
- linters:
- staticcheck
path: .*\.go$
text: 'SA1019: "sigs.k8s.io/cluster-api/util/deprecated/.*" is deprecated: This package is deprecated and is going to be removed when support for v1beta1 will be dropped.'
# Ignore GetEventRecorderFor deprecation (CAPI itself still uses it).
- linters:
- staticcheck
text: 'SA1019: (env|mgr|testEnv).GetEventRecorderFor is deprecated'
# Ignore remote.NewClusterClient deprecation pending migration to ClusterCache.
- linters:
- staticcheck
text: 'SA1019: remote.NewClusterClient is deprecated'
# Ignore CAPZ v1beta1 deprecations (SharedGallery, VMState) still used for backward compatibility.
- linters:
- staticcheck
text: 'SA1019: .*SharedGallery is deprecated'
- linters:
- staticcheck
text: 'SA1019: .*VMState is deprecated'
paths:
- zz_generated\.(\w*)\.go$
- third_party$
- builtin$
- examples$
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
# changes in PRs and avoid nitpicking.
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-provider-azure) # Custom section: groups all imports with the specified Prefix.
custom-order: true
exclusions:
generated: lax
paths:
- zz_generated\.(\w*)\.go$
- third_party$
- builtin$
- examples$