Skip to content

Commit 7d99775

Browse files
authored
Merge pull request #3391 from cnvergence/update-golangci-lint
update golangci-lint to v2
2 parents 54966ed + 4dbae87 commit 7d99775

File tree

44 files changed

+274
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+274
-284
lines changed

.golangci.yaml

Lines changed: 147 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,108 @@
1+
version: "2"
12
run:
2-
timeout: 10m
33
allow-parallel-runners: true
4-
54
linters:
6-
disable-all: true
5+
default: none
76
enable:
8-
- asasalint
9-
- asciicheck
10-
- bidichk
11-
- bodyclose
12-
- containedctx
13-
- copyloopvar
14-
- dupword
15-
- durationcheck
16-
- errcheck
17-
- errchkjson
18-
- gci
19-
- gocritic
20-
- godot
21-
- gofmt
22-
- goprintffuncname
23-
- gosec
24-
- gosimple
25-
- govet
26-
- importas
27-
- ineffassign
28-
- misspell
29-
- nilerr
30-
- noctx
31-
- nolintlint
32-
- nosprintfhostport
33-
- prealloc
34-
- revive
35-
- staticcheck
36-
- unconvert
37-
- unused
38-
- usestdlibvars
39-
- whitespace
7+
- asasalint
8+
- asciicheck
9+
- bidichk
10+
- bodyclose
11+
- containedctx
12+
- copyloopvar
13+
- dupword
14+
- durationcheck
15+
- errcheck
16+
- errchkjson
17+
- gocritic
18+
- godot
19+
- goprintffuncname
20+
- gosec
21+
- govet
22+
- importas
23+
- ineffassign
24+
- misspell
25+
- nilerr
26+
- noctx
27+
- nolintlint
28+
- nosprintfhostport
29+
- prealloc
30+
- revive
31+
- staticcheck
32+
- unconvert
33+
- unused
34+
- usestdlibvars
35+
- whitespace
4036
# TODO(vincepri): Figure out if we want to enable or remove the following linters:
4137
# - predeclared
4238
# - goconst
43-
44-
linters-settings:
45-
misspell:
46-
ignore-words:
47-
- creater
48-
goconst:
49-
ignore-tests: true
50-
nolintlint:
51-
allow-unused: false
52-
allow-leading-space: false
53-
require-specific: true
54-
revive:
39+
settings:
40+
gocritic:
41+
disabled-checks:
42+
- appendAssign
43+
- dupImport # https://github.com/go-critic/go-critic/issues/845
44+
- evalOrder
45+
- ifElseChain
46+
- octalLiteral
47+
- regexpSimplify
48+
- sloppyReassign
49+
- truncateCmp
50+
- typeDefFirst
51+
- unnamedResult
52+
- unnecessaryDefer
53+
- whyNoLint
54+
- wrapperFunc
55+
- unnecessaryBlock
56+
- rangeValCopy
57+
- hugeParam
58+
- commentedOutCode
59+
- emptyStringTest
60+
- singleCaseSwitch
61+
- nestingReduce
62+
- filepathJoin
63+
- tooManyResultsChecker
64+
enabled-tags:
65+
- diagnostic
66+
- experimental
67+
- performance
68+
gosec:
69+
excludes:
70+
- G307 # Deferring unsafe method "Close" on type "\*os.File"
71+
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
72+
# TODO(vincepri): The following should be looked at and removed in future iterations.
73+
- G401 # Use of weak cryptographic primitive (replace sha1 usage)
74+
- G505 # crypto/sha1: weak cryptographic primitive
75+
- G402 # TLS MinVersion too low (set MinVersion in TLSClientConfig)
76+
- G404 # Use of weak random number generator (use crypto/rand)
77+
- G101 # Potential hardcoded credentials (returns false positives)
78+
- G306 # Expect WriteFile permissions to be 0600 or less
79+
misspell:
80+
ignore-rules:
81+
- creater
82+
nolintlint:
83+
require-specific: true
84+
allow-unused: false
85+
revive:
5586
# make sure error-strings issues actually surface (default confidence is 0.8)
56-
confidence: 0.6
57-
rules:
58-
- name: context-keys-type
59-
- name: duplicated-imports
60-
- name: error-return
61-
- name: error-strings
62-
- name: error-naming
63-
- name: if-return
64-
- name: increment-decrement
65-
- name: var-declaration
66-
- name: package-comments
67-
- name: range
68-
- name: receiver-naming
69-
- name: time-naming
70-
- name: errorf
71-
- name: superfluous-else
72-
- name: unreachable-code
73-
- name: bool-literal-in-expr
74-
- name: constant-logical-expr
87+
confidence: 0.6
88+
rules:
89+
- name: context-keys-type
90+
- name: duplicated-imports
91+
- name: error-return
92+
- name: error-strings
93+
- name: error-naming
94+
- name: if-return
95+
- name: increment-decrement
96+
- name: var-declaration
97+
- name: package-comments
98+
- name: range
99+
- name: receiver-naming
100+
- name: time-naming
101+
- name: errorf
102+
- name: superfluous-else
103+
- name: unreachable-code
104+
- name: bool-literal-in-expr
105+
- name: constant-logical-expr
75106
# TODO(vincepri): Figure out if we want to enable
76107
# the following rules, or remove them completely, they're a bit noisy.
77108
# - name: context-as-argument
@@ -82,69 +113,55 @@ linters-settings:
82113
# - name: indent-error-flow # I think @ncdc prefers explicit else statements, remove?
83114
# - name: redefines-builtin-id
84115
# - name: dot-imports
85-
gci:
86-
custom-order: true
87-
sections:
88-
- standard
89-
- default
90-
- prefix(k8s.io)
91-
- prefix(github.com/kcp-dev)
92-
- prefix(github.com/kcp-dev/kcp)
93-
- blank
94-
- dot
95-
skip-generated: false
96-
gosec:
97-
excludes:
98-
- G307 # Deferring unsafe method "Close" on type "\*os.File"
99-
- G108 # Profiling endpoint is automatically exposed on /debug/pprof
100-
# TODO(vincepri): The following should be looked at and removed in future iterations.
101-
- G401 # Use of weak cryptographic primitive (replace sha1 usage)
102-
- G505 # crypto/sha1: weak cryptographic primitive
103-
- G402 # TLS MinVersion too low (set MinVersion in TLSClientConfig)
104-
- G404 # Use of weak random number generator (use crypto/rand)
105-
- G101 # Potential hardcoded credentials (returns false positives)
106-
- G306 # Expect WriteFile permissions to be 0600 or less
107-
gocritic:
108-
enabled-tags:
109-
- diagnostic
110-
- experimental
111-
- performance
112-
disabled-checks:
113-
- appendAssign
114-
- dupImport # https://github.com/go-critic/go-critic/issues/845
115-
- evalOrder
116-
- ifElseChain
117-
- octalLiteral
118-
- regexpSimplify
119-
- sloppyReassign
120-
- truncateCmp
121-
- typeDefFirst
122-
- unnamedResult
123-
- unnecessaryDefer
124-
- whyNoLint
125-
- wrapperFunc
126-
- unnecessaryBlock
127-
- rangeValCopy
128-
- hugeParam
129-
- commentedOutCode
130-
# TODO(vincepri): potentially enable the following?
131-
- emptyStringTest
132-
- singleCaseSwitch
133-
- nestingReduce
134-
- filepathJoin
135-
- tooManyResultsChecker
136-
116+
exclusions:
117+
generated: lax
118+
presets:
119+
- comments
120+
- common-false-positives
121+
- legacy
122+
- std-error-handling
123+
rules:
124+
- linters:
125+
- unparam
126+
text: always receives
127+
- linters:
128+
- gosec
129+
path: _test\.go
130+
text: 'G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server'
131+
- linters:
132+
- gosec
133+
path: test/e2e/*
134+
- linters:
135+
- goconst
136+
path: (.+)_test\.go
137+
- linters:
138+
- staticcheck
139+
text: QF1008
140+
paths:
141+
- third_party$
142+
- builtin$
143+
- examples$
137144
issues:
138-
max-same-issues: 0
139145
max-issues-per-linter: 0
140-
exclude-rules:
141-
- linters:
142-
- unparam
143-
text: always receives
144-
- linters:
145-
- gosec
146-
path: _test\.go
147-
text: "G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server"
148-
- linters:
149-
- gosec
150-
path: test/e2e/*
146+
max-same-issues: 0
147+
formatters:
148+
enable:
149+
- gci
150+
- gofmt
151+
settings:
152+
gci:
153+
sections:
154+
- standard
155+
- default
156+
- prefix(k8s.io)
157+
- prefix(github.com/kcp-dev)
158+
- prefix(github.com/kcp-dev/kcp)
159+
- blank
160+
- dot
161+
custom-order: true
162+
exclusions:
163+
generated: disable
164+
paths:
165+
- third_party$
166+
- builtin$
167+
- examples$

Makefile

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ YAML_PATCH_BIN := yaml-patch
5050
YAML_PATCH := $(TOOLS_DIR)/$(YAML_PATCH_BIN)-$(YAML_PATCH_VER)
5151
export YAML_PATCH # so hack scripts can use it
5252

53-
GOLANGCI_LINT_VER := v1.62.2
53+
GOLANGCI_LINT_VER := v2.1.6
5454
GOLANGCI_LINT_BIN := golangci-lint
5555
GOLANGCI_LINT := $(TOOLS_GOBIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER)
56+
GOLANGCI_LINT_FLAGS ?=
5657

5758
HTTEST_VER := v0.3.2
5859
HTTEST_BIN := httest
@@ -128,7 +129,7 @@ install: require-jq require-go require-git verify-go-versions ## Install the pro
128129
.PHONY: install
129130

130131
$(GOLANGCI_LINT):
131-
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
132+
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/v2/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
132133

133134
$(HTTEST):
134135
GOBIN=$(TOOLS_GOBIN_DIR) $(GO_INSTALL) go.xrstf.de/httest $(HTTEST_BIN) $(HTTEST_VER)
@@ -140,10 +141,21 @@ $(KCP_APIGEN_GEN):
140141
pushd . && cd sdk && GOBIN=$(TOOLS_GOBIN_DIR) go install ./cmd/apigen && popd
141142

142143
lint: $(GOLANGCI_LINT) $(LOGCHECK) ## Verify lint
143-
$(GOLANGCI_LINT) run --timeout 20m ./...
144+
echo "Linting root module..."; \
145+
$(GOLANGCI_LINT) run $(GOLANGCI_LINT_FLAGS) -c $(ROOT_DIR)/.golangci.yaml --timeout 20m
146+
for MOD in $$(git ls-files '**/go.mod' | sed 's,/go.mod,,'); do \
147+
if [ "$$MOD" != "." ]; then \
148+
echo "Linting $$MOD module..."; \
149+
(cd $$MOD && $(GOLANGCI_LINT) run $(GOLANGCI_LINT_FLAGS) -c $(ROOT_DIR)/.golangci.yaml --timeout 20m); \
150+
fi; \
151+
done
144152
./hack/verify-contextual-logging.sh
145153
.PHONY: lint
146154

