-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy path.golangci.yml
More file actions
206 lines (182 loc) · 6.9 KB
/
.golangci.yml
File metadata and controls
206 lines (182 loc) · 6.9 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
version: "2"
run:
build-tags:
- codeanalysis
linters:
default: none
enable:
## golangci defaults (core linters)
# - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
- ineffassign # detects when assignments to existing variables are not used
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
## style & formatting
- gocritic # provides diagnostics that check for bugs, performance and style issues
- whitespace # detects leading and trailing whitespace
- nolintlint # reports ill-formed or insufficient nolint directives
- errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- nonamedreturns # reports all named returns
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
- tagalign # checks that struct tags are well aligned
- tagliatelle # checks the struct tags are snake case
# TODO: use this when merged into tagliatelle https://github.com/ldez/tagliatelle/pull/21
## code complexity detectors
- nestif # reports deeply nested if statements
# - lll # reports long lines
# - funlen # tool for detection of long functions
# - gocognit # computes and checks the cognitive complexity of functions
# - gocyclo # computes and checks the cyclomatic complexity of functions
# - cyclop # checks function and package cyclomatic complexity
## code smell (can lead to errors/bugs)
- asasalint # checks for pass []any as any in variadic func(...any)
- bidichk # checks for dangerous unicode character sequences
- unused # checks for unused constants, variables, functions and types
- dogsled # checks assignments with too many blank identifiers (e.g. x, , , _, := f())
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
- errchkjson # checks for unnecessary json marshal error checks
- copyloopvar # detects places where loop variables are copied
- makezero # finds slice declarations with non-zero initial length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- nakedret # finds naked returns in functions greater than a specified function length
- wastedassign # finds wasted assignment statements
- unparam # reports unused function parameters
- unconvert # removes unnecessary type conversions
- goconst # finds repeated strings that could be replaced by a constant
- predeclared # finds code that shadows one of Go's predeclared identifiers
- reassign # checks that package variables are not reassigned
# - dupl # tool for code clone detection
# - nilnil # checks that there is no simultaneous return of nil error and an invalid value
## enforcements which can lead to better code
# - musttag # enforces field tags in (un)marshaled structs
# - exhaustruct # checks if all structure fields are initialized
## misc linters
- gocheckcompilerdirectives # validates go compiler directive comments (//go:)
- gomodguard # allow and block lists linter for direct Go module dependencies.
- mirror # reports wrong mirror patterns of bytes/strings usage
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
- usestdlibvars # detects the possibility to use variables/constants from the Go standard library
settings:
cyclop:
max-complexity: 30
package-average: 10
errcheck:
check-type-assertions: true
exhaustruct:
exclude:
## sim code
## dependencies
- 'net/http'
# - 'github\.com/urfave/cli/v2'
- 'google\.golang\.org/protobuf/encoding/protojson'
funlen:
lines: 100
statements: 50
gocognit:
min-complexity: 20
gocritic:
enabled-tags:
- performance # finds places where we can make performance improvements
- opinionated # opinionated style rules
disabled-checks:
- importShadow # covered by another linter
- builtinShadow # covered by another linter
- unnamedResult # opposite of nonamedreturns
- hugeParam # probably want to enable for better performance. Benchmark first
settings:
captLocal:
paramsOnly: false
underef:
skipRecvDeref: false
revive:
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
rules:
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: var-naming
arguments:
- [""] # AllowList
- [""] # DenyList
- - skip-package-name-checks: true # TODO: rename internal/characters/traveler/common and internal/weapons/common
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unreachable-code
- name: redefines-builtin-id
govet:
enable-all: true
disable:
- fieldalignment # great for micro-optimizations, too much work for us to maintain
- shadow # can help to find hard to find bugs, but annoying to make golang code compatible
gomodguard:
blocked:
modules:
- github.com/golang/protobuf:
recommendations:
- google.golang.org/protobuf
reason: "see https://protobuf.dev/reference/go/faq/#modules"
nakedret:
max-func-lines: 0
nolintlint:
require-explanation: true
require-specific: true
allow-no-explanation:
- funlen
- gocognit
- lll
tagliatelle:
case:
use-field-name: true
rules:
json: snake
yaml: snake
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- source: "//noinspection"
linters:
- gocritic
- linters:
- staticcheck
- revive
text: ".*Ids? should be .*IDs?"
- linters:
- tagliatelle
text: "got '_id' want 'id'" # play nice with MongoDB
paths:
- cmd/wasm/
- third_party$
- builtin$
- examples$
severity:
default: error
issues:
max-same-issues: 50
formatters:
enable:
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- cmd/wasm/
- third_party$
- builtin$
- examples$