-
Notifications
You must be signed in to change notification settings - Fork 1
/
.golangci.yml
487 lines (446 loc) · 20.5 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
# Documentation:
# https://golangci-lint.run/usage/configuration/#run-configuration
# Run the last version:
# go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest run --fix
# List linters by category in a YAML-compatible format:
# go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest --color always help linters | sed -n '/Linters presets:/,$p' | sed 's/^/# /;s/[:,]/\n-/g'
# List non-deprecated linters that may be enabled:
# go run github.com/golangci/golangci-lint/cmd/golangci-lint@latest --color always linters | sed -n '/Disabled.*:/,$p' | grep -v deprecated
---
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
- 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
- gci
- 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
- gochecknoglobals
- 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
- goprintffuncname # check printf-like functions are named with `f` at the end
- gosimple # simplify code
- grouper # Aanalyze expression groups
- importas # enforce consistent import aliases - ireturn # accept Interfaces, return Concrete Types
- lll
- 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
- nosprintfhostport # check for misuse of Sprintf to construct a host with port in a URL
- predeclared # find code that shadows one of Go's predeclared identifiers
- promlinter # check Prometheus metrics naming via promlint
- tagliatelle
- tenv # detect using os.Setenv instead of t.Setenv since Go1.17
- unconvert # remove unnecessary type conversions
- varnamelen
- wastedassign # find wasted assignment statements
- whitespace # detect leading and trailing whitespace
# test
- exhaustruct
- paralleltest
- testpackage
- thelper # detect golang test helpers without t.Helper() call and checks the consistency of test helpers
- tparallel # detect inappropriate usage of t.Parallel() method in your Go test codes
# unused
- deadcode # find unused code
- ineffassign # detect when assignments to existing variables are not used
- unparam # report unused function parameters
- unused # check for unused constants, variables, functions and types
- varcheck # find unused global variables and constants
# new
- asasalint # []any as any in variadic func(...any)
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library
disable:
# ANNOYING
- godox # no TODO/BUG/FIXME
- goerr113 # error
- ireturn # Accept Interfaces, Return Concrete Types
- nlreturn # style - new line before return and branch statements
- nonamedreturns # style
- stylecheck # replacement for golint
- wrapcheck # error
- wsl # style
# DEPRECATED
- exhaustivestruct
- golint # alternatives: revive and stylecheck
- interfacer
- maligned
- scopelint
- ifshort # check code uses short syntax for if-statements whenever possible
- structcheck # find unused struct fields
- nosnakecase # detects snake case of variable naming and function name
linters-settings:
dupl:
threshold: 94
exhaustruct:
include: []
exclude:
- "Perm$"
funlen:
lines: 100
statements: 50
gocyclo:
min-complexity: 10
cyclop:
max-complexity: 10
gci:
sections:
- standard
- default
- 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
# ANNOYING 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
# CRASH 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.22"
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
misspell:
locale: US
nolintlint:
allow-leading-space: false # must be in 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.22"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
staticcheck:
go: "1.22"
# https://staticcheck.io/docs/options#checks
checks: ["all"]
stylecheck:
go: "1.22"
# 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
-
varnamelen:
# The longest distance, in source lines, that is being considered a "small scope".
# Variables used in at most this many lines will be ignored.
# Default: 5
max-distance: 14
# The minimum length of a variable's name that is considered "long".
# Variable names that are at least this long will be ignored.
# Default: 3
min-name-length: 2
# Check method receivers.
# Default: false
check-receiver: false
# Check named return values.
# Default: false
check-return: true
# Check type parameters.
# Default: false
check-type-param: true
# Ignore "ok" variables that hold the bool return value of a type assertion.
# Default: false
ignore-type-assert-ok: false
# Ignore "ok" variables that hold the bool return value of a map index.
# Default: false
ignore-map-index-ok: false
# Ignore "ok" variables that hold the bool return value of a channel receive.
# Default: false
ignore-chan-recv-ok: false
# Optional list of variable names that should be ignored completely.
# Default: []
ignore-names:
- err
- r # request
- w # writer
- g # garcon
- u # url
- d # duration
# Optional list of variable declarations that should be ignored completely.
# Entries must be in one of the following forms (see below for examples):
# - for variables, parameters, named return values, method receivers, or type parameters:
# <name> <type> (<type> can also be a pointer/slice/map/chan/...)
# - for constants: const <name>
#
# Default: []
ignore-decls:
- t testing.T
- f *foo.Bar
- e error
- i int
- const C
- T any
- m map[string]int
issues:
exclude-rules:
# More flexible with test source code
- path: _test\.go
linters:
- cyclop
- dupl
- errcheck
- forcetypeassert
- funlen
- gochecknoglobals
- gocognit
- gocyclo
- varnamelen
## Examples
#- text: "unnecessaryDefer:"
# linters: [gocritic]
#- 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.22"
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