Skip to content

Commit 532ffdb

Browse files
authored
Merge pull request #20620 from ivanvc/bump-golangci-lint-to-v2
Bump golangci lint to v2
2 parents d46722b + c2a53f7 commit 532ffdb

File tree

7 files changed

+399
-345
lines changed

7 files changed

+399
-345
lines changed

scripts/test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,11 @@ function govet_shadow_pass {
447447
}
448448

449449
function lint_pass {
450-
run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml"
450+
run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml" --show-stats=false
451451
}
452452

453453
function lint_fix_pass {
454-
run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml" --fix
454+
run_for_modules generic_checker run golangci-lint run --config "${ETCD_ROOT_DIR}/tools/.golangci.yaml" --fix --show-stats=false
455455
}
456456

457457
function license_header_per_module {

scripts/verify_golangci-lint_version.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function install_golangci_lint() {
1818
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b "${GOPATH}/bin" "${GOLANGCI_LINT_VERSION}"
1919
}
2020

21-
GOLANGCI_LINT_VERSION=$(cd tools/mod && go list -m -f '{{.Version}}' github.com/golangci/golangci-lint)
21+
GOLANGCI_LINT_VERSION=$(cd tools/mod && go list -m -f '{{.Version}}' github.com/golangci/golangci-lint/v2)
2222
echo "golangci-lint version: $GOLANGCI_LINT_VERSION"
2323
GOLANGCI_LINT_PRESENT=$(which golangci-lint)
2424

tests/common/hashkv_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestVerifyHashKVAfterCompactAndDefrag(t *testing.T) {
183183
after, err := cc.HashKV(ctx, compactOnRev)
184184
require.NoError(t, err)
185185

186-
require.Equal(t, len(before), len(after))
186+
require.Len(t, before, len(after))
187187
for i := range before {
188188
assert.Equal(t, before[i].Hash, after[i].Hash)
189189
}

tools/.golangci.yaml

Lines changed: 132 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,13 @@
11
---
2-
run:
3-
timeout: 30m
4-
formatters:
5-
enable:
6-
- gci
7-
settings: # please keep this alphabetized
8-
gci:
9-
sections:
10-
- standard
11-
- default
12-
- prefix(go.etcd.io)
13-
issues:
14-
max-same-issues: 0
15-
# Excluding configuration per-path, per-linter, per-text and per-source
16-
exclude-rules:
17-
# exclude ineffassing linter for generated files for conversion
18-
- path: conversion\.go
19-
linters: [ineffassign]
20-
- text: "S1000" # TODO: Fix me
21-
linters:
22-
- gosimple
23-
exclude-files:
24-
- ^zz_generated.*
2+
version: "2"
253
linters:
26-
disable-all: true
4+
default: none
275
enable: # please keep this alphabetized
28-
# Don't use soon to deprecated[1] linters that lead to false
29-
# https://github.com/golangci/golangci-lint/issues/1841
30-
# - deadcode
31-
# - structcheck
32-
# - varcheck
336
- errorlint
34-
- gofumpt
35-
- goimports
36-
- gosimple
377
- ineffassign
388
- nakedret
399
- revive
4010
- staticcheck
41-
- stylecheck
4211
- testifylint
4312
- thelper
4413
- unconvert # Remove unnecessary type conversions
@@ -47,82 +16,134 @@ linters:
4716
- usestdlibvars
4817
- usetesting
4918
- whitespace
50-
linters-settings: # please keep this alphabetized
51-
goimports:
52-
local-prefixes: go.etcd.io # Put imports beginning with prefix after 3rd-party packages.
53-
nakedret:
54-
# Align with https://github.com/alexkohler/nakedret/blob/v1.0.2/cmd/nakedret/main.go#L10
55-
max-func-lines: 5
56-
revive:
57-
confidence: 0.8
19+
settings:
20+
nakedret:
21+
# Align with https://github.com/alexkohler/nakedret/blob/v1.0.2/cmd/nakedret/main.go#L10
22+
max-func-lines: 5
23+
revive:
24+
confidence: 0.8
25+
rules:
26+
- name: blank-imports
27+
- name: context-as-argument
28+
- name: context-keys-type
29+
- name: dot-imports
30+
- name: early-return
31+
arguments:
32+
- preserveScope
33+
- name: error-return
34+
- name: error-naming
35+
- name: error-strings
36+
- name: errorf
37+
- name: if-return
38+
- name: increment-decrement
39+
- name: indent-error-flow
40+
- name: package-comments
41+
- name: range
42+
- name: receiver-naming
43+
- name: superfluous-else
44+
arguments:
45+
- preserveScope
46+
- name: time-naming
47+
- name: unnecessary-stmt
48+
- name: use-any
49+
- name: var-declaration
50+
- name: var-naming
51+
arguments:
52+
# The following is the configuration for var-naming rule, the first element is the allow list and the second element is the deny list.
53+
- [] # AllowList: leave it empty to use the default (empty, too). This means that we're not relaxing the rule in any way, i.e. elementId will raise a violation, it should be elementID, refer to the next line to see the list of denied initialisms.
54+
# DenyList: Add GRPC and WAL to strict the rule not allowing instances like Wal or Grpc. The default values are located at commonInitialisms, refer to: https://github.com/mgechev/revive/blob/v1.3.7/lint/utils.go#L93-L133.
55+
- - GRPC
56+
- WAL
57+
- name: exported
58+
disabled: true
59+
- name: unexported-return
60+
disabled: true
61+
staticcheck:
62+
checks:
63+
- all
64+
- -SA1019 # TODO(fix) Using a deprecated function, variable, constant or field
65+
- -SA2002 # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
66+
- -QF1001 # TODO(fix) Apply De Morgan’s law
67+
- -QF1002 # TODO(fix) Convert untagged switch to tagged switch
68+
- -QF1003 # TODO(fix) Convert if/else-if chain to tagged switch
69+
- -QF1004 # TODO(fix) Use strings.ReplaceAll instead of strings.Replace with n == -1
70+
- -QF1006 # TODO(fix) Lift if+break into loop condition
71+
- -QF1008 # TODO(fix) Omit embedded fields from selector expression
72+
- -QF1009 # TODO(fix) Use time.Time.Equal instead of == operator
73+
- -QF1012 # TODO(fix) Use fmt.Fprintf(x, ...) instead of x.Write(fmt.Sprintf(...))
74+
- -ST1003 # TODO(fix) Poorly chosen identifier
75+
- -ST1005 # TODO(fix) Drop unnecessary use of the blank identifier
76+
- ST1019 # Importing the same package multiple times.
77+
testifylint:
78+
enable-all: true
79+
formatter:
80+
# Require f-assertions (e.g. assert.Equalf) if a message is passed to the assertion, even if
81+
# there is no variable-length variables, i.e. require require.NoErrorf for both cases below:
82+
# require.NoErrorf(t, err, "whatever message")
83+
# require.NoErrorf(t, err, "whatever message: %v", v)
84+
#
85+
# Note from golang programming perspective, we still prefer non-f-functions (i.e. fmt.Print)
86+
# to f-functions (i.e. fmt.Printf) when there is no variable-length parameters. It's accepted
87+
# to always require f-functions for stretchr/testify, but not for golang standard lib.
88+
# Also refer to https://github.com/etcd-io/etcd/pull/18741#issuecomment-2422395914
89+
require-f-funcs: true
90+
thelper:
91+
test:
92+
first: false
93+
begin: false
94+
fuzz:
95+
first: false
96+
begin: false
97+
benchmark:
98+
first: false
99+
begin: false
100+
tb:
101+
first: false
102+
begin: false
103+
usetesting:
104+
os-mkdir-temp: false
105+
exclusions:
106+
generated: lax
107+
presets:
108+
- comments
109+
- common-false-positives
110+
- legacy
111+
- std-error-handling
58112
rules:
59-
- name: blank-imports
60-
- name: context-as-argument
61-
- name: context-keys-type
62-
- name: dot-imports
63-
- name: early-return
64-
arguments:
65-
- "preserveScope"
66-
- name: error-return
67-
- name: error-naming
68-
- name: error-strings
69-
- name: errorf
70-
- name: if-return
71-
- name: increment-decrement
72-
- name: indent-error-flow
73-
- name: package-comments
74-
- name: range
75-
- name: receiver-naming
76-
- name: superfluous-else
77-
arguments:
78-
- "preserveScope"
79-
- name: time-naming
80-
- name: unnecessary-stmt
81-
- name: use-any
82-
- name: var-declaration
83-
- name: var-naming
84-
arguments:
85-
# The following is the configuration for var-naming rule, the first element is the allow list and the second element is the deny list.
86-
- [] # AllowList: leave it empty to use the default (empty, too). This means that we're not relaxing the rule in any way, i.e. elementId will raise a violation, it should be elementID, refer to the next line to see the list of denied initialisms.
87-
- ["GRPC", "WAL"] # DenyList: Add GRPC and WAL to strict the rule not allowing instances like Wal or Grpc. The default values are located at commonInitialisms, refer to: https://github.com/mgechev/revive/blob/v1.3.7/lint/utils.go#L93-L133.
88-
# TODO: enable the following rules
89-
- name: exported
90-
disabled: true
91-
- name: unexported-return
92-
disabled: true
93-
staticcheck:
94-
checks:
95-
- all
96-
- -SA1019 # TODO(fix) Using a deprecated function, variable, constant or field
97-
- -SA2002 # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed
98-
stylecheck:
99-
checks:
100-
- ST1019 # Importing the same package multiple times.
101-
testifylint:
102-
enable-all: true
103-
formatter:
104-
# Require f-assertions (e.g. assert.Equalf) if a message is passed to the assertion, even if
105-
# there is no variable-length variables, i.e. require require.NoErrorf for both cases below:
106-
# require.NoErrorf(t, err, "whatever message")
107-
# require.NoErrorf(t, err, "whatever message: %v", v)
108-
#
109-
# Note from golang programming perspective, we still prefer non-f-functions (i.e. fmt.Print)
110-
# to f-functions (i.e. fmt.Printf) when there is no variable-length parameters. It's accepted
111-
# to always require f-functions for stretchr/testify, but not for golang standard lib.
112-
# Also refer to https://github.com/etcd-io/etcd/pull/18741#issuecomment-2422395914
113-
require-f-funcs: true
114-
thelper:
115-
test:
116-
first: false
117-
begin: false
118-
benchmark:
119-
first: false
120-
begin: false
121-
tb:
122-
first: false
123-
begin: false
124-
fuzz:
125-
first: false
126-
begin: false
127-
usetesting:
128-
os-mkdir-temp: false
113+
- linters:
114+
- ineffassign
115+
path: conversion\.go
116+
- linters:
117+
- staticcheck
118+
text: S1000
119+
- linters:
120+
- revive
121+
text: 'var-naming: avoid meaningless package names'
122+
paths:
123+
- ^zz_generated.*
124+
- third_party$
125+
- builtin$
126+
- examples$
127+
issues:
128+
max-same-issues: 0
129+
formatters:
130+
enable:
131+
- gci
132+
- gofmt
133+
- goimports
134+
settings: # please keep this alphabetized
135+
gci:
136+
sections:
137+
- standard
138+
- default
139+
- prefix(go.etcd.io)
140+
goimports:
141+
local-prefixes:
142+
- go.etcd.io # Put imports beginning with prefix after 3rd-party packages.
143+
exclusions:
144+
generated: lax
145+
paths:
146+
- ^zz_generated.*
147+
- third_party$
148+
- builtin$
149+
- examples$

0 commit comments

Comments
 (0)