-
Notifications
You must be signed in to change notification settings - Fork 428
/
.golangci.yml
308 lines (305 loc) · 11.8 KB
/
.golangci.yml
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
run:
timeout: 10m
build-tags:
- e2e
allow-parallel-runners: true
linters:
disable-all: true
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
- gci # ensures imports are organized
- 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
- gofmt # warns about incorrect use of fmt functions
- goimports # import formatting
- goprintffuncname # printft-like functions should be named with f at the end
- gosec # potential security problems
- gosimple # simplify code
- 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
- stylecheck # another replacement for golint
- tenv # using os.Setenv instead of t.Setenv in tests
- 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
- whitespace # unnecessary newlines
linters-settings:
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
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
ginkgolinter:
forbid-focus-container: true
goconst:
ignore-tests: true
godot:
# declarations - for top level declaration comments (default);
# toplevel - for top level comments;
# all - for all comments.
scope: toplevel
exclude:
- '^ \+.*'
- '^ ANCHOR.*'
gocritic:
enabled-tags:
- "experimental"
disabled-checks:
- appendAssign
- dupImport # https://github.com/go-critic/go-critic/issues/845
- evalOrder
- ifElseChain
- octalLiteral
- regexpSimplify
- sloppyReassign
- truncateCmp
- typeDefFirst
- unnamedResult
- unnecessaryDefer
- whyNoLint
- wrapperFunc
importas:
no-unaliased: true
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/v1beta1
alias: clusterv1
# CAPI exp
- pkg: sigs.k8s.io/cluster-api/exp/api/v1beta1
alias: expv1
# 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
nolintlint:
allow-unused: false
require-specific: true
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
unused:
go: "1.22"
issues:
exclude-files:
- 'zz_generated\.(\w*)\.go$'
exclude-rules:
- 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"
- path: (^test/|_test.go$)
linters:
- dogsled
- goconst
- godot
- prealloc
- path: (^test/|_test.go$)
text: exported (.+) should have comment( \(or a comment on this block\))? or be unexported
- source: \"github.com/onsi/(ginkgo/v2|gomega)\"
text: "should not use dot imports"
# 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
text: exported (method|function|type|const) (.+) should have comment or be unexported
path: fake_\.go
# Dot imports for gomega and ginkgo are allowed
# within test files and test utils.
- linters:
- revive
- stylecheck
path: _test\.go
text: should not use dot imports
- linters:
- revive
# 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"
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
# 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
# Ignoring stylistic checks for generated code
path: .*(api|types|test)\/.*\/conversion.*\.go$
- linters:
- revive
# By convention, receiver names in a method should reflect their identity.
text: "receiver-naming: receiver name"
# Ignoring stylistic checks for generated code
path: .*(api|types)\/.*\/conversion.*\.go$
- linters:
- stylecheck
text: "ST1016: methods on the same type should have the same receiver name"
path: .*(api|types)\/.*\/conversion.*\.go$
# We don't care about defer in for loops in test files.
- linters:
- gocritic
text: "deferInLoop: Possible resource leak, 'defer' is called in the 'for' loop"
path: _test\.go
# 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
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
path: (^test\/e2e\/.*\.go$|.*_test\.go$)
# Do not validate file paths in tests
- linters:
- gosec
text: "G304: Potential file inclusion via variable"
path: ^test\/e2e\/.*\.go$
# Ignore the elevated access that "others" have for dirs/files created in tests with 0755 permissions
- linters:
- gosec
text: "G301: Expect directory permissions to be 0750 or less"
path: ^test\/e2e\/.*\.go$
# Ignore the elevated access that "group" and "others" have for dirs/files opened in tests with 0644 permissions
- linters:
- gosec
text: "G302: Expect file permissions to be 0600 or less"
path: ^test\/e2e\/.*\.go$
# Ignore unhandled errors in test files when using os.Setenv
- linters:
- gosec
text: "G104: Errors unhandled."
path: ^test\/e2e\/.*\.go$
# Ignore the unhandled errors on using os.Setenv in test files
- linters:
- gosec
text: "G104: Errors unhandled."
path: .*_test\.go$
# Ignore unused parameters in test files
- linters:
- revive
text: "^unused-parameter: parameter '.*' seems to be unused, consider removing or renaming it as _$"
path: .*(_test|test)\.go$
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- revive
text: "^package-comments: package comment should be of the form \".*\"$"
path: .*\.go$
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- revive
text: "package-comments: should have a package comment"
path: .*\.go$
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- stylecheck
text: "ST1000: at least one file in a package should have a package comment"
path: .*\.go$
# Ignore adding package comments for all files. TODO: Ideally, we should add package comments to all the packages files.
- linters:
- stylecheck
text: "ST1000: package comment should be of the form \".*\"$"
path: .*\.go$
# 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.
exclude-use-default: false
max-issues-per-linter: 0
max-same-issues: 0