-
Notifications
You must be signed in to change notification settings - Fork 3
/
.golangci.yml
391 lines (309 loc) · 9.22 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
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
run:
timeout: 2m
issues-exit-code: 1
tests: true
skip-dirs-use-default: true
modules-download-mode: readonly
allow-parallel-runners: true
build-tags:
- generator
output:
format: tab
print-issued-lines: true
print-linter-name: true
# Print all issue on single line.
# We should set to true 'cause if one single line has issues from different linters
# we will only one of them.
uniq-by-line: false
sort-results: true
linters-settings:
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
check-type-assertions: true
# Report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
check-blank: true
errorlint:
# Report non-wrapping error creation using fmt.Errorf, for instance:
#
# ```
# if _, err := := strconv.Atoi(numStr); err != nil {
# return fmt.Errorf("failed to convert: %s", err) <-- Will trigger an error at this line.
# }
# ```
errorf: true
exhaustive:
check-generated: true
default-signifies-exhaustive: true
goconst:
# Minimal length of string constant.
min-len: 3
# Minimal occurrences count to trigger.
min-occurrences: 3
gocyclo:
min-complexity: 10
godot:
check-all: true
gofmt:
simplify: false
goimports:
# Put imports beginning with prefix after 3rd-party packages.
# It's a comma-separated list of prefixes.
local-prefixes: github.com/solusio/solus-go-sdk
govet:
# We have many false-positive match for `err`.
check-shadowing: false
settings:
printf:
funcs:
- github.com/hashicorp/terraform-plugin-sdk/v2/diag.Errorf
enable:
- assign
- atomic
- bools
- buildtag
- cgocall
- copylocks
- errorsas
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
- printf
- shift
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
enable-all: false
disable-all: false
lll:
# Max line length, lines longer will be reported.
# '\t' is counted as 1 character by default, and can be changed with the `tab-width` option.
line-length: 120
# In our code, tab is 4 space long.
tab-width: 4
misspell:
locale: US
nakedret:
max-func-lines: 5
nestif:
min-complexity: 5
revive:
# https://github.com/mgechev/revive#available-rules
rules:
# Make sure `context.Context` is the first argument of a function.
- name: context-as-argument
# Warns on some defer gotchas.
# https://blog.learngoprogramming.com/5-gotchas-of-defer-in-go-golang-part-iii-36a1ab3d6ef1
- name: defer
# Forbids . imports.
- name: dot-imports
# Looks for packages that are imported two or more times.
- name: duplicated-imports
# Spots if-then-else statements that can be refactored to simplify code reading.
- name: early-return
# Make sure error return parameter is the last.
- name: error-return
# Warns on getters that do not yield any result.
- name: get-return
# Warns on if-then-else statements with identical then and else branches.
- name: identical-branches
# Warns on redundant `if` when returning an error.
- name: if-return
# Warns on `i += 1` and `i -= 1`.
- name: increment-decrement
# Warns on assignments to value-passed method receivers.
- name: modifies-value-receiver
# Warns on redundant variables when iterating over a collection.
- name: range
# Warns on function calls that will lead to (direct) infinite recursion.
- name: unconditional-recursion
# Warns when a public return is from unexported type.
- name: unexported-return
# Warns on unnecessary statements.
- name: unnecessary-stmt
# Warns on unused method receivers.
- name: unused-receiver
staticcheck:
enable: true
stylecheck:
go: "1.17"
checks:
- "all"
nolintlint:
# Require machine-readable nolint directives (i.e. with no leading space)
allow-leading-space: false
# Report any unused nolint directives.
allow-unused: false
# Require an explanation for nolint directives.
require-explanation: true
# Exclude following linters from requiring an explanation.
allow-no-explanation:
- lll
# Require nolint directives to be specific about which linter is being skipped.
require-specific: true
unused:
check-exported: true
linters:
# https://golangci-lint.run/usage/linters/
enable:
# Finds unused code.
- deadcode
# Checks if package imports are in a list of acceptable packages.
- depguard
# Checks assignments with too many blank identifiers (e.g. `x, , , _, := f()`).
- dogsled
# Code clone detection.
- dupl
# Check for two durations multiplied together.
#
# ```
# func do(d time.Duration) {
# ...
# time.Sleep(d * time.Second) <-- will trigger an error at this line.
# ...
# }
# ```
- durationcheck
# Searches for unchecked errors.
- errcheck
# Find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- errorlint
# Checks exhaustiveness of enum switch statements.
- exhaustive
# Checks for pointers to enclosing loop variables
- exportloopref
# Forbids identifiers.
- forbidigo
# Checks that no init functions are present in Go code.
- gochecknoinits
# Finds repeated strings that could be replaced by a constant.
- goconst
# Provides many diagnostics that check for bugs, performance and style issues.
# https://go-critic.github.io/overview
- gocritic
# Computes and checks the cyclomatic complexity of functions.
- gocyclo
# Check if comments end in a period.
- godot
# Checks whether code was gofmt-ed.
- gofmt
# Checks is file header matches to pattern.
- goheader
# Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
- gomoddirectives
# Inspects source code for security problems.
- gosec
# Linter that specializes in simplifying a code.
- gosimple
- govet
# Checks that your code uses short syntax for if-statements whenever possible.
#
# Bad:
# ```
# _, err := := strconv.Atoi(numStr) <-- Will trigger an error at this line.
# if err != nil {
# return fmt.Errorf("failed to convert: %w", err)
# }
# ```
#
# Good:
# ```
# if _, err := := strconv.Atoi(numStr); err != nil {
# return fmt.Errorf("failed to convert: %w", err)
# }
# ```
- ifshort
# Detects when assignments to existing variables are not used.
- ineffassign
# Reports long lines.
- lll
# Finds commonly misspelled words in comments.
- misspell
# Finds naked returns in functions greater than a specified function length.
- nakedret
# Reports deeply nested if statements.
- nestif
# Finds the code that returns nil even if it checks that the error is not nil.
- nilerr
# Reports ill-formed or insufficient nolint directives.
- nolintlint
# Find code that shadows one of Go's predeclared identifiers.
- predeclared
- revive
# Applying a ton of static analysis checks.
- staticcheck
# Finds unused struct fields.
- structcheck
# Is a replacement for golint.
- stylecheck
# Like the front-end of a Go compiler, parses and type-checks Go code.
- typecheck
# Finds unnecessary type conversions.
- unconvert
# Reports unused function parameters.
- unparam
# Checks Go code for unused constants, variables, functions and types.
- unused
# Finds unused global variables and constants.
- varcheck
# Finds wasted assignment statements.
#
# ```
# func f() int {
# a := 0
# b := 0
# fmt.Print(a)
# fmt.Print(b)
# a = 1 // This reassignment is wasted, because never used afterwards. Wastedassign find this.
#
# b = 1 // This reassignment is wasted, because reassigned without use this value. Wastedassign find this.
# b = 2
# fmt.Print(b)
#
# return 1 + 2
# }
# ```
- wastedassign
# Finds leading and trailing whitespace.
- whitespace
disbale:
- megacheck
issues:
# Maximum count of issues with the same text. Set to 0 to disable.
max-same-issues: 0
include:
# ```
# switch ... {
# case ...:
# break <-- Will trigger an error at this line.
# }
# ```
- "ineffective break statement. Did you mean to break out of the outer loop"
exclude-rules:
- path: _test\.go
linters:
- dupl
- errcheck
- goconst
- gocyclo
- gosec
# Ignore long lines in comments.
- source: "^[ \t]*// "
linters:
- lll
# Ignore lll in lines with `nolint` (but without `lll` in ignored)
- source: "//nolint:[[:graph:]]*[^l]{3}[[:graph:]]*"
linters:
- lll
- path: generators/
text: "use of `fmt.Printf`"
severity:
default-severity: error
case-sensitive: false