Skip to content

Commit 7fa6bef

Browse files
committed
Upgrade golangci-lint to v2.1.1 and migrate configuration
On-behalf-of: SAP <[email protected]> Signed-off-by: Marvin Beckers <[email protected]>
1 parent 1964831 commit 7fa6bef

File tree

3 files changed

+159
-158
lines changed

3 files changed

+159
-158
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ jobs:
3838
- name: golangci-lint
3939
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # tag=v7.0.0
4040
with:
41-
version: v1.64.5
42-
args: --out-format=colored-line-number
41+
version: v2.1.1
4342
working-directory: ${{matrix.working-directory}}
4443

4544
golangci-lint: # aggregate the results of the matrix job. This we can depend on in the branch protection rule.

.golangci.yml

Lines changed: 157 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
version: "2"
2+
run:
3+
go: "1.23"
4+
allow-parallel-runners: true
15
linters:
2-
disable-all: true
6+
default: none
37
enable:
48
- asasalint
59
- asciicheck
@@ -12,15 +16,11 @@ linters:
1216
- errchkjson
1317
- errorlint
1418
- exhaustive
15-
- gci
1619
- ginkgolinter
1720
- goconst
1821
- gocritic
1922
- gocyclo
20-
- gofmt
21-
- goimports
2223
- goprintffuncname
23-
- gosimple
2424
- govet
2525
- importas
2626
- ineffassign
@@ -32,161 +32,163 @@ linters:
3232
- prealloc
3333
- revive
3434
- staticcheck
35-
- stylecheck
3635
- tagliatelle
37-
- typecheck
3836
- unconvert
3937
- unparam
4038
- unused
4139
- whitespace
42-
43-
linters-settings:
44-
govet:
45-
enable-all: true
46-
disable:
47-
- fieldalignment
48-
- shadow
49-
gci:
50-
custom-order: true
51-
skip-generated: true
52-
sections:
53-
- standard
54-
- default
55-
- prefix(k8s.io)
56-
- prefix(sigs.k8s.io/controller-runtime)
57-
- prefix(sigs.k8s.io/multicluster-runtime)
58-
- blank
59-
- dot
60-
importas:
61-
no-unaliased: true
62-
alias:
63-
# Kubernetes
64-
- pkg: k8s.io/api/core/v1
65-
alias: corev1
66-
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
67-
alias: apiextensionsv1
68-
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
69-
alias: metav1
70-
- pkg: k8s.io/apimachinery/pkg/api/errors
71-
alias: apierrors
72-
- pkg: k8s.io/apimachinery/pkg/util/errors
73-
alias: kerrors
74-
# Controller Runtime
75-
- pkg: sigs.k8s.io/controller-runtime
76-
alias: ctrl
77-
revive:
78-
rules:
40+
settings:
41+
govet:
42+
disable:
43+
- fieldalignment
44+
- shadow
45+
enable-all: true
46+
importas:
47+
alias:
48+
# Kubernetes
49+
- pkg: k8s.io/api/core/v1
50+
alias: corev1
51+
- pkg: k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1
52+
alias: apiextensionsv1
53+
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
54+
alias: metav1
55+
- pkg: k8s.io/apimachinery/pkg/api/errors
56+
alias: apierrors
57+
- pkg: k8s.io/apimachinery/pkg/util/errors
58+
alias: kerrors
59+
# Controller Runtime
60+
- pkg: sigs.k8s.io/controller-runtime
61+
alias: ctrl
62+
no-unaliased: true
63+
revive:
7964
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
80-
- name: blank-imports
81-
- name: context-as-argument
82-
- name: context-keys-type
83-
- name: dot-imports
84-
- name: error-return
85-
- name: error-strings
86-
- name: error-naming
87-
- name: exported
88-
- name: if-return
89-
- name: increment-decrement
90-
- name: var-naming
91-
- name: var-declaration
92-
- name: range
93-
- name: receiver-naming
94-
- name: time-naming
95-
- name: unexported-return
96-
- name: indent-error-flow
97-
- name: errorf
98-
- name: superfluous-else
99-
- name: unreachable-code
100-
- name: redefines-builtin-id
101-
#
102-
# Rules in addition to the recommended configuration above.
103-
#
104-
- name: bool-literal-in-expr
105-
- name: constant-logical-expr
106-
65+
rules:
66+
- name: blank-imports
67+
- name: context-as-argument
68+
- name: context-keys-type
69+
- name: dot-imports
70+
- name: error-return
71+
- name: error-strings
72+
- name: error-naming
73+
- name: exported
74+
- name: if-return
75+
- name: increment-decrement
76+
- name: var-naming
77+
- name: var-declaration
78+
- name: range
79+
- name: receiver-naming
80+
- name: time-naming
81+
- name: unexported-return
82+
- name: indent-error-flow
83+
- name: errorf
84+
- name: superfluous-else
85+
- name: unreachable-code
86+
- name: redefines-builtin-id
87+
# Rules in addition to the recommended configuration above.
88+
- name: bool-literal-in-expr
89+
- name: constant-logical-expr
90+
exclusions:
91+
generated: lax
92+
rules:
93+
- linters:
94+
- gosec
95+
text: 'G108: Profiling endpoint is automatically exposed on /debug/pprof'
96+
- linters:
97+
- revive
98+
text: 'exported: exported method .*\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported'
99+
- linters:
100+
- errcheck
101+
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
102+
- linters:
103+
- staticcheck
104+
text: 'SA1019: .*The component config package has been deprecated and will be removed in a future release.'
105+
- linters:
106+
- staticcheck
107+
text: 'QF1008: could remove embedded field ".*" from selector'
108+
# With Go 1.16, the new embed directive can be used with an un-named import,
109+
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
110+
# This directive allows the embed package to be imported with an underscore everywhere.
111+
- linters:
112+
- revive
113+
source: _ "embed"
114+
# Exclude some packages or code to require comments, for example test code, or fake clients.
115+
- linters:
116+
- revive
117+
text: exported (method|function|type|const) (.+) should have comment or be unexported
118+
source: (func|type).*Fake.*
119+
- linters:
120+
- revive
121+
path: fake_\.go
122+
text: exported (method|function|type|const) (.+) should have comment or be unexported
123+
# Disable unparam "always receives" which might not be really
124+
# useful when building libraries.
125+
- linters:
126+
- unparam
127+
text: always receives
128+
# Dot imports for gomega and ginkgo are allowed
129+
# within test files.
130+
- path: _test\.go
131+
text: should not use dot imports
132+
- path: _test\.go
133+
text: cyclomatic complexity
134+
- path: _test\.go
135+
text: 'G107: Potential HTTP request made with variable url'
136+
# Append should be able to assign to a different var/slice.
137+
- linters:
138+
- gocritic
139+
text: 'appendAssign: append result not assigned to the same slice'
140+
- linters:
141+
- gocritic
142+
text: 'singleCaseSwitch: should rewrite switch statement to if statement'
143+
# It considers all file access to a filename that comes from a variable problematic,
144+
# which is naiv at best.
145+
- linters:
146+
- gosec
147+
text: 'G304: Potential file inclusion via variable'
148+
- linters:
149+
- dupl
150+
path: _test\.go
151+
- linters:
152+
- revive
153+
path: .*/internal/.*
154+
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
155+
# If it is decided they will not be addressed they should be moved above this comment.
156+
- path: (.+)\.go$
157+
text: Subprocess launch(ed with variable|ing should be audited)
158+
- path: (.+)\.go$
159+
text: (G204|G104|G307)
160+
- path: (.+)\.go$
161+
text: 'ST1000: at least one file in a package should have a package comment'
162+
paths:
163+
- zz_generated.*\.go$
164+
- .*conversion.*\.go$
165+
- third_party$
166+
- builtin$
167+
- examples$
107168
issues:
108-
max-same-issues: 0
109169
max-issues-per-linter: 0
110-
# We are disabling default golangci exclusions because we want to help reviewers to focus on reviewing the most relevant
111-
# changes in PRs and avoid nitpicking.
112-
exclude-use-default: false
113-
# List of regexps of issue texts to exclude, empty list by default.
114-
exclude:
115-
# The following are being worked on to remove their exclusion. This list should be reduced or go away all together over time.
116-
# If it is decided they will not be addressed they should be moved above this comment.
117-
- Subprocess launch(ed with variable|ing should be audited)
118-
- (G204|G104|G307)
119-
- "ST1000: at least one file in a package should have a package comment"
120-
exclude-files:
121-
- "zz_generated.*\\.go$"
122-
- ".*conversion.*\\.go$"
123-
exclude-rules:
124-
- linters:
125-
- gosec
126-
text: "G108: Profiling endpoint is automatically exposed on /debug/pprof"
127-
- linters:
128-
- revive
129-
text: "exported: exported method .*\\.(Reconcile|SetupWithManager|SetupWebhookWithManager) should have comment or be unexported"
130-
- linters:
131-
- errcheck
132-
text: Error return value of .((os\.)?std(out|err)\..*|.*Close|.*Flush|os\.Remove(All)?|.*print(f|ln)?|os\.(Un)?Setenv). is not checked
133-
- linters:
134-
- staticcheck
135-
text: "SA1019: .*The component config package has been deprecated and will be removed in a future release."
136-
# With Go 1.16, the new embed directive can be used with an un-named import,
137-
# revive (previously, golint) only allows these to be imported in a main.go, which wouldn't work for us.
138-
# This directive allows the embed package to be imported with an underscore everywhere.
139-
- linters:
140-
- revive
141-
source: _ "embed"
142-
# Exclude some packages or code to require comments, for example test code, or fake clients.
143-
- linters:
144-
- revive
145-
text: exported (method|function|type|const) (.+) should have comment or be unexported
146-
source: (func|type).*Fake.*
147-
- linters:
148-
- revive
149-
text: exported (method|function|type|const) (.+) should have comment or be unexported
150-
path: fake_\.go
151-
# Disable unparam "always receives" which might not be really
152-
# useful when building libraries.
153-
- linters:
154-
- unparam
155-
text: always receives
156-
# Dot imports for gomega and ginkgo are allowed
157-
# within test files.
158-
- path: _test\.go
159-
text: should not use dot imports
160-
- path: _test\.go
161-
text: cyclomatic complexity
162-
- path: _test\.go
163-
text: "G107: Potential HTTP request made with variable url"
164-
# Append should be able to assign to a different var/slice.
165-
- linters:
166-
- gocritic
167-
text: "appendAssign: append result not assigned to the same slice"
168-
- linters:
169-
- gocritic
170-
text: "singleCaseSwitch: should rewrite switch statement to if statement"
171-
# It considers all file access to a filename that comes from a variable problematic,
172-
# which is naiv at best.
173-
- linters:
174-
- gosec
175-
text: "G304: Potential file inclusion via variable"
176-
- linters:
177-
- dupl
178-
path: _test\.go
179-
- linters:
180-
- revive
181-
path: .*/internal/.*
182-
- linters:
183-
- unused
184-
# Seems to incorrectly trigger on the two implementations that are only
185-
# used through an interface and not directly..?
186-
# Likely same issue as https://github.com/dominikh/go-tools/issues/1616
187-
path: pkg/controller/priorityqueue/metrics\.go
188-
189-
run:
190-
go: "1.23"
191-
timeout: 10m
192-
allow-parallel-runners: true
170+
max-same-issues: 0
171+
formatters:
172+
enable:
173+
- gci
174+
- gofmt
175+
- goimports
176+
settings:
177+
gci:
178+
sections:
179+
- standard
180+
- default
181+
- prefix(k8s.io)
182+
- prefix(sigs.k8s.io/controller-runtime)
183+
- prefix(sigs.k8s.io/multicluster-runtime)
184+
- blank
185+
- dot
186+
custom-order: true
187+
exclusions:
188+
generated: lax
189+
paths:
190+
- zz_generated.*\.go$
191+
- .*conversion.*\.go$
192+
- third_party$
193+
- builtin$
194+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ $(CONTROLLER_GEN): # Build controller-gen from tools folder.
100100
GOLANGCI_LINT_BIN := golangci-lint
101101
GOLANGCI_LINT_VER := $(shell cat .github/workflows/ci.yml | grep [[:space:]]version: | sed 's/.*version: //')
102102
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
103-
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
103+
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
104104

105105
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
106106
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)

0 commit comments

Comments
 (0)