-
Notifications
You must be signed in to change notification settings - Fork 0
/
.golangci.yml
747 lines (628 loc) · 30.2 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
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
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
#
# UpCloud golangci-lint configuration
#
run:
timeout: 5m
linters:
#
# We use a custom set of linters, so disable all and enable one-by-one.
#
disable-all: true
#
# Run golangci-lint linters or see https://golangci-lint.run/usage/linters/
# for a list of all linters. This config was last updated for v1.59.1.
#
# Please keep the list sorted alphabetically.
#
# Key:
# #: Transitionally disabled or optional, possibly to be enabled
# ##: Permanently, intentionally disabled due to implementation concerns
# or redundancy with something else that is enabled
# ###: Permanently, intentionally disabled due to deprecation
#
# If disabling a linter that is enabled in the default config or enabling
# one marked with DISABLE in it, please append a `# PROJECT: reasoning here`
# comment. For optionals, the comment is recommended but not required.
# Permanently disabled linters should not be enabled.
#
# Do consider inline case by case disabling of particular issues flagged
# instead of disabling something wholesale on this level.
#
enable:
# Warn about slices suspiciously passed as `any` variadic arguments.
# This is usually not the intent; contents of the slice more often is.
- asasalint
# Makes sure there are no non-ASCII identifiers that could be confusing or
# hard to use.
- asciicheck
# Warns on "dangerous" unicode characters, in order to prevent "trojan
# source" problems,
# https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-42574.
# While it's not that interesting for various projects, it doesn't really
# hurt either, and the probability of false positives is very low.
- bidichk
# Checks that HTTP response body (a `ReadCloser`) is closed properly.
# Somewhat chore/prone to false positives in tests.
- bodyclose
# Warns about `context.Context` members in structs, which is a "do not"
# in the `context` docs. See also https://go.dev/blog/context-and-structs.
# Some daemon life cycle management patterns are at odds with this.
- containedctx
# Checks that parent Contexts are passed on, possibly after adding to,
# instead of being dropped or new ones created in too low level code.
# Essentially `context.With*()` should be used for adding to existing
# Contexts, and Contexts carried around through the whole call chain down
# to wherever they are used. Tends to require largish refactoring in places
# where this is not met.
- contextcheck
# Checks function and package cyclomatic complexity. Could result in better
# readable and maintainable code, but in practice seems more often to get
# in the way, resolving flagged issues it not always a net win. Compared to
# `gocyclo`, calculates both function and package cyclomatic complexity.
# Similar: `gocognit`, `gocyclo`, `maintidx`.
## - cyclop # DISABLE
### - deadcode # deprecated, replaced by `unused`
# Encourage various rules on grouping and arranging `const`s, `var`s,
# `type`s and `func`s, configurability per mentioned keyword; and `init`
# func first. `init` first could be nice and differentiates this from
# alternatives, but on the other hand has similar considerations as
# one for single declaration requirement: it may not be desirable,
# as e.g. higher level grouping by placing related globals and `init`,
# functions next to their uses arguably more desirable -- then again
# this could/should be handled by splitting to more files, and if so,
# perhaps we should actually enable this? `gofumpt` makes the grouping
# redundant. Enabling would call for some discussion on desired order
# of managed types of declarations, and configuring that (does nothing
# by default without config).
# Similar: `gofumpt`, `grouper`.
## - decorder # DISABLE
# Go linter that checks if package imports are in a list of acceptable
# packages.
# Similar: `gomodguard`.
- depguard
# Warns on too many blank receivers in an assignment, for example
# `_, _, _, err := doSomething()`. Commonly this would indicate a potential
# need for refactoring, if we're using a method and ignoring most of what
# it returns. Frequently met and kind of unavoidable in some fairly rare
# use cases, such as using `runtime.Caller` to get the current file name.
- dogsled
# Warns on bits of code that have long, identical series of tokens. Helps
# with keeping code DRY which in turn helps with maintenance, readability,
# and testability. Not always trivial to fix, needs some understanding of
# the code in question. Refactoring these out can be prone to errors, due
# to missing subtle differences. Good idea to enable this as early in
# project lifecycle as possible.
- dupl
# Check for duplicate adjacent words in comments and strings. These are
# almost always errors, often caused by inadvertent edits.
- dupword
# Checks for two durations multiplied together. Seems like this could
# prevent potential bugs, but based on the experiences with actual code,
# not sure how common and serious the bugs would actually be and whether it
# actually helps or not. Code variants that pass the linter are not
# necessarily any clearer, just different.
## - durationcheck # DISABLE
# Warns about not checking errors for functions that return an error.
# Makes it impossible for the developer to miss an error being returned, as
# all errors need either to be checked or `//nolint`ed. A bit of a chore in
# tests, in particular, where there are sometimes places where one might not
# really care about errors (e.g. crashing would be ok). However, seems like
# a small price to pay for the upside.
- errcheck
# Specialized linter for JSON error checks. Contains smarts to not require
# error handling for marshaling operations that "cannot" return an error.
# However there are some doubts about this, including whether/how
# exhaustive it is, how futureproof regarding Go versions it is, and
# stopping using this linter would place us at risk unless something else
# would cover for its fallout. Ignoring errors is also a bad general
# practice, which could spread. The default config in golangci-lint is good
# and conservative, "cannot happen" error flagging is not enabled.
- errchkjson
# Verifies consistent naming for error types (`type FooError ...`) and
# sentinels (`var ErrFoo = errors.New(...)`), as used in stdlib and
# described in the conventions, see
# https://github.com/golang/go/wiki/Errors#naming.
- errname
# Promotes use of the stdlib error handling primitives (`errors.Is`,
# `errors.As`, `%w` in `fmt.Errorf`, etc). Somewhat at odds with codebases
# using `pkg/errors`, but those are generally moving towards stdlib.
- errorlint
# Checks that SQL statements are executed with the appropriate `.Exec` or
# `.Query` function.
### - execinquery # deprecated as of 1.58.1
# Checks that switches of enum(-like) types cover every possible case.
# Very helpful when we need to add new cases to enums, making sure that all
# the relevant bits are checked. Can become annoying if there's a _lot_ of
# possible cases, for example with `reflect.Kind`.
- exhaustive
### - exhaustivestruct # deprecated, replaced by exhaustruct
# Checks if all struct's fields are initialized. Good in the sense that
# doing so would make it easier to spot changes to underlying structs.
# Breaks the "empty struct as default value" convention of Go code. Not
# meant to be enabled for everything, can be useful in specific cases.
## - exhaustruct # DISABLE
# Forbids passing pointers to the loop variable out of scope. This is a
# common class of bugs in Go code, as the semantics aren't immediately
# obvious to everyone. In Go, the loop variable is re-used on every run of
# the loop meaning that any pointers pointing to it are also pointing to
# the same location across iterations. Some codebases seem to have a common
# pattern of storing the pointer and immediately breaking the loop
# afterwards, which should be fine. However, it certainly opens up the door
# for regressions down the road if the changes to that code do not keep it
# as such. Enabling `exportloopref` forces such cases to be commented, at
# least. Redundant with `gosec`s G601, which also catches more cases of
# this category.
## - exportloopref # DISABLE
# Forbid use of particular identifiers. Most commonly used to disallow use
# of `println` and `fmt.Print*`. Rationale here is that these are commonly
# used as debugging tools and as such, should not make their way into the
# actual commits. A bit of a chore to avoid in cases where we actually
# _want_ to print to stdout. `fmt.Fprint*` and/or using an appropriate
# logging package serve as examples of replacements.
- forbidigo
# Promotes checking of all type conversions. We shouldn't need to do that
# much type converting in general (`interface{}` is a bit of a code smell
# in most cases) but when we do, making sure we got the right type and
# handling it gracefully beats panicing. This is at odds in some projects
# that need to follow dependencies' conventions involving `interface{}`
# passing and their type safety checked by other means. `errcheck`
# configured with `check-type-assertions: true` makes this redundant.
## - forcetypeassert # DISABLE
# Limits the size of functions to a maximum number of lines and statements.
# Difficult to enable later on, as many of the long functions are hard to
# break up later. By setting a limitation from day 1, it should be easier
# to avoid writing complex functions that are hard to maintain and
# test/validate.
# Similar: cyclomatic complexity and maintainability linters, but this very
# basic and easy to understand limit is good enough for most cases.
- funlen
# Control package import order and make it deterministic. Handles empty
# lines better than `goimport` does. Gets rid of commits that change the
# order, which would otherwise pollute commits and/or history. Autofixable.
# Redundant with `gofumpt`.
# Similar: `gofumpt`, `goimports`.
## - gci # DISABLE
# Warns about global variables. Global variables make it hard to follow
# what happens and add hard to spot side effects to importing. Avoidable
# in most cases.
- gochecknoglobals
# Warns about `init()`s. `init()`s make it hard to follow what happens and
# add hard to spot side effects to importing, as well as some startup
# costs. Avoidable in most cases.
- gochecknoinits
# Checks exhaustiveness of type switch statements for interfaces
# annotated to be "sum types".
- gochecksumtype
# See `cyclop` for discussion.
## - gocognit # DISABLE
# Promotes making consts out of repeated strings. Eases maintenance,
# lessens the chance of typo errors and helps with DX as well.
# Perhaps slightly on the aggressive side for example in tests.
- goconst
# Quite an opinionated linter, but has a lot of good suggestions and
# catches bugs. See `linters-settings` for some more info.
- gocritic
# See `cyclop` for discussion.
## - gocyclo # DISABLE
# Quite a minor one, only checks (autofixable) that comments end in a
# period as the Go code review comments suggest:
# https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences.
- godot
# Warns on comments with TODO, FIXME, etc. These kinds of comments
# typically get forgotten quickly, only to be discovered by whoever is
# working on the code next who then has two tasks at hand, instead of the
# one expected. The rationale here is that these kinds of things should be
# handled through the same issue management tools as everything else,
# rather than leaving code comments. Usefulness depends on project
# lifecycle, can be a chore early on.
# - godox # OPTIONAL
# Check error handling expressions. Redundant with `errorlint`.
## - goerr113 # DISABLE
# The ubiquitous, official Go formatter. We like to take a compatible step
# further, and enable `gofumpt` instead, making this redundant.
# Similar: `gofumpt`, `goimports`.
## - gofmt # DISABLE
# A more opinionated superset of `gofmt`, enforcing a standard formatting
# of code, autofixable. See the list of added rules over `go fmt` at
# https://github.com/mvdan/gofumpt#added-rules. IDE configured to format
# with gofumpt recommended.
# Similar: `gofmt` + `gci`, `goimports`.
- gofumpt
# Check file header matches a configured pattern. We don't have a standard
# one applicable to all projects.
## - goheader # DISABLE
# Does everything `gofmt` does, and additionally fixes up and formats
# imports. Our use of `gofumpt` makes this redundant.
# Similar: `gci`, `gofmt`, `gofumpt`.
## - goimports # DISABLE
### - golint # deprecated, replaced by revive
# Ensures that `go.mod` files stay clean. Limits the use of `replace` and
# `retract` and `exclude` directives in `go.mod`, which are mostly used
# ad-hoc in development, and becoming obsolete as of Go 1.18's workspaces.
- gomoddirectives
# See discussion in `depguard`.
## - gomodguard # DISABLE
# Checks that printf-style functions have a tailing `f` in their name.
- goprintffuncname
# Warns on a lot of different potentially insecure bits of code. There are
# some case dependent false positives that are not easily avoidable through
# config, for example related to intentionally relaxed file permissions and
# `math/rand` vs `crypto/rand`.
- gosec
# Suggests various simplifications in code, hopefully resulting in better
# readability. Perhaps slightly on the aggressive side.
- gosimple
# Flags code smells that may prove to be hindrance to
# internationalization ("i18n") and/or localization ("l10n").
- gosmopolitan
# `go vet` is the 'official' linter, found in stdlib. Seems to do a lot of
# the same stuff as `staticcheck`, but as both are enabled in golangci-lint
# by default, and neither is advertized as being a replacement for the
# other, we keep both enabled as well.
- govet
# Do various checks on grouping and arranging `const`s, `var`s, `type`s and
# `import`s, configurability per mentioned keyword. Partially redundant
# with `gofumpt`, `decorder` would be a superset of this if we'd like to
# expand beyond what `gofumpt` does.
## - grouper # DISABLE
### - ifshort # deprecated
# Promotes consistent style of import aliasing. Enabled as long as there
# are some entries to configure, see `linters-settings` for more info.
- importas
# Detects when assignments to existing variables are not used. Can uncover
# variable shadowing bugs as well. Redundant with `wastedassign`.
# - ineffassign # DISABLE
# Check for too many interface members.
# Go Proverbs: "The bigger the interface, the weaker the abstraction."
- interfacebloat
### - interfacer # deprecated
# Implements the return part of the popular "accept abstract types, return
# concrete types" programming paradigm; essentially, advises not to return
# interfaces. Although not always that clear cut, returning interfaces
# tends to require callers to jump through an unneeded layer of indirection
# hoops.
# - ireturn # OPTIONAL
# Report too long lines. Likely calls for discussion before enabling.
## - lll # DISABLE
# Check that common logger library function calls have appropriate number
# of key/value arguments.
- loggercheck
# See discussion in `cyclop`.
## - maintidx # DISABLE
# Warns on `make`:ing slices with non-0 length but > 0 capacity, that get
# appended to shortly afterwards. Essentially, picks up that
# `slice := make([]int, 1)` (this list would be `[]int{ 0 }` with cap 1)
# should be `slice := make([]int, 0, 1)` (an empty list with cap 1) if
# followed by `slice = append(slice, 1)`. This is a classic Go bug at this
# point as `append` is the common way of adding to a slice and it's easy to
# forget the initial size from the `make` call by accident.
- makezero
### - maligned # deprecated
# Helps avoid unnecessary conversions between byte arrays and strings.
- mirror
# Finds commonly misspelled English words, autofixable. Fixes/suggestions
# need to be handled with care, as they include occurrences of misspelled
# words in strings which could have external dependencies, such as APIs.
- misspell
# Forbids final naked returns (eg. named return values and just `return` as
# the last statement) in long enough (configurable) functions.
# Naked returns are nice for simple helper methods, but in many cases they
# can be a bit difficult to follow along and make things more confusing
# compared to just explicit `return foo, nil`.
- nakedret
# Warns on deeply nested if-statements. These are hard to read and follow.
# Can be a chore to address after the fact, enabling early recommended.
- nestif
# Flags returning a `nil` after checking for an error, a fairly common
# mistake to make with `==` vs `!=`.
- nilerr
# Warns against both return value and error being `nil`, instructs using a
# sentinel value for the return in non-error conditions. Non-error `nil`
# return values are unusual and tend to need additional checks or extra
# care on use. Going against this rule is sometimes necessary due to
# contracts in implemented interfaces.
- nilnil
# Checks for a new line before return and branch statements to increase
# code clarity. Helps with readability. Rendered redundant by `whitespace`.
# Similar: `whitespace`, `wsl`
## - nlreturn # DISABLE
# Checks for use of Context in HTTP requests. Contexts should be supported
# in relevant places, in order to allow for cancellation etc., but more
# importantly, to make the developer consider the scenario too.
- noctx
# Promotes consistent style for `//nolint` directives, requiring them to
# specify the disabled linter _and_ have a comment, describing why it was
# disabled in the case at hand. Does very little in its default
# golangci-lint config, see `linters-settings` for non-defaults we set.
- nolintlint
# Similar as `nakedret`, but without the configurability, and triggers
# on existence rather than use of named return values.
## - nonamedreturns # DISABLE
# Redundant subset of what `revive`s `var-naming` does.
## - nosnakecase # DISABLE
# Advises to use `net.JoinHostPort` instead of direct `fmt.Sprintf` with
# separate host and port to construct URLs, for IPv6 compatibility.
- nosprintfhostport
# Together with `tparallel', encourages the use of `t.Parallel()` in all
# tests and catches some common problems with them. Using `t.Parallel()` as
# much as possible improves confidence in our code being thread-safe and
# working in parallel, forces the developer to think about parallelism,
# improves the encapsulation of tests as sharing state typically makes it
# difficult to run tests in parallel, speeds up running of tests, greatly
# improving DX. A chore to introduce afterwards, so should be enabled as
# early as possible.
- paralleltest
# Promotes preallocating slices and maps with a known length. Go grows
# these on demand, but in clear cases we should help it out as it can have
# a non-negligible performance benefit. Arguably makes code a little bit
# more brittle (need to remember to take this into account when
# refactoring) and a bit less readable (simple default value slices are
# clearer).
- prealloc
# Forbids using names that would shadow
# [predeclared Go identifiers](https://golang.org/ref/spec#Predeclared_identifiers).
# While Go allows this, it seems like common sense to not shadow built-in
# identifiers as that might make some code rather surprising.
- predeclared
# Check Prometheus metrics naming via promlint. Not applicable for now.
## - promlinter # DISABLE
# Check protobuf field chain accesses susceptible for causing panics.
- protogetter
# Warn about reassigning top level variables from another package.
# Such variables are rarely if ever intended to be reassigned; they tend
# to be variables instead of constants because of language constraints or
# for interoperability/idiomacy.
- reassign
# A better (e.g. more rules and faster) version of the original `golint`
# which has been deprecated.
# Similar: `stylecheck` (`revive` seems more extensive, `stylecheck` is a
# sibling project to `staticcheck`).
- revive
# Verifies that `sql.Rows` `.Error()` is checked when querying database.
# Easy to miss but important to do, for example to be aware of connection
# breakages while iterating results, thus getting only a subset.
- rowserrcheck
### - scopelint # deprecated
# Code style consistency checks specific to `log/slog` use.
- sloglint
# Checks that `sql.Rows` and `sql.Stmt` are closed properly. Not closing
# can cause exhaustion of the connection pool and problems.
- sqlclosecheck
# Detects incorrect OpenTelemetry span usage patterns.
- spancheck
# A lot of different checks, `go vet` on steroids, as described by the
# author. Encourages some basic good practices, catches some hard to debug
# problems.
- staticcheck
### - structcheck # deprecated, replaced by `unused`
# Encourages various opinionated styles and rules including naming.
# Redundant with `revive`.
## - stylecheck # DISABLE
# Aligns and sorts struct tags, for better readability and
# mainainability.
- tagalign
# Checks the struct tags for correct and consistent style.
# Many struct tags exist for interoperability in possibly third party
# JSON APIs, which the code needs to abide by no matter consistency or
# style concerns.
## - tagliatelle # DISABLE
# Advises to use `t.SetEnv` instead of `os.SetEnv` so that one does not
# need to bother with restoring the pre-test env var value. Note that
# this is not applicable to parallel tests.
- tenv
# Checks that examples run by the `testing` package have an applicable
# "output" comment, so that the example output can be verified to be as
# expected.
- testableexamples
# Code style consistency and readability checks specific to `testify`.
- testifylint
# Promotes using test packages (eg. `package foo_test`) in regular tests
# (files ending with `_test.go`), allows for internal tests (in the same
# package) only to exist in files ending with `_internal_test.go`.
# This separation forces the developer to think about the exported
# interface and how it is used, keeps test packages better separated as
# it's more difficult (impossible?) to refer to other packages' tests,
# and makes it harder to accidentally export test-related helpers and mocks
# that could be confusing. Somewhat chore to address afterwards, so good
# to enable in as early project lifecycle as possible.
- testpackage
# Checks for `t.Helper()` in helper methods. Using `t.Helper()` improves
# the output of testing and thus gives better information to the developer,
# improving DX. Helps with some good practices in test functions as well,
# such as `t *testing.T` as the first parameter.
- thelper
# See discussion for `paralleltest`.
- tparallel
# Basically does what the frontend of the Go compiler does, parses and type
# checks code. More of a sanity check before committing than an actual
# linter. Several other linters require compiled/typechecked code before
# they can do their work, so this cannot really be disabled in the usual
# sense. See https://github.com/golangci/golangci-lint/issues/2912
- typecheck
# Warns on unnecessary type conversions. Unnecessary conversions make code
# harder to read and can also relay false information to the developer,
# e.g. assuming that a particular method returns a type that needs to be
# converted.
- unconvert
# Reports unused function parameters. Drawbacks include catching methods
# in tests that always get called with the same parameters, and checking
# return values where always returning a `nil` err is required for
# interface contracts. Poor signal to noise ratio in experiments.
## - unparam # DISABLE
# Checks code for unused constants, variables, functions and types.
# Removing unused bits is good, as they could easily confuse future
# development and even cause unnecessary work.
- unused
# Endorse use of various consts and variables defined in stdlib.
- usestdlibvars
### - varcheck # deprecated, replaced by `unused`
# Variable name length checks, takes definition and use span lengths into
# account. Nice idea, idiomatic Go, but needs discussion if we want to go
# with their defaults which cause a lot of errors in various existing
# codebases, or if we want to refine what our default limits would be.
# - varnamelen # OPTIONAL
# Warns on assignments that are never read or are overwritten before
# reading. This helps with readability of the code as it's not always so
# clear where the actual value comes from, especially if it's overwritten
# in assignments. Might also prevent some bugs where a value gets
# overwritten by accident. Detects more cases than `ineffassign`, and
# gives better explanations.
# Similar: `ineffassign`
- wastedassign
# Checks for whitespace/empty lines around blocks, autofixable. Does
# generally enough without being too overbearing.
# Similar: `wsl` (more aggressive, not autofixable (?)), `nlreturn`
# (also not seem to be autofixable (?), at least through golangci-lint).
- whitespace
# Checks that errors returned originating from external packages are
# wrapped. The most important facet of wrapping errors is to provide
# context for figuring out where an error actually occurred.
- wrapcheck
# A whitespace linter that is quite aggressive, causing a lot of changes
# in typical codebases. `whitespace` is the generally preferred choice
# over this.
## - wsl # DISABLE
# Detects incorrect zerolog usage patterns.
- zerologlint
output:
# Get all issues from all linters, instead of just first per line, so we
# get to see everything on first pass.
uniq-by-line: false
issues:
exclude: []
# We used to have a mixture of initialisms and non-initialisms between and
# even within projects, but are converging towards the initialisms practice
# that is the most common one with Go code in general. Note that changing
# the naming is a breaking change, and whether/when/how to do it depends on
# the case at hand.
# - "^var-naming: .+ should be " # OPTIONAL, if needed
# Disable per linter/same-issue limits, again to get the whole picture on
# first pass.
max-issues-per-linter: 0
max-same-issues: 0
# Fix found issues where supported, because life is too short. Be sure to
# sanity check the diffs.
fix: true
# Exclude some linters from testing
exclude-rules:
# PROJECT: This project curently follows cobra example on how to setup command tree, which means use of global variables and init function.
- path: cmd/
linters:
- gochecknoglobals
- gochecknoinits
- path: _test\.go
linters:
# Test functions can easily grow quite large and don't/can't really
# be shortened
- funlen
# Enforcing context in tests clutters up the code and isn't really
# necessary
- noctx
# Closing response bodies in tests clutters up the code and isn't
# really necessary
- bodyclose
linters-settings:
depguard:
rules:
main:
deny:
- pkg: "github.com/pkg/errors"
desc: "use stdlib instead"
errcheck:
# See discussion in `forcetypeassert`.
check-type-assertions: true
gocritic:
disabled-checks:
# commentFormatting is redundant with/inferior to gofumpt which can also
# autofix this.
- commentFormatting
# hugeParam, range*Copy (from performance tag) to be discussed, arguably
# promote unconventional code.
- hugeParam
- rangeValCopy
- rangeExprCopy
enabled-tags:
# Most performance checks also encourage clean/idiomatic code.
- performance
settings:
captLocal:
paramsOnly: false
gofumpt:
extra-rules: true
importas:
no-unaliased: true
alias:
# Prominently differentiate pkg/errors and stdlib errors.
- pkg: github.com/pkg/errors
alias: pkgerrors
nolintlint:
require-explanation: true
require-specific: true
reassign:
patterns:
- ".*"
revive:
rules:
- name: var-naming
arguments:
- []
- [
"ACME",
"AMQP",
"BGP",
"CA",
"CIDR",
"CN",
"CSV",
"DB",
"DCMI",
"DHCP",
"DN",
"DSA",
"ECDSA",
"EMA",
"EVI",
"EVPN",
"FIFO",
"FRU",
"GID",
"GPU",
"IB",
"IOPS",
"IPMI",
"JWT",
"KV",
"LAN",
"LFU",
"LIFO",
"LRU",
"MAC",
"MS",
"NIC",
"PDF",
"PKI",
"PSU",
"PTR",
"REST",
"RSA",
"RTP",
"RX",
"SCSI",
"SDN",
"SHA",
"SIP",
"SPOE",
"SSD",
"TS",
"TSIG",
"TSV",
"TTL",
"TX",
"TXN",
"ULID",
"VAT",
"VCPU",
"VIP",
"VLAN",
"VRF",
]