-
Notifications
You must be signed in to change notification settings - Fork 50
/
.golangci.yml
196 lines (191 loc) · 7.29 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
# Copyright The Karpor Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This file contains all available configuration options
# with their default values.
# For complete .golangci.yml configuration, reference: https://golangci-lint.run/usage/configuration/#config-file
# options for analysis running
run:
timeout: 8m
go: '1.22'
linters:
disable-all: true
enable: # please keep this alphabetized
- bodyclose # Checks whether HTTP response body is closed successfully
- contextcheck # Check whether the function uses a non-inherited context
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
- errorlint # Find code that will cause problems with the error wrapping scheme
- errname # Checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
- copyloopvar # Checks for range loop variables that are used after the loop in goroutines
- forbidigo # Forbids identifiers
- gocritic # Provides diagnostics that check for bugs, performance and style issues
- goconst # Finds repeated strings that could be replaced by a constant
- gofumpt # Checks whether code was gofumpt-ed
- gosimple # Specializes in simplifying code
- ineffassign # Detects when assignments to existing variables are not used
- loggercheck # Checks key value pairs for common logger libraries
- misspell # Finds commonly misspelled English words
- nilerr # Finds the code that returns nil even if it checks that the error is not nil
- nilnil # Checks that there is no simultaneous return of nil error and an invalid value
- nolintlint # Reports ill-formed or insufficient nolint directives
- prealloc # Finds slice declarations that could potentially be pre-allocated
- predeclared # Finds code that shadows one of Go's predeclared identifiers
- staticcheck # Go static analysis
- stylecheck # Stylecheck is a replacement for golint
- tagliatelle # Checks the struct tags case
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- thelper # thelper detects golang test helpers without t.Helper() call
- tparallel # Detects inappropriate usage of t.Parallel() method in your Go test codes
- unconvert # Remove unnecessary type conversions
- unparam # Reports unused function parameters
- unused # Checks Go code for unused constants, variables, functions and types
- usestdlibvars # Detects the possibility to use variables/constants from the Go standard library
- whitespace # Tool for detection of leading and trailing whitespace
linters-settings:
gofumpt:
extra-rules: false
tagliatelle:
case:
use-field-name: true
rules:
# Support string case: `camel`, `pascal`, `kebab`, `snake`, `upperSnake`, `goCamel`, `goPascal`, `goKebab`, `goSnake`, `upper`, `lower`
json: goCamel
yaml: goCamel
xml: goCamel
toml: goCamel
errorlint:
# Check whether fmt.Errorf uses the %w verb for formatting errors
errorf: false
govet:
enable:
- asmdecl
- assign
- atomic
- bools
- buildtag
- cgocall
- composites
- copylocks
- errorsas
- fieldalignment
- framepointer
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
- printf
- shift
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
disable:
- buildssa
- fieldalignment
settings:
printf:
funcs:
- (github.com/sirupsen/logrus.FieldLogger).Infof
- (github.com/sirupsen/logrus.FieldLogger).Warnf
- (github.com/sirupsen/logrus.FieldLogger).Errorf
- (github.com/sirupsen/logrus.FieldLogger).Fatalf
issues:
exclude-rules:
- path: _test\.go
linters:
- gocyclo
- errcheck
- dupl
- gosec
- path: \.pb\.go
linters:
- all
- path: \.gen\.go
linters:
- all
- path: pkg/kubernetes/.*
linters:
- goanalysis_metalinter
- path: pkg/kubernetes/internalimport/internal_import\.go$
linters:
- all
- path: internal_import\.go$
linters:
- typecheck
- govet
- text: "import .* is a program, not an importable package"
linters:
- typecheck
- text: "json\\(goCamel\\): got 'metadata'" # Allow 'metadata' as standard k8s field name
linters:
- tagliatelle
- path: pkg/syncer/source\.go
text: "return both a `nil` error and an invalid value"
linters:
- nilnil
- path: pkg/syncer/syncer\.go
text: "return both a `nil` error and an invalid value"
linters:
- nilnil
- path: pkg/syncer/jsonextracter/jsonpath\.go
text: "return both a `nil` error and an invalid value"
linters:
- nilnil
- path: pkg/syncer/jsonextracter/jsonpath\.go
text: "`\\(\\*JSONPath\\)\\.evalRecursive` - `node` is unused"
linters:
- unparam
- path: pkg/syncer/jsonextracter/fieldpath\.go
text: "return both a `nil` error and an invalid value"
linters:
- nilnil
- path: pkg/core/manager/cluster/manager_test\.go
text: "`newMockCluster` - `name` always receives"
linters:
- unparam
# Allow fmt.Println in version generation script
- path: pkg/version/scripts/gen/gen\.go
text: "use of `fmt.Println`"
linters:
- forbidigo
# Allow fmt.Println in version commands
- path: cmd/(cert-generator|karpor)/.*
text: "use of `fmt.Println`"
linters:
- forbidigo
- path: cmd/karpor/app/server\.go
linters:
- contextcheck
exclude-dirs:
- "pkg/kubernetes/generated" # Generated code
- "pkg/kubernetes/openapi" # Generated OpenAPI code
- "api/openapispec" # Generated API specs
- "hack" # Scripts and tools
- vendor # Third-party dependencies
- third_party # Third-party code
- test # Test files
exclude-files:
- internal_import\.go$
- pkg/kubernetes/openapi/zz_generated.openapi.go
exclude:
- "G306: Expect WriteFile permissions to be 0600 or less" # Security warning for file permissions
- "ST1018: string literal contains Unicode control characters" # Style issue for string literals
- "ifElseChain: rewrite if-else to switch statement" # Style suggestion
- "S1000: should use for range instead of for { select {} }" # Style suggestion
- "SA4004: the surrounding loop is unconditionally terminated" # Code structure warning