155+
fix-lint: $(GOLANGCI_LINT)
156+
GOLANGCI_LINT_FLAGS="--fix" $(MAKE) lint
157+
.PHONY: fix-lint
158+
147159
update-contextual-logging: $(LOGCHECK) ## Update contextual logging
148160
UPDATE=true ./hack/verify-contextual-logging.sh
149161
.PHONY: update-contextual-logging
@@ -198,7 +210,7 @@ crds: $(CONTROLLER_GEN) $(YAML_PATCH) ## Generate crds
198210
./hack/update-codegen-crds.sh
199211
.PHONY: crds
200212

201-
codegen: $(KCP_APIGEN_GEN) crds ## Generate all
213+
codegen: $(KCP_APIGEN_GEN) crds ## Generate all
202214
go mod download
203215
./hack/update-codegen-clients.sh
204216
./hack/gen-patch-defaultrestmapper.sh
@@ -228,10 +240,10 @@ verify-codegen: ## Verify codegen
228240
imports: WHAT ?=
229241
imports: $(GOLANGCI_LINT) verify-go-versions
230242
if [ -n "$(WHAT)" ]; then \
231-
$(GOLANGCI_LINT) run --enable-only=gci --fix --exclude-generated disable $(WHAT); \
243+
$(GOLANGCI_LINT) fmt --enable gci -c $(ROOT_DIR)/.golangci.yaml $(WHAT); \
232244
else \
233245
for MOD in . $$(git ls-files '**/go.mod' | sed 's,/go.mod,,'); do \
234-
(set -x; cd $$MOD; $(GOLANGCI_LINT) run --enable-only=gci --fix --exclude-generated disable); \
246+
(set -x; cd $$MOD; $(GOLANGCI_LINT) fmt --enable gci -c $(ROOT_DIR)/.golangci.yaml); \
235247
done; \
236248
fi
237249

cli/cmd/kubectl-create-workspace/cmd/kubectlCreateWorkspace.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ func KubectlCreateWorkspaceCommand() *cobra.Command {
4141
klog.InitFlags(fs)
4242
createWorkspaceCommand.PersistentFlags().AddGoFlagSet(fs)
4343
return createWorkspaceCommand
44-
4544
}

cli/cmd/kubectl-ws/cmd/kubectlWs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@ func KubectlWsCommand() *cobra.Command {
4141
klog.InitFlags(fs)
4242
wsCommand.PersistentFlags().AddGoFlagSet(fs)
4343
return wsCommand
44-
4544
}

cli/pkg/workspace/plugin/context_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ func TestCreateContext(t *testing.T) {
196196
},
197197
}
198198
for _, tt := range tests {
199-
tt := tt
200-
201199
t.Run(tt.name, func(t *testing.T) {
202200
var got *clientcmdapi.Config
203201

0 commit comments

Comments
 (0)