...
1# golangci-lint is used in Kubernetes with different configurations that
2# enable an increasing amount of checks:
3# - golangci.yaml is the most permissive configuration. All existing code
4# passed.
5# - golangci-strict.yaml adds checks that all new code in pull requests
6# must pass.
7# - golangci-hints.yaml adds checks for code patterns where developer
8# and reviewer may decide whether findings should get addressed before
9# merging. Beware that the golangci-lint output includes also the
10# issues that must be fixed and doesn't indicate how severe each issue
11# is (https://gophers.slack.com/archives/CS0TBRKPC/p1685721815275349).
12#
13# All three flavors are generated from golangci.yaml.in with
14# hack/update-golangci-lint-config.sh.
15
16run:
17 timeout: 30m
18 skip-files:
19 - "^zz_generated.*"
20
21output:
22 sort-results: true
23
24issues:
25 max-issues-per-linter: 0
26 max-same-issues: 0
27
28 # The default excludes disable the "should have comment or be unexported" check from revive.
29 # We want that to be enabled, therefore we have to disable all default excludes and
30 # add those back one-by-one that we want. See https://github.com/golangci/golangci-lint/issues/456#issuecomment-617470264
31 exclude-use-default: false
32 exclude:
33 # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
34 - ineffective break statement. Did you mean to break out of the outer loop
35
36 # Excluding configuration per-path, per-linter, per-text and per-source
37 exclude-rules:
38 # exclude ineffassign linter for generated files for conversion
39 - path: conversion\.go
40 linters:
41 - ineffassign
42
43 # SSA Extract calls are allowed in tests.
44 - linters:
45 - forbidigo
46 text: should not be used because managedFields was removed
47 path: _test.go$
48
49 # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components
50 # with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs.
51 - path: (pkg/volume/*|test/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*)
52 linters:
53 - gocritic
54
55 # The Kubernetes naming convention for conversion functions uses underscores
56 # and intentionally deviates from normal Go conventions to make those function
57 # names more readable. Same for SetDefaults_*.
58 #
59 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627
60 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592
61 - linters:
62 - stylecheck
63 - revive
64 text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)"
65
66 # This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91).
67 - linters:
68 - ginkgolinter
69 text: use a function call in (Eventually|Consistently)
70
71 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435
72 - linters:
73 - gocritic
74 text: "ifElseChain: rewrite if-else to switch statement"
75
76 # Only packages listed here opt into the strict "exported symbols must be documented".
77 #
78 # Exclude texts from https://github.com/golangci/golangci-lint/blob/ab3c3cd69e602ff53bb4c3e2c188f0caeb80305d/pkg/config/issues.go#L11-L103
79 - linters:
80 - golint
81 - revive
82 - stylecheck
83 text: comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|exported (.+) should have comment( \(or a comment on this block\))? or be unexported|package comment should be of the form "(.+)...|comment on exported (.+) should be of the form "(.+)...|should have a package comment
84 path-except: cmd/kubeadm
85
86 # The following issues were deemed "might be worth fixing, needs to be
87 # decided on a case-by-case basis". This was initially decided by a
88 # majority of the developers who voted in
89 # https://github.com/kubernetes/kubernetes/issues/117288 and may evolve
90 # over time.
91
92 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918
93 - linters:
94 - gocritic
95 text: "assignOp:"
96
97 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507016854
98 - linters:
99 - gosimple
100 text: "S1002: should omit comparison to bool constant"
101
102 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507023980
103 - linters:
104 - gosimple
105 text: "S1016: should convert opts .* instead of using struct literal"
106
107 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507026758
108 - linters:
109 - gosimple
110 text: "S1033: unnecessary guard around call to delete"
111
112 # Didn't make it into https://github.com/kubernetes/kubernetes/issues/117288.
113 # Discussion on Slack concluded that "it's hard to have a universal policy for all
114 # functions marked deprecated" and thus this can only be a hint which must
115 # be considered on a case-by-case basis.
116 - linters:
117 - staticcheck
118 text: "SA1019: .*is deprecated"
119
120 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507030071
121 - linters:
122 - stylecheck
123 text: "ST1012: error var .* should have name of the form ErrFoo"
124
125 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507031224
126 - linters:
127 - stylecheck
128 text: "ST1023: should omit type .* from declaration; it will be inferred from the right-hand side"
129
130linters:
131 disable-all: true
132 enable: # please keep this alphabetized
133 - forbidigo
134 - ginkgolinter
135 - gocritic
136 - govet
137 - ineffassign
138 - logcheck
139 - revive
140 - staticcheck
141 - stylecheck
142 - unused
143
144linters-settings: # please keep this alphabetized
145 custom:
146 logcheck:
147 # Installed there by hack/verify-golangci-lint.sh.
148 path: ../_output/local/bin/logcheck.so
149 description: structured logging checker
150 original-url: k8s.io/logtools/logcheck
151 settings:
152 config: |
153 # hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>,
154 # for example k8s.io/cmd/kube-scheduler/app/config/config.go.
155 #
156 # By default, structured logging call parameters are checked, but usage of
157 # those calls is not required. That is changed on a per-file basis.
158 #
159 # Remember to clean the golangci-lint cache when changing the configuration and
160 # running the verify-golangci-lint.sh script multiple times, otherwise
161 # golangci-lint will report stale results:
162 # _output/local/bin/golangci-lint cache clean
163
164 # At this point we don't enforce the usage structured logging calls except in
165 # those packages that were migrated. This disables the check for other files.
166 -structured .*
167
168 # Now enable it again for migrated packages.
169 structured k8s.io/kubernetes/cmd/kubelet/.*
170 structured k8s.io/kubernetes/pkg/kubelet/.*
171 structured k8s.io/kubernetes/pkg/proxy/.*
172 structured k8s.io/kms/.*
173 structured k8s.io/apiserver/pkg/storage/value/.*
174 structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.*
175
176 # The following packages have been migrated to contextual logging.
177 # Packages matched here do not have to be listed above because
178 # "contextual" implies "structured".
179 contextual k8s.io/client-go/metadata/.*
180 contextual k8s.io/client-go/tools/events/.*
181 contextual k8s.io/client-go/tools/record/.*
182 contextual k8s.io/dynamic-resource-allocation/.*
183 contextual k8s.io/kubernetes/cmd/kube-proxy/.*
184 contextual k8s.io/kubernetes/cmd/kube-scheduler/.*
185 contextual k8s.io/kubernetes/pkg/controller/.*
186 contextual k8s.io/kubernetes/pkg/scheduler/.*
187 contextual k8s.io/kubernetes/test/e2e/dra/.*
188
189 # As long as contextual logging is alpha or beta, all WithName, WithValues,
190 # NewContext calls have to go through klog. Once it is GA, we can lift
191 # this restriction. Whether we then do a global search/replace remains
192 # to be decided.
193 with-helpers .*
194 forbidigo:
195 analyze-types: true
196 forbid:
197 - p: ^managedfields\.ExtractInto$
198 pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
199 msg: should not be used because managedFields was removed
200 - p: \.Extract
201 pkg: ^k8s\.io/client-go/applyconfigurations/
202 msg: should not be used because managedFields was removed
203 gocritic:
204 enabled-checks:
205 - equalFold
206 - boolExprSimplify
207 revive:
208 # Only these rules are enabled.
209 rules:
210 - name: exported
211 arguments:
212 - disableStutteringCheck
213 staticcheck:
214 checks:
215 - "all"
216 - "-SA1019" # TODO(fix) Using a deprecated function, variable, constant or field
217 - "-SA2002" # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
218 stylecheck:
219 checks:
220 - "ST1019" # Importing the same package multiple times
View as plain text