-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.golangci.yml
309 lines (308 loc) · 11.9 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
---
version: "2"
run:
tests: false
linters:
default: none
enable:
# Default linters
- bodyclose
- errcheck # Checks for unhandled errors.
- govet # Reports suspicious constructs.
- ineffassign # Detects ineffective assignments.
- staticcheck # Performs static analysis checks, including those from govet.
# Disabled by default
- bodyclose # Checks for unclosed HTTP response bodies.
- goconst # Finds repeated strings that could be replaced by constants.
- gocritic # Performs more advanced static analysis checks.
- gosec # Identifies security vulnerabilities.
- misspell # Detects common misspellings.
- nilerr # Checks for redundant nil error checks.
- prealloc # Detects potential memory allocations that could be preallocated.
- revive # Runs additional static analysis checks. Replaces golint.
- sloglint # Checks for issues in slog calls.
- unconvert # Finds unnecessary type conversions.
- unparam # Detects unused function parameters.
- unused # Finds unused code.
# disable:
# - cyclop # Checks function and package cyclomatic complexity.
# - gocyclo # Measures cyclomatic complexity.
# - gocognit # Checks the cognitive complexity of functions
# - funlen # Finds long functions
settings:
cyclop:
# The maximal code complexity to report.
# Default: 10
max-complexity: 30
# The maximal average package complexity.
# If it's higher than 0.0 (float) the check is enabled
# Default: 0.0
package-average: 10
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
# Such cases aren't reported by default.
# Default: false
check-type-assertions: true
funlen:
# Checks the number of lines in a function.
# If lower than 0, disable the check.
# Default: 60
lines: 100
# Checks the number of statements in a function.
# If lower than 0, disable the check.
# Default: 40
statements: 50
# Ignore comments when counting lines.
# Default false
ignore-comments: true
gocognit:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
min-complexity: 20
gocyclo:
# Minimal code complexity to report.
# Default: 30 (but we recommend 10-20)
min-complexity: 20
gosec:
# Filter out the issues with a lower severity than the given value.
severity: medium
# Filter out the issues with a lower confidence than the given value.
confidence: medium
config:
# Maximum allowed permissions mode for os.Mkdir and os.MkdirAll
G301: "0750"
# Maximum allowed permissions mode for os.OpenFile and os.Chmod
G302: "0640"
# Maximum allowed permissions mode for os.WriteFile and ioutil.WriteFile
G306: "0640"
misspell:
locale: US
extra-words:
- typo: artefact
correction: artifact
revive:
enable-all-rules: false
rules:
# Suggests using constant for magic numbers and string literals
- name: add-constant
arguments:
- allowFloats: 0.0,0.,1.0,1.,2.0,2.,3.0,3.,4.0,4.,5.0,5.,6.0,6.,7.0,7.,8.0,8.,9.0,9.
allowInts: 0,1,2,3,4,5,6,7,8,9,10,0o755,0o644
allowStrs: '"","\n"'
ignoreFuncs: fmt\.*,slog\.*,.*\.WriteString
maxLitCount: "5"
severity: warning
# Warns when a function receives more parameters than the maximum set by
# the rule's configuration
- name: argument-limit
arguments:
- 5
severity: warning
# Check for commonly mistaken usages of the sync/atomic package
- name: atomic
# Using Boolean literals (true, false) in logic expressions may make the
# code less readable.
- name: bool-literal-in-expr
severity: warning
# Cognitive complexity is a measure of how hard code is to understand
# - name: cognitive-complexity
# arguments: [7]
# severity: warning
# Methods or fields of struct that have names different only by
# capitalization could be confusing.
- name: confusing-naming
severity: warning
# Function or methods that return multiple, no named, values of the same
# type could induce error
- name: confusing-results
# The rule spots logical expressions that evaluate always to the same
# value
- name: constant-logical-expr
severity: warning
# Basic types should not be used as a key in context.WithValue
- name: context-keys-type
# This rule spots potential dataraces caused by go-routines capturing
# (by-reference) particular identifiers of the function from which
# go-routines are created.
- name: datarace
# Packages exposing functions that can stop program execution by exiting
# are hard to reuse.
- name: deep-exit
severity: warning
# This rule warns on some common mistakes when using defer statement
- name: defer
arguments:
- - immediate-recover
- recover
- return
- loop
# Importing with . makes the programs much harder to understand
- name: dot-imports
severity: warning
# It is possible to unintentionally import the same package twice
- name: duplicated-imports
# In Go it is idiomatic to minimize nesting statements, a typical example
# is to avoid if-then-else constructions
- name: early-return
severity: warning
# It is possible to get a simpler program by replacing
# errors.New(fmt.Sprintf()) with fmt.Errorf().
- name: errorf
# Exported function and methods should have comments
- name: exported
arguments:
- checkPublicInterface
# Enforces conventions on source file names
# Default: ^[_A-Za-z0-9][_A-Za-z0-9-]*\.go$
- name: filename-format
# If a function controls the flow of another by passing it information on
# what to do, both functions are said to be control-coupled. Coupling
# among functions must be minimized for better maintainability of the
# code
- name: flag-parameter
severity: warning
# Typically, functions with names prefixed with Get are supposed to return
# a value
- name: get-return
# An if-then-else conditional with identical implementations in both
# branches is an error
- name: identical-branches
# Checking if an error is nil to just after return the error or nil is
# redundant
- name: if-return
# In Go it is possible to declare identifiers (packages, structs,
# interfaces, parameters, receivers, variables, constants...) that
# conflict with the name of an imported package
- name: import-shadowing
severity: warning
# By convention, for better readability, incrementing an integer variable
# by 1 is recommended to be done using the ++ operator.
- name: increment-decrement
# To improve the readability of code, it is recommended to reduce the
# indentation as much as possible. This rule highlights redundant
# else-blocks that can be eliminated from the code.
- name: indent-error-flow
# Packages declaring structs that contain other inline struct definitions
# can be hard to understand/read for other developers
- name: nested-structs
severity: warning
# This rule spots logical expressions where the order of evaluation of
# terms seems non optimal
- name: optimize-operands-order
# This rule suggests a shorter way of writing ranges that do not use the
# second value
- name: range
# Constant names like false, true, nil, function names like append, make,
# and basic type names like bool, and byte are not reserved words of the
# language; therefore the can be redefined.
- name: redefines-builtin-id
# This rule warns on redundant import aliases
- name: redundant-import-alias
# Explicit type conversion string(i) where i has an integer type other
# than rune might behave not as expected by the developer (e.g.
# string(42) is not "42"). This rule spot that kind of suspicious
# conversions
- name: string-of-int
# Struct tags are not checked at compile time
- name: struct-tag
arguments:
- json,inline
# This rule highlights redundant else-blocks that can be eliminated from
# the code
- name: superfluous-else
# This rule warns when using == and != for equality check time.Time and
# suggest to time.time.Equal method
- name: time-equal
# Using unit-specific suffix like "Secs", "Mins", ... when naming
# variables of type time.Duration can be misleading
- name: time-naming
# This rule checks whether a type assertion result is checked (the ok
# value), preventing unexpected panics
- name: unchecked-type-assertion
# Unconditional recursive calls will produce infinite recursion, thus
# program stack overflow
- name: unconditional-recursion
# This rule suggests to remove redundant statements like a break at the
# end of a case block, for improving the code's readability
- name: unnecessary-stmt
# This rule spots and proposes to remove unreachable code
- name: unreachable-code
# This rule warns on unused parameters
- name: unused-parameter
# This rule proposes to replace instances of interface{} with any
- name: use-any
# This rule warns on useless break statements in case clauses of switch
# and select statements
- name: useless-break
# This rule proposes simplifications of variable declarations
- name: var-declaration
# Function parameters that are passed by value, are in fact a copy of the
# original argument
- name: waitgroup-by-value
sloglint:
# Enforce not mixing key-value pairs and attributes.
# Default: true
no-mixed-args: true
# Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
# Default: false
# kv-only: true
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
# Default: false
# attr-only: true
# Enforce not using global loggers.
# Values:
# - "": disabled
# - "all": report all global loggers
# - "default": report only the default slog logger
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global
# Default: ""
no-global: all
# Enforce using methods that accept a context.
# Default: false
# Values:
# - "": disabled
# - "all": report all contextless calls
# - "scope": report only if a context exists in the scope of the outermost function
context: scope
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- linters:
- errcheck
- gosec
path: _test\.go
- linters:
- cyclop
- goconst
path: (.+)_test\.go
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
severity:
default: error
rules:
- linters:
- cyclop
- funlen
- gocognit
- gocyclo
severity: info
formatters:
enable:
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$