generated from hedzr/cmdr-go-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.golangci.yaml
457 lines (441 loc) · 15 KB
/
.golangci.yaml
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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# This code is licensed under the terms of the MIT license.
## Golden config for golangci-lint v1.50.1
#
# This is the best config for golangci-lint based on my experience and opinion.
# It is very strict, but not extremely strict.
# Feel free to adopt and change it for your needs.
# This file contains only configs which differ from defaults.
# All possible options can be found here https://github.com/golangci/golangci-lint/blob/master/.golangci.reference.yml
# https://fossies.org/linux/istio/common/config/.golangci.yml
# https://github.com/golangci/golangci-lint/blob/master/.golangci.yml
# https://olegk.dev/go-linters-configuration-the-right-version
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
#
# The original version of this file is located in the https://github.com/istio/common-files repo.
# If you're looking at this file in a different repo and want to make a change, please go to the
# common-files repo, make the change there and check it in. Then come back to this repo and run
# "make update-common".
service:
# When updating this, also update the version stored in docker/build-tools/Dockerfile in the istio/tools repo.
golangci-lint-version: 1.54.x # use the fixed version to not introduce new linters unexpectedly
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 20m
build-tags:
- integ
- integfuzz
- integration
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- genfiles$
- vendor$
- ref
- playground
- fixtures
- testdata
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
- ".*\\_string\\.go"
# issues-exit-code: 1
# skip-dirs-use-default: false
# go: '1.19'
output:
# I prefer the simplest one: `line-number` and saving to `lint.txt`
#
# The `tab` also looks good and with the next release I will switch to it
# (ref: https://github.com/golangci/golangci-lint/issues/3728)
#
# There are more formats which can be used on CI or by your IDE.
format: line-number:lint.txt
# I do not find this useful, parameter above already enables filepath
# with a line and column. For me, it's easier to follow the path and
# see the line in an IDE where I see more code and understand it better.
print-issued-lines: false
# Must have. Easier to understand the output.
print-linter-name: true
# No, no skips, everything should be reported.
uniq-by-line: false
# To be honest no idea when this can be needed, maybe a multi-module setup?
path-prefix: ""
# Slightly easier to follow the results + getting deterministic output.
sort-results: true
linters:
disable-all: true
enable:
- errcheck
- exportloopref
- depguard
- gocritic
- gofumpt
- goimports
- revive
- gosimple
- govet
- ineffassign
- lll
- misspell
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- gci
- gosec
fast: false
linters-settings:
dupword: # checks for duplicate words in the source code [fast: true, auto-fix: true]
auto-fix: false
tagliatelle:
case:
rules:
json: snake # kebab? why it's not a `snake` by default?!
yaml: kebab # snake? why it's not a `snake` by default?!
xml: camel
bson: camel
avro: snake
mapstructure: kebab
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 # Deafult: flse
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false
# Function to skip.
exclude-functions:
- io/ioutil.ReadFile
- io.Copy(*bytes.Buffer)
- io.Copy(os.Stdout)
goconst:
min-len: 2
min-occurrences: 3
godot: # Check if comments end in a period [fast: true, auto-fix: true]
auto-fix: true
gofmt:
auto-fix: true
gofumpt:
auto-fix: true
govet:
# report about shadowed variables
check-shadowing: false
fast: true
disable:
- fieldalignment # I'm ok to waste some bytes
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: istio.io/
# auto-fix: true
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
fast: true
auto-fix: false
ignore-words:
- cancelled
- hedzr
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 160
# tab width in spaces. Default to 1.
tab-width: 1
revive:
ignore-generated-header: false
severity: "warning"
confidence: 0.0
error-code: 2
warning-code: 1
rules:
- name: blank-imports
- name: context-keys-type
- name: time-naming
- name: var-declaration
- name: unexported-return
- name: errorf
- name: context-as-argument
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: increment-decrement
- name: var-naming
- name: package-comments
- name: range
- name: receiver-naming
- name: indent-error-flow
- name: superfluous-else
- name: modifies-parameter
- name: unreachable-code
- name: struct-tag
- name: constant-logical-expr
- name: bool-literal-in-expr
- name: redefines-builtin-id
- name: imports-blacklist
- name: range-val-in-closure
- name: range-val-address
- name: waitgroup-by-value
- name: atomic
- name: call-to-gc
- name: duplicated-imports
- name: string-of-int
- name: defer
arguments:
- - "call-chain"
- name: unconditional-recursion
- name: identical-branches
# the following rules can be enabled in the future
# - name: empty-lines
# - name: confusing-results
# - name: empty-block
# - name: get-return
# - name: confusing-naming
# - name: unexported-naming
# - name: early-return
# - name: unused-parameter
# - name: unnecessary-stmt
# - name: deep-exit
# - name: import-shadowing
# - name: modifies-value-receiver
# - name: unused-receiver
# - name: bare-return
# - name: flag-parameter
# - name: unhandled-error
# - name: if-return
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
# and rta for programs with main packages. Default is cha.
algo: cha
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
gci:
sections:
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- prefix(github.com/hedzr/) # Groups all imports with the specified Prefix.
- prefix(istio.io/) # Groups all imports with the specified Prefix.
- prefix(github.com/gravitational/teleport) # Custom section: groups all imports with the specified Prefix.
skip-generated: true # Skip generated files.
custom-order: true # Required for "sections" to take effect.
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
# These 3 will detect many cases, but they do sense
# if it's performance oriented code
- hugeParam
- rangeExprCopy
- rangeValCopy
- commentedOutCode
enabled-checks: []
# Already Enabled:
# - appendCombine
# - argOrder
# - assignOp
# - badCond
# - boolExprSimplify
# - builtinShadow
# - captLocal
# - caseOrder
# - codegenComment
# - commentedOutCode
# - commentedOutImport
# - defaultCaseOrder
# - deprecatedComment
# - docStub
# - dupArg
# - dupBranchBody
# - dupCase
# - dupSubExpr
# - elseif
# - emptyFallthrough
# - equalFold
# - flagDeref
# - flagName
# - hexLiteral
# - indexAlloc
# - initClause
# - methodExprCall
# - nilValReturn
# - octalLiteral
# - offBy1
# - rangeExprCopy
# - regexpMust
# - sloppyLen
# - stringXbytes
# - switchTrue
# - typeAssertChain
# - typeSwitchVar
# - typeUnparen
# - underef
# - unlambda
# - unnecessaryBlock
# - unslice
# - valSwap
# - weakCond
# Unused
# - yodaStyleExpr
# - appendAssign
# - commentFormatting
# - emptyStringTest
# - exitAfterDefer
# - ifElseChain
# - hugeParam
# - importShadow
# - nestingReduce
# - paramTypeCombine
# - ptrToRefParam
# - rangeValCopy
# - singleCaseSwitch
# - sloppyReassign
# - unlabelStmt
# - unnamedResult
# - wrapperFunc
depguard:
rules:
DenyGogoProtobuf:
files:
- $all
deny:
- pkg: github.com/gogo/protobuf
desc: "gogo/protobuf is deprecated, use golang/protobuf"
# deny for all go files
AllGoFiles:
files:
- $all
deny:
- pkg: golang.org/x/net/http2/h2c
desc: "h2c.NewHandler is unsafe; use wrapper istio.io/istio/pkg/h2c"
- pkg: github.com/golang/protobuf
desc: 'use "google.golang.org/protobuf"'
- pkg: github.com/golang/protobuf/jsonpb
desc: "don't use the jsonpb package directly; use util/protomarshal instead"
- pkg: google.golang.org/protobuf/encoding/protojson
desc: "don't use the protojson package directly; use util/protomarshal instead"
- pkg: gomodules.xyz/jsonpatch/v3
desc: "don't use v3; v2 is orders of magnitude higher performance"
- pkg: k8s.io/apimachinery/pkg/util/sets
desc: "use istio.io/istio/pkg/sets"
- pkg: k8s.io/utils/env
desc: "use istio.io/istio/pkg/env"
- pkg: k8s.io/utils/strings/slices
desc: "use istio.io/istio/pkg/slices"
- pkg: k8s.io/utils/pointer
desc: "use istio.io/istio/pkg/ptr"
- pkg: go.opencensus.io
desc: "do not use OpenCensus; use OpenTelemetry instead"
- pkg: github.com/siddontang/go-log/log
desc: 'use "github.com/sirupsen/logrus" instead'
- pkg: github.com/siddontang/go/log
desc: 'use "github.com/sirupsen/logrus" instead'
- pkg: go.uber.org/atomic
desc: 'use "sync/atomic" instead'
- pkg: io/ioutil
desc: 'use "io" or "os" packages instead'
DenyOperatorAndIstioctl:
files:
# Tests can do anything
- "!$test"
# Main code should only be used by appropriate binaries
- "!**/operator/**"
- "!**/istioctl/**"
- "!**/tools/bug-report/**"
# This should only really import operator API, but that is hard to express without a larger refactoring
- "!**/pkg/kube/**"
- "!**/pkg/url/**"
- "!**/pkg/test/framework/**"
- "!**/tests/fuzz/**"
deny:
- pkg: istio.io/istio/operator
desc: "operator should not be imported"
- pkg: istio.io/istio/istioctl
desc: "istioctl should not be imported"
DenyOpenTelemetry:
files:
- $all
- "!**/pkg/monitoring/**"
- "!**/pkg/tracing/**"
deny:
- pkg: go.opentelemetry.io/otel
desc: "do not use OpenTelemetry directly; use pkg/monitoring"
- pkg: go.opentelemetry.io/otel/metric
desc: "do not use OpenTelemetry directly; use pkg/monitoring"
gosec:
includes:
- G401
- G402
- G404
nolintlint:
allow-unused: true # Enabled because of conditional builds / build tags.
require-explanation: true
require-specific: true
golint:
min-confidence: 0
gocyclo:
min-complexity: 25
dupl:
threshold: 200
funlen:
lines: 100
statements: 50
tagalign: # check that struct tags are well aligned [fast: true, auto-fix: true]
auto-fix: true
whitespace:
auto-fix: true
issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- composite literal uses unkeyed fields
exclude-rules:
# Exclude some linters from running on test files.
- path: _test\.go$|^tests/|^samples/
linters:
- errcheck
- maligned
# We need to use the deprecated module since the jsonpb replacement is not backwards compatible.
- linters:
- staticcheck
text: "SA1019: package github.com/golang/protobuf/jsonpb"
- linters:
- staticcheck
text: 'SA1019: "github.com/golang/protobuf/jsonpb"'
# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: true
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0