generated from atomicgo/template
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
.golangci.yml
186 lines (176 loc) · 9.06 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
# ┌───────────────────────────────────────────────────────────────────┐
# │ │
# │ IMPORTANT NOTE │
# │ │
# │ This file is synced with https://github.com/atomicgo/template │
# │ │
# │ Please apply all changes to the template repository │
# │ │
# └───────────────────────────────────────────────────────────────────┘
run:
timeout: 3m
linters:
enable:
- errcheck # check for unchecked errors
- gosimple # specializes in simplifying code
- govet # roughly the same as go vet
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # staticcheck is a go vet on steroids, applying static analysis to your code
- unused # finds unused variables and constants
- asasalint # check `any` variadic funcs
- asciicheck # check for non-ASCII characters
- bidichk # check for dangerous unicode character sequences
- bodyclose # check that HTTP response body is closed
- canonicalheader # check that canonical headers are used
- containedctx # detects struct contained context.Context field
- contextcheck # check whether the function uses a non-inherited context
- decorder # check declaration order and count of types, constants, variables and functions
- dupl # finds duplicated code
- durationcheck # check for two durations multiplied together
- err113 # check the errors handling expressions
- errchkjson # checks types passed to the json encoding functions
- errname # check error names
- errorlint # check error wrapping
- exhaustive # check that all enum cases are handled
- exportloopref # checks for pointers to enclosing loop variables
- fatcontext # detects nested contexts in loops
- forcetypeassert # finds unchecked type assertions
- funlen # check for long functions
- gci # controls Go package import order and makes it always deterministic
- gocheckcompilerdirectives # checks that go compiler directive comments (//go:) are valid
- gochecksumtype # exhaustiveness checks on Go "sum types"
- gocognit # check for high cognitive complexity
- gocritic # Go source code linter that provides a ton of rules
- gocyclo # checks cyclomatic complexity
- gofmt # checks whether code was gofmt-ed
- gofumpt # checks whether code was gofumpt-ed
- goimports # check import statements are formatted according to the 'goimport' command
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects source code for security problems
- gosmopolitan # report certain i18n/l10n anti-patterns in your Go codebase
- inamedparam # reports interfaces with unnamed method parameters
- interfacebloat # check for large interfaces
- intrange # find places where for loops could make use of an integer range
- lll # check for long lines
- maintidx # measures the maintainability index of each function
- mirror # reports wrong mirror patterns of bytes/strings usage
- misspell # finds commonly misspelled English words
- musttag # enforce field tags in (un)marshaled structs
- nakedret # checks that functions with naked returns are not longer than a maximum size
- nestif # reports deeply nested if statements
- nilerr # finds code that returns nil even if it checks that the error is not nil
- nilnil # checks that there is no simultaneous return of nil error and an invalid value
- nlreturn # checks for a new line before return and branch statements to increase code clarity
- nolintlint # reports ill-formed or insufficient nolint directives
- nosprintfhostport # checks for misuse of Sprintf to construct a host with port in a URL
- paralleltest # detects missing usage of t.Parallel() method in your Go test
- perfsprint # checks that fmt.Sprintf can be replaced with a faster alternative
- prealloc # finds slice declarations that could potentially be pre-allocated
- predeclared # finds code that shadows one of Go's predeclared identifiers
- promlinter # checks Prometheus metrics naming via promlint
- protogetter # reports direct reads from proto message fields when getters should be used
- reassign # checks that package variables are not reassigned
- revive # drop-in replacement of golint.
- rowserrcheck # checks whether Rows.Err of rows is checked successfully
- sloglint # ensures consistent code style when using log/slog
- spancheck # checks for mistakes with OpenTelemetry/Census spans
- sqlclosecheck # checks that sql.Rows, sql.Stmt, sqlx.NamedStmt, pgx.Query are closed
- stylecheck # replacement for golint
- tagalign # checks that struct tags are well aligned
- tagliatelle # checks the struct tags
- tenv # analyzer that detects using os.Setenv instead of t.Setenv
- thelper # detects tests helpers which is not start with t.Helper() method
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # unnecessary type conversions
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
- varnamelen # checks that the length of a variable's name matches its scope
- wastedassign # finds wasted assignment statements
- whitespace # checks for unnecessary newlines at the start and end of functions, if, for, etc
- wrapcheck # checks that errors returned from external packages are wrapped
- wsl # add or remove empty lines
disable:
- copyloopvar # fixed in go 1.22+
- depguard # no forbidden imports
- dogsled # blank identifiers are allowed
- dupword # duplicate words are allowed
- exhaustruct # many structs don't need to be exhaustive
- forbidigo # no forbidden identifiers
- ginkgolinter # not used
- gochecknoinits # init functions are fine, if used carefully
- goconst # many false positives
- godot # comments don't need to be complete sentences
- godox # todo comments are allowed
- goheader # no need for a header
- gomoddirectives # allow all directives
- gomodguard # no forbidden imports
- grouper # unused
- importas # some aliases are fine
- loggercheck # no slog support
- makezero # make with non-zero initial length is fine
- noctx # http request may be sent without context
- nonamedreturns # named returns are fine
- testableexamples # examples do not need to be testable (have declared output)
- testifylint # testify is not recommended
- testpackage # not a go best practice
- unparam # interfaces can enforce parameters
- zerologlint # slog should be used instead of zerlog
- execinquery # deprecated
- gomnd # deprecated
- mnd # too many detections
- cyclop # covered by gocyclo
- gochecknoglobals # there are many valid reasons for global variables, depending on the project
- ireturn # there are too many exceptions
linters-settings:
wsl:
allow-cuddle-declarations: true
force-err-cuddling: true
force-case-trailing-whitespace: 3
funlen:
lines: 100
statements: 50
ignore-comments: true
lll:
line-length: 140
tab-width: 1
nlreturn:
block-size: 2
exhaustive:
check-generated: false
default-signifies-exhaustive: true
varnamelen:
ignore-type-assert-ok: true # ignore "ok" variables
ignore-map-index-ok: true
ignore-chan-recv-ok: true
ignore-decls:
- n int # generic number
- x int # generic number (e.g. coordinate)
- y int # generic number (e.g. coordinate)
- z int # generic number (e.g. coordinate)
- i int # generic number
- a int # generic number
- r int # generic number (e.g. red or radius)
- g int # generic number (e.g. green)
- b int # generic number (e.g. blue)
- c int # generic number (e.g. count)
- j int # generic number (e.g. index)
- T any # generic type
- a any # generic any (e.g. data)
- b any # generic any (e.g. body)
- c any # generic any
- d any # generic any (e.g. data)
- data any # generic data
- n any # generic any
- t time.Time # often used as a variable name
- f func() # often used as a callback variable name
- cb func() # often used as a callback variable name
- t testing.T # default testing.T variable name
- b testing.B # default testing.B variable name
- sb strings.Builder # often used as a variable name
issues:
exclude-rules:
- path: "_test(_[^/]+)?\\.go"
linters:
- gochecknoglobals
- noctx
- funlen
- dupl