-
Notifications
You must be signed in to change notification settings - Fork 13
/
.golangci.yml
426 lines (382 loc) · 18.4 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
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
# Documentation:
# https://golangci-lint.run/usage/configuration/#run-configuration
# Run:
# go run github.com/golangci/golangci-lint/cmd/golangci-lint run --fix
# List linters by category in a YAML-compatible format:
# go run github.com/golangci/golangci-lint/cmd/golangci-lint help --color always linters | sed -n '/Linters presets:/,$p' | sed 's/^/# /;s/[:,]/\n-/g'
---
linters:
enable:
# bugs
- asciicheck # check code does not contain non-ASCII identifiers
- bidichk # check for dangerous unicode character sequences
- contextcheck # check the function whether use a non-inherited context
- durationcheck # check for two durations multiplied together
- errchkjson # check types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted.
- exhaustive # check exhaustiveness of enum switch statements
- exportloopref # check for pointers to enclosing loop variables
- gosec # inspect source code for security problems
- makezero # find slice declarations with non-zero initial length
- nilerr # find the code that returns nil even if it checks that the error is not nil
- typecheck # check types
# comment
- godot # check if comments end in a period
- misspell # find commonly misspelled English words in comments
# complexity
- cyclop # check function and package cyclomatic complexity
- funlen # detect long functions
- gocognit # compute the cognitive complexity of functions
- gocyclo # check the cyclomatic complexity of functions
- maintidx # measure the maintainability index of each function.
- nestif # report deeply nested if statements
# error
- errcheck # ANNOYING
- errorlint # find code that will cause problems with the error wrapping scheme introduced in Go 1.13
# format
- decorder # check declaration order and count of types, constants, variables and functions
- gofmt # check if code was gofmt-ed and check for code simplification
- gofumpt # check if code was gofumpt-ed.
# import
- goimports # fix imports and format code in the same style as gofmt.
- gomodguard # allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
# metalinter
- gocritic # check bugs, performance and style issues
- govet # report suspicious constructs, such as Printf calls whose arguments do not align with the format string
- revive # drop-in replacement of golint
- staticcheck # apply a ton of static analysis checks
# module
- depguard # check if package imports are in a list of acceptable packages
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
# performance
- bodyclose # check if HTTP response body is closed successfully
- noctx # noctx finds sending http request without context.Context
- prealloc # find slice declarations that could potentially be preallocated
# sql
- execinquery # check query string in Query function which reads your Go src files
- rowserrcheck # check whether Err of rows is checked successfully
- sqlclosecheck # check that sql.Rows and sql.Stmt are closed.
# style
- containedctx # detect struct contained context.Context field
- dogsled # check assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- dupl # find duplicated code
- errname # check sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`
- forbidigo # forbids identifiers
- forcetypeassert # finds forced type assertions
- gochecknoinits # check that no init functions are present in Go code
- goconst # find repeated strings that could be replaced by a constant
- goheader # check if file header matches to pattern
- gomnd # ANNOYING
- goprintffuncname # check printf-like functions are named with `f` at the end
- gosimple # simplify code
- grouper # Aanalyze expression groups
- ifshort # check code uses short syntax for if-statements whenever possible
- importas # enforce consistent import aliases - ireturn # accept Interfaces, return Concrete Types
- nakedret # find naked returns in functions greater than a specified function length
- nilnil # chec there is no simultaneous return of `nil` error and an invalid value
- nolintlint # reports ill-formed or insufficient nolint directives
- predeclared # find code that shadows one of Go's predeclared identifiers
- promlinter # check Prometheus metrics naming via promlint
- tenv # detect using os.Setenv instead of t.Setenv since Go1.17
- unconvert # remove unnecessary type conversions
- wastedassign # find wasted assignment statements
- whitespace # detect leading and trailing whitespace
- nosprintfhostport # check for misuse of Sprintf to construct a host with port in a URL
# test
- tparallel # detect inappropriate usage of t.Parallel() method in your Go test codes
- thelper # detect golang test helpers without t.Helper() call and checks the consistency of test helpers
# unused
- deadcode # find unused code
- ineffassign # detect when assignments to existing variables are not used
- structcheck # find unused struct fields
- unparam # report unused function parameters
- unused # check for unused constants, variables, functions and types
- varcheck # find unused global variables and constants
disable:
# bugs
- scopelint # DEPRECATED
# comment
- godox # ANNOYING
# error
- goerr113 # ANNOYING
- wrapcheck # ANNOYING
# import
- gci # ANNOYING
# performance
- maligned # DEPRECATED
# style
- gochecknoglobals # ANNOYING
- golint # DEPRECATED (alternatives: revive and stylecheck)
- interfacer # DEPRECATED
- lll # ANNOYING
- nlreturn # ANNOYING
- tagliatelle # ANNOYING
- varnamelen # ANNOYING
- wsl # ANNOYING
- nonamedreturns # ANNOYING
# test
- paralleltest # ANNOYING
- testpackage # ANNOYING
- exhaustivestruct # DEPRECATED
- exhaustruct # ANNOYING
linters-settings:
dupl:
threshold: 150
funlen:
lines: 100
statements: 50
gocyclo:
min-complexity: 15
cyclop:
max-complexity: 15
gci:
sections: [prefix(github.com/teal-finance/)]
goconst:
min-len: 2
min-occurrences: 5
gocritic:
enabled-checks:
- appendAssign # Detects suspicious append result assignments
- argOrder # Detects suspicious arguments order
- badCall # Detects suspicious function calls
- badCond # Detects suspicious condition expressions
- badLock # Detects suspicious mutex lock/unlock operations
- badRegexp # Detects suspicious regexp patterns
- builtinShadowDecl # Detects top-level declarations that shadow the predeclared identifiers
- caseOrder # Detects erroneous case order inside switch statements
- codegenComment # Detects malformed 'code generated' file comments
- commentedOutCode # Detects commented-out code inside function bodies
- deprecatedComment # Detects malformed 'deprecated' doc-comments
- dupArg # Detects suspicious duplicated arguments
- dupBranchBody # Detects duplicated branch bodies inside conditional statements
- dupCase # Detects duplicated case clauses inside switch or select statements
- dupSubExpr # Detects suspicious duplicated sub-expressions
- emptyDecl # Detects suspicious empty declarations blocks
- evalOrder # Detects unwanted dependencies on the evaluation order
- exitAfterDefer # Detects calls to exit/fatal inside functions that use defer
- externalErrorReassign # Detects suspicious reassigment of error from another package
- filepathJoin # Detects problems in filepath.Join() function calls
- flagDeref # Detects immediate dereferencing of `flag` package pointers
- flagName # Detects suspicious flag names
- mapKey # Detects suspicious map literal keys
- nilValReturn # Detects return statements those results evaluate to nil
- offBy1 # Detects various off-by-one kind of errors
- regexpPattern # Detects suspicious regexp patterns
- returnAfterHttpError # Detects suspicious http.Error call without following return
- sloppyReassign # Detects suspicious/confusing re-assignments
- sloppyTypeAssert # Detects redundant type assertions
- sortSlice # Detects suspicious sort.Slice calls
- sprintfQuotedString # Detects "%s" formatting directives that can be replaced with %q
- sqlQuery # Detects issue in Query() and Exec() calls
- syncMapLoadAndDelete # Detects sync.Map load+delete operations that can be replaced with LoadAndDelete
- truncateCmp # Detects potential truncation issues when comparing ints of different sizes
- unnecessaryDefer # Detects redundantly deferred calls
- weakCond # Detects conditions that are unsafe due to not being exhaustive
- assignOp # Detects assignments that can be simplified by using assignment operators
- boolExprSimplify # Detects bool expressions that can be simplified
- builtinShadow # Detects when predeclared identifiers are shadowed in assignments
- captLocal # Detects capitalized names for local variables
- commentFormatting # Detects comments with non-idiomatic formatting
- commentedOutImport # Detects commented-out imports
- defaultCaseOrder # Detects when default case in switch isn't on 1st or last position
- deferUnlambda # Detects deferred function literals that can be simplified
- docStub # Detects comments that silence go lint complaints about doc-comment
- dupImport # Detects multiple imports of the same package under different aliases
- elseif # Detects else with nested if statement that can be replaced with else-if
- emptyFallthrough # Detects fallthrough that can be avoided by using multi case values
- emptyStringTest # Detects empty string checks that can be written more idiomatically
- exposedSyncMutex # Detects exposed methods from sync.Mutex and sync.RWMutex
- hexLiteral # Detects hex literals that have mixed case letter digits
- httpNoBody # Detects nil usages in http.NewRequest calls, suggesting http.NoBody as an alternative
- ifElseChain # Detects repeated if-else statements and suggests to replace them with switch statement
- importShadow # Detects when imported package names shadowed in the assignments
- initClause # Detects non-assignment statements inside if/switch init clause
- ioutilDeprecated # Detects deprecated io/ioutil package usages
- methodExprCall # Detects method expression call that can be replaced with a method call
- nestingReduce # Finds where nesting level could be reduced
- newDeref # Detects immediate dereferencing of `new` expressions
- octalLiteral # Detects old-style octal literals
- paramTypeCombine # Detects if function parameters could be combined by type and suggest the way to do it
- preferFilepathJoin # Detects concatenation with os.PathSeparator which can be replaced with filepath.Join
- ptrToRefParam # Detects input and output parameters that have a type of pointer to referential type
- redundantSprint # Detects redundant fmt.Sprint calls
- regexpMust # Detects `regexp.Compile*` that can be replaced with `regexp.MustCompile*`
- regexpSimplify # Detects regexp patterns that can be simplified
- ruleguard # Runs user-defined rules using ruleguard linter
- singleCaseSwitch # Detects switch statements that could be better written as if statement
- sloppyLen # Detects usage of `len` when result is obvious or doesn't make sense
- stringConcatSimplify # Detects string concat operations that can be simplified
- switchTrue # Detects switch-over-bool statements that use explicit `true` tag value
- timeExprSimplify # Detects manual conversion to milli- or microseconds
- tooManyResultsChecker # Detects function with too many results
- typeAssertChain # Detects repeated type assertions and suggests to replace them with type switch statement
- typeDefFirst # Detects method declarations preceding the type definition itself
- typeSwitchVar # Detects type switches that can benefit from type guard clause with variable
- typeUnparen # Detects unneded parenthesis inside type expressions and suggests to remove them
- underef # Detects dereference expressions that can be omitted
- unlabelStmt # Detects redundant statement labels
- unlambda # Detects function literals that can be simplified
- unnamedResult # Detects unnamed results that may benefit from names
- unnecessaryBlock # Detects unnecessary braced statement blocks
- unslice # Detects slice expressions that can be simplified to sliced expression itself
- valSwap # Detects value swapping code that are not using parallel assignment
- whyNoLint # Ensures that `//nolint` comments include an explanation
- wrapperFunc # Detects function calls that can be replaced with convenience wrappers
- yodaStyleExpr # Detects Yoda style expressions and suggests to replace them
- appendCombine # Detects `append` chains to the same slice that can be done in a single `append` call
- equalFold # Detects unoptimal strings/bytes case-insensitive comparison
- hugeParam # Detects params that incur excessive amount of copying
- indexAlloc # Detects strings.Index calls that may cause unwanted allocs
- preferDecodeRune # Detects expressions like []rune(s)[0] that may cause unwanted rune slice allocation
- preferFprint # Detects fmt.Sprint(f|ln) calls which can be replaced with fmt.Fprint(f|ln)
- preferStringWriter # Detects w.Write or io.WriteString calls which can be replaced with w.WriteString
- preferWriteByte # Detects WriteRune calls with byte literal argument and reports to use WriteByte instead
- rangeExprCopy # Detects expensive copies of `for` loop range expressions
- rangeValCopy # Detects loops that copy big objects during each iteration
- sliceClear # Detects slice clear loops, suggests an idiom that is recognized by the Go compiler
- stringXbytes # Detects redundant conversions between string and []byte
# next release:
# suspiciousSorting # Detects bad usage of sort package
# https://github.com/mvdan/gofumpt
gofumpt:
lang-version: "1.19"
extra-rules: true
goimports:
local-prefixes: github.com/teal-finance/
gomnd:
settings:
mnd:
# don't include the "operation" and "assign,argument,case,condition"
checks: [return]
govet:
check-shadowing: true
settings:
printf:
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
lll:
line-length: 160
maligned:
suggest-new: true
misspell:
locale: US
nolintlint:
allow-leading-space: false # must bein format "//nolint"
require-specific: true # must be in format "//nolint:xxxx"
require-explanation: true # must be in format "//nolint:xxxx // explanation"
allow-unused: false # report any unused nolint directives
gosimple:
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
staticcheck:
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
stylecheck:
go: "1.19"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
# https://staticcheck.io/docs/options#dot_import_whitelist
dot-import-whitelist: []
# https://staticcheck.io/docs/options#http_status_code_whitelist
http-status-code-whitelist: []
# https://staticcheck.io/docs/options#initialisms
initialisms:
[
"ACL",
"API",
"ASCII",
"CPU",
"CSS",
"DNS",
"EOF",
"GUID",
"HTML",
"HTTP",
"HTTPS",
"ID",
"IP",
"JSON",
"QPS",
"RAM",
"RPC",
"SLA",
"SMTP",
"SQL",
"SSH",
"TCP",
"TLS",
"TTL",
"UDP",
"UI",
"GID",
"UID",
"UUID",
"URI",
"URL",
"UTF8",
"VM",
"XML",
"XMPP",
"XSRF",
"XSS",
"SIP",
"RTP",
"AMQP",
"DB",
"TS",
]
tagliatelle:
case:
rules:
json: snake # could be "goCamel"
# https://github.com/butuzov/ireturn
# https://golangci-lint.run/usage/linters/#ireturn
ireturn:
allow:
- anon # anonymous interfaces such as: interface{Stop()}
- error # error interface
- stdlib # standard library interfaces
- github.com/prometheus\/client_golang\/prometheus.Gauge
- github.com/prometheus\/client_golang\/prometheus.Counter
issues:
exclude-rules:
# More flexible with test source code
- path: _test\.go
linters:
- gomnd
- gosec # weak random number generator (math/rand instead of crypto/rand)
- gocyclo
- errcheck
## Example commented
#- text: "unnecessaryDefer:"
# linters: [gocritic]
## Example commented
#- text: "exitAfterDefer:"
# linters: [gocritic]
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 9m
# exit code when at least one issue was found, default is 1
issues-exit-code: 1
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs: [poc]
go: "1.17"
output:
# colored-line-number|line-number|json|tab|checkstyle, default is "colored-line-number"
format: colored-line-number
# print lines of code with issue, default is true
print-issued-lines: true
# print linter name in the end of issue text, default is true
print-linter-name: true
# make issues output unique by line, default is true
uniq-by-line: true
# sorts results by: filepath, line and column
sort-results: true