generated from ianlewis/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.golangci.yml
More file actions
552 lines (436 loc) · 15.1 KB
/
.golangci.yml
File metadata and controls
552 lines (436 loc) · 15.1 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
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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
# Copyright 2025 Ian Lewis
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
version: "2"
issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
new-from-rev: ""
linters:
default: none
enable:
# Enabled by default
- errcheck
- govet
- ineffassign
- staticcheck
- unused
# Disabled by default
# Check for pass []any as any in variadic func(...any).
- asasalint
# Checks that all code identifiers does not have non-ASCII symbols in the
# name.
- asciicheck
# Checks for dangerous unicode character sequences.
- bidichk
# Checks whether HTTP response body is closed successfully.
- bodyclose
# Canonicalheader checks whether net/http.Header uses canonical header.
- canonicalheader
# Containedctx is a linter that detects struct contained context.Context
# field.
- containedctx
# Check whether the function uses a non-inherited context.
- contextcheck
# A linter detects places where loop variables are copied.
- copyloopvar
# Checks function and package cyclomatic complexity.
- cyclop
# Check declaration order and count of types, constants, variables and
# functions.
- decorder
# Go linter that checks if package imports are in a list of acceptable
# packages.
- depguard
# Checks assignments with too many blank identifiers (e.g. x, , , _, :=
# f()).
- dogsled
# Detects duplicate fragments of code.
- dupl
# Checks for duplicate words in the source code.
- dupword
# Check for two durations multiplied together.
- durationcheck
# Go linter to check the errors handling expressions.
- err113
# Checks types passed to the json encoding functions. Reports unsupported
# types and reports occurrences where the check for the returned error can
# be omitted.
- errchkjson
# Checks that sentinel errors are prefixed with the Err and error types are
# suffixed with the Error.
- errname
# Errorlint is a linter for that can be used to find code that will cause
# problems with the error wrapping scheme introduced in Go 1.13.
- errorlint
# Check exhaustiveness of enum switch statements.
- exhaustive
# Checks if all structure fields are initialized.
# NOTE: exhaustruct is useful based on preferences but is very noisy for
# deliberately omitted nil values.
# - exhaustruct
# Detects functions from golang.org/x/exp/ that can be replaced by std
# functions.
- exptostd
# Detects nested contexts in loops and function literals.
- fatcontext
# NOTE: forbidigo is useful based on your preferences and configuration.
# - forbidigo # Forbids identifiers.
# Finds forced type assertions.
- forcetypeassert
# Checks for long functions.
# NOTE: funlen operates on a very simple and inflexible length-based rule.
# Other complexity checkers are better.
# - funlen
# Enforces standards of using ginkgo and gomega.
- ginkgolinter
# Checks that go compiler directive comments (//go:) are valid.
- gocheckcompilerdirectives
# Check that no global variables exist.
- gochecknoglobals
# Checks that no init functions are present in Go code.
- gochecknoinits
# Run exhaustiveness checks on Go "sum types".
- gochecksumtype
# Computes and checks the cognitive complexity of functions.
- gocognit
# Finds repeated strings that could be replaced by a constant.
- goconst
# Provides diagnostics that check for bugs, performance and style issues.
- gocritic
# Computes and checks the cyclomatic complexity of functions.
# NOTE: gocyclo overlaps in functionality with cyclop.
# - gocyclo
# Check if comments end in a period.
- godot
# Detects usage of FIXME, TODO and other keywords inside comments.
- godox
# Checks if file header matches to pattern.
- goheader
# Manage the use of 'replace', 'retract', and 'excludes' directives in
# go.mod.
- gomoddirectives
# 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.
- gomodguard
# Checks that printf-like functions are named with f at the end.
- goprintffuncname
# Inspects source code for security problems.
- gosec
# Report certain i18n/l10n anti-patterns in your Go codebase.
# NOTE: the project does not support i18n/l10n actively.
# - gosmopolitan
# Analyze expression groups.
- grouper
# Detect the incorrect use of interfaces, helping developers avoid interface
# pollution.
- iface
# Enforces consistent import aliases.
- importas
# Reports interfaces with unnamed method parameters.
- inamedparam
# A linter that checks the number of methods inside an interface.
- interfacebloat
# Intrange is a linter to find places where for loops could make use of an
# integer range.
- intrange
# Accept Interfaces, Return Concrete Types.
- ireturn
# Reports long lines.
- lll
# Checks key value pairs for common logger libraries (kitlog,klog,logr,zap).
- loggercheck
# Maintidx measures the maintainability index of each function.
# NOTE: maintidx does not provide much value above other complexity
# checkers.
# - maintidx
# Finds slice declarations with non-zero initial length.
- makezero
# Reports wrong mirror patterns of bytes/strings usage.
- mirror
# Finds commonly misspelled English words.
- misspell
# An analyzer to detect magic numbers.
- mnd
# Enforce field tags in (un)marshaled structs.
- musttag
# Checks that functions with naked returns are not longer than a maximum
# size (can be zero).
- 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 constructs that checks for err != nil, but returns a different nil
# value error. Powered by nilness and nilerr.
- nilnesserr
# Checks that there is no simultaneous return of nil error and an invalid value.
- nilnil
# nlreturn checks for a new line before return and branch statements to
# increase code clarity.
# NOTE: nlreturn could be enabled based on your preferences but is noisy
# otherwise.
# - nlreturn
# Finds sending http request without context.Context.
- noctx
# Reports ill-formed or insufficient nolint directives.
- nolintlint
# Reports all named returns.
- nonamedreturns
# Checks for misuse of Sprintf to construct a host with port in a URL.
- nosprintfhostport
# Detects missing usage of t.Parallel() method in your Go test.
- paralleltest
# Checks that fmt.Sprintf can be replaced with a faster alternative.
- perfsprint
# Finds slice declarations that could potentially be pre-allocated.
- prealloc
# Find code that shadows one of Go's predeclared identifiers.
- predeclared
# Check Prometheus metrics naming via promlint.
- promlinter
# Reports direct reads from proto message fields when getters should be used.
- protogetter
# Checks that package variables are not reassigned.
- reassign
# Checks for receiver type consistency.
- recvcheck
# Fast, configurable, extensible, flexible, and beautiful linter for Go.
# Drop-in replacement of golint.
- revive
# Checks whether Rows.Err of rows is checked successfully.
- rowserrcheck
# Ensure consistent code style when using log/slog.
- sloglint
# Checks for mistakes with OpenTelemetry/Census spans.
- spancheck
# Checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed.
- sqlclosecheck
# Check that struct tags are well aligned.
- tagalign
# Checks the struct tags.
# NOTE: tagliatelle is useful but requires configuration based on your
# preferences.
# - tagliatelle
# Linter checks if examples are testable (have an expected output).
- testableexamples
# Checks usage of github.com/stretchr/testify.
- testifylint
# Linter that makes you use a separate _test package.
# NOTE: Blackbox testing shouldn't necessarily be enforced and sometimes
# hinders full test coverage.
# - testpackage
# thelper detects tests helpers which is not start with t.Helper() method.
- thelper
# tparallel detects inappropriate usage of t.Parallel() method in your Go
# test codes.
- tparallel
# Remove unnecessary type conversions.
- unconvert
# Reports unused function parameters.
- unparam
# A linter that detect the possibility to use variables/constants from the
# Go standard library.
- usestdlibvars
# Reports uses of functions with replacement inside the testing package.
- usetesting
# Checks that the length of a variable's name matches its scope.
# NOTE: varnamelen isn't bad necessarily, but it is very noisy.
- varnamelen
# Finds wasted assignment statements.
- wastedassign
# Whitespace is a linter that checks for unnecessary newlines at the start
# and end of functions, if, for, etc.
- whitespace
# Checks that errors returned from external packages are wrapped.
- wrapcheck
# Add or remove empty lines.
# NOTE: wsl isn't bad necessarily, but it can be very noisy.
- wsl_v5
# Detects the wrong usage of zerolog that a user forgets to dispatch with
# Send or Msg.
- zerologlint
# Duplicate feature in another linter. Replaced by usetesting.
# - ten
settings:
cyclop:
max-complexity: 30
package-average: 6
depguard:
rules:
main:
files:
- $all
- "!$test"
allow:
# Go standard library
- $gostd
- github.com/ianlewis/lexparse
- github.com/ianlewis/runeio
deny:
- pkg: reflect
desc: Please don't use reflect package
- pkg: unsafe
desc: Please don't use unsafe package
test:
files:
# Go test files
- $test
allow:
# Go standard library
- $gostd
- github.com/ianlewis/lexparse
- github.com/ianlewis/runeio
- "github.com/google/go-cmp/cmp"
deny:
- pkg: reflect
desc: Use go-cmp instead.
- pkg: unsafe
desc: Please don't use unsafe package
errcheck:
check-type-assertions: true
check-blank: true
exhaustive:
# Presence of "default" case in switch statements satisfies
# exhaustiveness, even if all enum members are not listed.
default-signifies-exhaustive: true
gocognit:
min-complexity: 40
gocritic:
disable-all: true
enabled-checks:
- appendAssign
- argOrder
- badCond
- caseOrder
- codegenComment
- commentedOutCode
- deprecatedComment
- dupArg
- dupBranchBody
- dupCase
- dupSubExpr
- exitAfterDefer
- flagDeref
- flagName
- nilValReturn
- offBy1
- sloppyReassign
- weakCond
- octalLiteral
- appendCombine
- equalFold
- hugeParam
- indexAlloc
- rangeExprCopy
- rangeValCopy
- assignOp
- boolExprSimplify
- captLocal
- commentFormatting
- commentedOutImport
- defaultCaseOrder
- docStub
- elseif
- emptyFallthrough
- emptyStringTest
- hexLiteral
- ifElseChain
- methodExprCall
- regexpMust
- singleCaseSwitch
- sloppyLen
- stringXbytes
- switchTrue
- typeAssertChain
- typeSwitchVar
- underef
- unlabelStmt
- unlambda
- unslice
- valSwap
- wrapperFunc
- yodaStyleExpr
- builtinShadow
- importShadow
- initClause
- nestingReduce
- paramTypeCombine
- ptrToRefParam
- typeUnparen
- unnecessaryBlock
godox:
keywords:
- BUG
- FIXME
- HACK
- XXX
govet:
enable:
- shadow
disable:
- fieldalignment
nestif:
min-complexity: 8
staticcheck:
# This option sets which checks should be enabled. By default, most checks
# will be enabled, except for those that are too opinionated or that only
# apply to packages in certain domains.
#
# All supported checks can be enabled with "all". Subsets of checks can be
# enabled via prefixes and the * glob; for example, "S*", "SA*" and "SA1*"
# will enable all checks in the S, SA and SA1 subgroups respectively.
# Individual checks can be enabled by their full IDs. To disable checks,
# prefix them with a minus sign. This works on all of the previously
# mentioned values.
#
# Default value: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020",
# "-ST1021", "-ST1022"]
checks: ["all"]
# ST1013 recommends using constants from the net/http package instead of
# hard-coding numeric HTTP status codes. This setting specifies a list of
# numeric status codes that this check does not complain about.
#
# Default: ["200", "400", "404", "500"]
http_status_code_whitelist: []
varnamelen:
max-distance: 20
exclusions:
# Mode of the generated files analysis.
#
# - `strict`: sources are excluded by strictly following the Go generated file convention.
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
# This line must appear before the first non-comment, non-blank text in the file.
# https://go.dev/s/generatedcode
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
# - `disable`: disable the generated files exclusion.
#
# Default: strict
generated: lax
# Log a warning if an exclusion rule is unused.
# Default: false
warn-unused: true
# Predefined exclusion rules.
presets:
- common-false-positives
- legacy
- std-error-handling