forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.golangci.yml
executable file
·207 lines (188 loc) · 8.08 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
# options for analysis running
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 15m
build-tags:
- synthetics
- integration
issues:
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 3
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 50
exclude-rules:
# Exclude package name contains '-' issue because we have at least one package with
# it on its name.
- text: "ST1003:"
linters:
- stylecheck
- text: "undefined"
linters:
- typecheck
- text: "undeclared name:"
linters:
- typecheck
- text: "imported and not used"
linters:
- typecheck
- text: "previous case"
linters:
- typecheck
# From mage we are printing to the console to ourselves
- path: (.*magefile.go|.*dev-tools/mage/.*)
linters: forbidigo
output:
sort-results: true
# Find the whole list here https://golangci-lint.run/usage/linters/
linters:
disable-all: true
enable:
- errcheck # checking for unchecked errors in go programs
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
- forbidigo # forbids identifiers matched by reg exps
- gosimple # linter for Go source code that specializes in simplifying a code
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nolintlint # reports ill-formed or insufficient nolint directives
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
- stylecheck # a replacement for golint
- unused # checks Go code for unused constants, variables, functions and types
- govet # Vet examines Go source code and 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
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
- bodyclose # checks whether HTTP response body is closed successfully
- durationcheck # check for two durations multiplied together
- exportloopref # checks for pointers to enclosing loop variables
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
- gosec # inspects source code for security problems
- importas # enforces consistent import aliases
- nilerr # finds the code that returns nil even if it checks that the error is not nil.
- noctx # noctx finds sending http request without context.Context
- unconvert # Remove unnecessary type conversions
- wastedassign # wastedassign finds wasted assignment statements.
- gomodguard # check for blocked dependencies
- depguard
- gomoddirectives
# all available settings of specific linters
linters-settings:
depguard:
rules:
apache-licensed-code:
list-mode: lax
files:
- '!**/x-pack/**/*.go'
deny:
- pkg: github.com/elastic/beats/v7/x-pack
desc: Apache 2.0 licensed code cannot depend on Elastic licensed code (x-pack/).
errcheck:
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: true
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
check-blank: false
# List of functions to exclude from checking, where each entry is a single function to exclude.
# See https://github.com/kisielk/errcheck#excluding-functions for details.
exclude-functions:
- (github.com/elastic/elastic-agent-libs/mapstr.M).Delete # Only returns ErrKeyNotFound, can safely be ignored.
- (github.com/elastic/elastic-agent-libs/mapstr.M).Put # Can only fail on type conversions, usually safe to ignore.
- github.com/elastic/elastic-agent-libs/logp.TestingSetup # Cannot return a non-nil error using the provided API.
- github.com/elastic/elastic-agent-libs/logp.DevelopmentSetup # Cannot return a non-nil error using the provided API.
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
errorf: true
# Check for plain type assertions and type switches
asserts: true
# Check for plain error comparisons
comparison: true
forbidigo:
# Forbid the following identifiers
forbid:
- fmt.Print.* # too much log noise
# Exclude godoc examples from forbidigo checks. Default is true.
exclude_godoc_examples: true
goimports:
local-prefixes: github.com/elastic
gomodguard:
blocked:
# List of blocked modules.
modules:
# Blocked module.
- github.com/pkg/errors:
# Recommended modules that should be used instead. (Optional)
recommendations:
- errors
- fmt
reason: "This package is deprecated, use `fmt.Errorf` with `%w` instead"
- github.com/google/uuid:
# Recommended modules that should be used instead. (Optional)
recommendations:
- github.com/gofrs/uuid/v5
reason: "Use one uuid library consistently across the codebase"
gomoddirectives:
# Forbid local `replace` directives
replace-local: false
# Forbid any `replace` directives that are intended temporarily only during
# development. The modules listed below are intended to be replaced permanently.
replace-allow-list:
- github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/consumption/armconsumption
- github.com/Shopify/sarama
- github.com/apoydence/eachers
- github.com/dop251/goja
- github.com/dop251/goja_nodejs
- github.com/fsnotify/fsevents
- github.com/fsnotify/fsnotify
- github.com/google/gopacket
- github.com/insomniacslk/dhcp
- github.com/meraki/dashboard-api-go/v3
- github.com/snowflakedb/gosnowflake
gosimple:
# Select the Go version to target. The default is '1.13'.
go: "1.22.8"
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 0
nolintlint:
# Enable to ensure that nolint directives are all used. Default is true.
allow-unused: false
# Exclude following linters from requiring an explanation. Default is [].
allow-no-explanation: []
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
require-explanation: true
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
require-specific: false
staticcheck:
# Select the Go version to target. The default is '1.13'.
go: "1.22.8"
checks: ["all"]
stylecheck:
# Select the Go version to target. The default is '1.13'.
go: "1.22.8"
# Disabled:
# ST1005: error strings should not be capitalized
checks: ["all", "-ST1005"]
unused:
# Select the Go version to target. The default is '1.13'.
go: "1.22.8"
gosec:
excludes:
- G306 # Expect WriteFile permissions to be 0600 or less
- G404 # Use of weak random number generator
- G401 # Detect the usage of DES, RC4, MD5 or SHA1: Used in non-crypto contexts.
- G501 # Import blocklist: crypto/md5: Used in non-crypto contexts.
- G505 # Import blocklist: crypto/sha1: Used in non-crypto contexts.
prealloc:
# IMPORTANT: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
# Report pre-allocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# Default: true
simple: false
# Report pre-allocation suggestions on range loops.
# Default: true
range-loops: true
# Report pre-allocation suggestions on for loops.
# Default: false
for-loops: true