forked from genshinsim/gcsim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.golangci.yml
184 lines (162 loc) · 6.64 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
run:
timeout: 5m
build-tags:
- codeanalysis
skip-dirs:
- cmd/wasm/
linters:
disable-all: true
enable:
## golangci defaults (core linters)
# - errcheck # checking for unchecked errors, these unchecked errors can be critical bugs in some cases
- gosimple # specializes in simplifying a code
- 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
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
## style & formatting
- gofmt # go fmt requirement
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
- stylecheck # style check rules defined by staticcheck (minimum go standard style)
- 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
- exportloopref # checks for pointers to enclosing loop variables
- 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
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
- 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
linters-settings:
cyclop:
max-complexity: 30
package-average: 10.0
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
- 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
check-shadowing: false
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:
allow-no-explanation: [funlen, gocognit, lll]
require-explanation: true
require-specific: true
tenv:
all: true
tagliatelle:
case:
use-field-name: true
rules:
json: snake
yaml: snake
severity:
default-severity: error
issues:
max-same-issues: 50
exclude-rules:
- source: "//noinspection"
linters: [gocritic]
- linters:
- stylecheck
- revive
text: ".*Id should be .*ID"
- linters:
- tagliatelle
text: "got '_id' want 'id'" # play nice with MongoDB