-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.golangci.yml
More file actions
443 lines (322 loc) · 12.2 KB
/
.golangci.yml
File metadata and controls
443 lines (322 loc) · 12.2 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
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
# All linters are checked and included either in enable or disable as of v2.6.0 of golangci-lint.
# gofumpt and golines are used as formatters.
# This is the config file for lint task of this library.
version: "2"
run:
modules-download-mode: readonly
linters:
default: none
enable:
# Check for pass []any as any in variadic func(...any). Rare case but good to have.
- asasalint
# Use plain ASCII identifiers.
- asciicheck
# Checks for dangerous unicode character sequences. Rare case but good to have.
- bidichk
# Checks whether HTTP response body is closed successfully.
- bodyclose
# Check whether the function uses a non-inherited context.
- contextcheck
# Find duplicate words. Rare case but good to have.
- dupword
# Check for two durations multiplied together.
- durationcheck
# Check if embedded fields are at top of the struct. Mutex should not be embedded.
- embeddedstructfieldcheck
# Forces to not skip error check.
- errcheck
# Checks `Err-` prefix for var and `-Error` suffix for error type.
- errname
# Suggests to use `%w` for error-wrapping and other post 1.13 directives of Is, As etc.
- errorlint
# Forces to handle more cases in enums.
- exhaustive
# Detects functions from golang.org/x/exp/ that can be replaced by standard functions.
# I don't prefer using exp at all, but good to keep it for preventing any accidents.
- exptostd
# Detects nested contexts in loops and function literals.
- fatcontext
# Finds forced type assertions.
- forcetypeassert
# Check order of functions and constructors.
- funcorder
# Checks that compiler directive comments (//go:) are valid.
- gocheckcompilerdirectives
# Run exhaustiveness checks on Go "sum types".
- gochecksumtype
# Finds repeated strings that could be replaced by a constant.
- goconst
# Meta linter with lots of great checks
- gocritic
# Forces to put `.` at the end of the comment. Code is poetry.
- godot
# Documentation sanity.
- godoclint
# Powerful security-oriented linter. But requires some time to
# configure it properly, see https://github.com/securego/gosec#available-rules
- gosec
# Official Go tool. Must have.
- govet
# Checks import alias consistency.
- importas
# Reports interfaces with unnamed method parameters.
- inamedparam
# Detects when assignments to existing variables are not used.
- ineffassign
# Dont allow non iota constants mixed with iota.
- iotamixing
# Reports wrong mirror patterns of bytes/strings usage.
- mirror
# Fix all the misspells, amazing thing.
- misspell
# gopls modernize analyzers
- modernize
# Enforce tags in un/marshaled structs.
- musttag
# Finds naked/bare returns and requires change them.
- nakedret
# Require a bit more explicit returns. Finds the code that returns nil even if it checks that the error is not nil.
- nilerr
# Require a bit more explicit returns. Checks that there is no simultaneous return of nil error and an invalid value.
- nilnil
# Finds sending HTTP request without context.Context.
- noctx
# Forces comment why another check is disabled.
# Better not to have //nolint: at all ;)
- nolintlint
# Checks that fmt.Sprintf can be replaced with a faster alternative.
- perfsprint
# Finds slices that could potentially be pre-allocated.
# Small performance win + cleaner code.
- prealloc
# Finds shadowing of Go's predeclared identifiers.
# I hear a lot of complaints from junior developers.
# But after some time they find it very useful.
- predeclared
# Checks that package variables are not reassigned.
# Super rare case but can catch bad things (like `io.EOF = nil`)
- reassign
# Checks for receiver type consistency. Dont mix and match value and pointer receivers.
- recvcheck
# Drop-in replacement of `golint`.
- revive
# Somewhat similar to `bodyclose` but for `database/sql` package.
- rowserrcheck
# Ensures consistent code style when using log/slog.
- sloglint
# Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed.
- sqlclosecheck
# Meta linter: golangci-lint runs all SA checks from staticcheck via this lint config
- staticcheck
# Makes you add t.Helper() as the first line in test helpers.
- thelper
# Reports uses of functions with replacements inside the testing package.
- tparallel
# Remove unnecessary type conversions, make code cleaner
- unconvert
# Checks Go code for unused constants, variables, functions and types.
- unused
# Detect the possibility to use variables/constants from stdlib.
- usestdlibvars
# Reports uses of functions with replacement inside the testing package.
- usetesting
# Finds wasted assignment statements.
- wastedassign
disable:
# Linter for ArangoDB go driver
- arangolint
# Checks whether net/http.Header uses canonical header. Most probably good to have but not my use case
- canonicalheader
# Detects struct containing context.Context field. Not a problem.
- containedctx
# Detect if loop vars are copied. checked by modernize too.
- copyloopvar
# Checks function and package cyclomatic complexity.
# I can have a long but trivial switch-case.
#
# Cyclomatic complexity is a measurement, not a goal.
# (c) Bryan C. Mills / https://github.com/bcmills
- cyclop
# Check declaration order of types, constants, variables, and functions.
# I can have mixed things, like interface type and then its funcs and then other interface with its funcs etc.
- decorder
# Checks if package imports are in a list of acceptable packages.
# I'm very picky about what I import, so no automation.
- depguard
# Checks assignments with too many blank identifiers. I amy have this as a conscious choice, in tests etc.
- dogsled
# Tool for code clone detection.
- dupl
# Error lint covers all things from this and more.
- err113
# Checks if err from json functions can be ignored. I'm fine to check the error from json.Marshal.
- errchkjson
# Forces to initialize all fields of struct. Lots of issues in linter wrt empty struct, private fields etc.
- exhaustruct
# Forbids some identifiers. I don't have a case for it.
- forbidigo
# Function length checker. I might have long but a simple function.
- funlen
# only if ginkgo and gomega packages are used.
- ginkgolinter
# Check that no global variables exist. Globals are okay.
- gochecknoglobals
# Checks that no init functions are present in Go code. init() is okay.
- gochecknoinits
# Similar to cyclop linter (see above). Computes and checks the cognitive complexity of functions.
- gocognit
# Similar to cyclop linter (see above). Computes and checks the cognitive complexity of functions.
- gocyclo
# TODO and friends are okay.
- godox
# I don't use file headers.
- goheader
# Manages the use of replace, retract, and exclude directives in go.mod.
- gomoddirectives
# Allowed/blocked packages to import. I prefer to do it manually.
- gomodguard
# Printf-like functions must have 'f' at the end. Not useful to me.
- goprintffuncname
# Reports certain internationalization anti-patterns.
- gosmopolitan
# Group declarations, for import, const, var, etc. Dont have a need for it.
- grouper
# Detects the incorrect use of interfaces to avoid interface pollution. Very subjective.
- iface
# Forces tiny interfaces, very subjective.
- interfacebloat
# Finds places where for-loops could use an integer range. modernize also does it.
- intrange
# Accept interfaces, return concrete types. Not always.
- ireturn
# Reports long lines.
# Using golines with gofumpt as base formatter takes care of this.
# This is not really AST-based, so it has issues with long struct tags, etc.
- lll
# Some log checkers might be useful. I tend to use log/slog. govet checks the same thing for it post 1.21.
- loggercheck
# Maintainability index of each function, subjective.
- maintidx
# Slice declarations with non-zero initial length.
- makezero
# Detects magic numbers. I dont mind in some cases.
- mnd
# Deeply nested if statements, subjective.
- nestif
# Reports constructs that check 'err != nil' but return a different nil value error.
# nilerr covers the desired things.
- nilnesserr
# Checks for a new line before return and branch statements to increase code clarity. Subjective.
- nlreturn
# Detect inline err handling. I prefer inline err handling if possible.
- noinlineerr
# Reports all named returns. Direct conflict with: unnamedResult from go-critic.
- nonamedreturns
# Finds misuse of Sprintf with host:port in a URL. Cool but rare.
- nosprintfhostport
# I don't use t.Parallel() that much.
- paralleltest
# Lint your Prometheus metrics name.
- promlinter
# Reports direct reads from proto message fields when getters should be used.
- protogetter
# Checks for mistakes with OpenTelemetry/Census spans.
- spancheck
# Checks that struct tags are well aligned.
- tagalign
# Checks the struct tags.
- tagliatelle
# Expects testable examples.
- testableexamples
# Checks usage of github.com/stretchr/testify.
- testifylint
# Forces the use of a separate _test package. Often non-_test package is okay.
- testpackage
# Reports unused function parameters. Covered by revive.
- unparam
# Avoid select * in SQL query.
- unqueryvet
# I'm fine with long variable names with a small scope.
- varnamelen
# Checks for unnecessary newlines at the start and end of functions.
# gofumpt covers that.
- whitespace
# Wrap all errors from external packages.
- wrapcheck
# Forces you to use empty lines.
- wsl_v5
# Detects the wrong usage of zerolog where a user forgets to dispatch with Send or Msg.
- zerologlint
settings:
embeddedstructfieldcheck:
# Checks that sync.Mutex and sync.RWMutex are not used as embedded fields.
forbid-mutex: true
errcheck:
# Report `a := b.(MyStruct)` when `a, ok := ...` should be.
check-type-assertions: true # Default: false
gocritic:
# As of golangci-lint v2.0.2 this enabled 102 checks and disables below 4.
enable-all: true
disabled-checks:
# These will detect many cases, but they do make sense
# if it's performance oriented code
- hugeParam
- rangeExprCopy
- rangeValCopy
- commentedOutCode
godot:
# Comments to be checked: `declarations`, `toplevel`, `noinline` or `all`.
# Default: declarations
scope: noinline
capital: true
importas:
# Do not allow unaliased imports of aliased packages.
# https://github.com/julz/importas/issues/15
# no-unaliased: true
# Do not allow non-required aliases.
no-extra-aliases: true
nakedret:
# No naked returns, ever.
max-func-lines: 0 # Default: 30
revive:
rules:
- name: unused-parameter
# Too noisy
disabled: true
sloglint:
msg-style: "lowercased"
# Doesnt support things like bundleID, can enable and just check for discovery, once in a while.
# key-naming-case: "camel"
exclusions:
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
# "/" will be replaced by the current OS file path separator to properly work on Windows.
# Default: []
paths:
- third_party$
- builtin$
rules:
- text: '(slog|log)\.\w+'
linters:
- noctx
issues:
max-issues-per-linter: 0
max-same-issues: 0
formatters:
enable:
- gofumpt
- golines
exclusions:
paths:
- third_party$
- builtin$
settings:
gofumpt:
extra-rules: true
golines:
max-len: 120
shorten-comments: true