Skip to content

Commit fcd9f89

Browse files
committed
bump golangci-lint to v2
1 parent 4d32b9d commit fcd9f89

File tree

6 files changed

+98
-137
lines changed

6 files changed

+98
-137
lines changed

.github/workflows/ci-pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
uses: golangci/golangci-lint-action@v6
2222
with:
2323
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
24-
version: v1.64.8
24+
version: v2.4.0
2525
args: --timeout 10m
2626
go-unit-test:
2727
runs-on: ubuntu-latest

.github/workflows/ci-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ jobs:
1818
if: github.event_name == 'pull_request'
1919
uses: golangci/golangci-lint-action@v6
2020
with:
21-
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
22-
version: v1.57.2
21+
version: v2.4.0
22+
args: --timeout 10m
2323
go-unit-test:
2424
runs-on: ubuntu-latest
2525
needs: [style-check]

.golangci.yaml

Lines changed: 88 additions & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,92 @@
1-
# WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY
2-
#
3-
# The original version of this file is located in the https://github.com/istio/common-files repo.
4-
# If you're looking at this file in a different repo and want to make a change, please go to the
5-
# common-files repo, make the change there and check it in. Then come back to this repo and run
6-
# "make update-common".
1+
version: "2"
72
run:
83
build-tags:
9-
- integ
10-
- integfuzz
11-
12-
4+
- integ
5+
- integfuzz
136
linters:
14-
disable-all: true
7+
default: none
158
enable:
16-
- errcheck
17-
- gocritic
18-
- gofumpt
19-
- goimports
20-
- gosimple
21-
- govet
22-
- ineffassign
23-
- lll
24-
- misspell
25-
- staticcheck
26-
- stylecheck
27-
- typecheck
28-
- unconvert
29-
- unparam
30-
fast: false
31-
32-
linters-settings:
33-
errcheck:
34-
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
35-
# default is false: such cases aren't reported by default.
36-
check-type-assertions: false
37-
38-
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
39-
# default is false: such cases aren't reported by default.
40-
check-blank: false
41-
goimports:
42-
# put imports beginning with prefix after 3rd-party packages;
43-
# it's a comma-separated list of prefixes
44-
local-prefixes: github.com/baizeai/kube-snapshot
45-
misspell:
46-
# Correct spellings using locale preferences for US or UK.
47-
# Default is to use a neutral variety of English.
48-
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
49-
locale: US
50-
ignore-words:
51-
- cancelled
52-
lll:
53-
# max line length, lines longer will be reported. Default is 120.
54-
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
55-
line-length: 160
56-
# tab width in spaces. Default to 1.
57-
tab-width: 1
58-
gocritic:
59-
enabled-checks:
60-
- appendCombine
61-
- boolExprSimplify
62-
- builtinShadow
63-
- commentedOutCode
64-
- commentedOutImport
65-
- docStub
66-
- emptyFallthrough
67-
- equalFold
68-
- hexLiteral
69-
- indexAlloc
70-
- initClause
71-
- methodExprCall
72-
- nilValReturn
73-
- octalLiteral
74-
- rangeExprCopy
75-
- stringXbytes
76-
- typeAssertChain
77-
- typeUnparen
78-
- unnecessaryBlock
79-
- weakCond
80-
81-
# Unused
82-
# - yodaStyleExpr
83-
# - appendAssign
84-
# - commentFormatting
85-
# - emptyStringTest
86-
# - exitAfterDefer
87-
# - ifElseChain
88-
# - hugeParam
89-
# - importShadow
90-
# - nestingReduce
91-
# - paramTypeCombine
92-
# - ptrToRefParam
93-
# - rangeValCopy
94-
# - singleCaseSwitch
95-
# - sloppyReassign
96-
# - unlabelStmt
97-
# - unnamedResult
98-
# - wrapperFunc
99-
100-
issues:
101-
# List of regexps of issue texts to exclude, empty list by default.
102-
# But independently from this option we use default exclude patterns,
103-
# it can be disabled by `exclude-use-default: false`. To list all
104-
# excluded by default patterns execute `golangci-lint run --help`
105-
exclude:
106-
- composite literal uses unkeyed fields
107-
108-
exclude-files:
109-
- ".*\\.pb\\.go"
110-
- ".*\\.gen\\.go"
111-
112-
exclude-dirs:
113-
- vendor$
114-
- genfiles$
115-
116-
exclude-rules:
117-
# Exclude some linters from running on test files.
118-
- path: _test\.go$|^tests/|^samples/
119-
linters:
120-
- errcheck
121-
122-
# TODO(https://github.com/dominikh/go-tools/issues/732) remove this once we update
123-
- linters:
124-
- staticcheck
125-
text: "SA1019: package github.com/golang/protobuf"
126-
127-
# Independently from option `exclude` we use default exclude patterns,
128-
# it can be disabled by this option. To list all
129-
# excluded by default patterns execute `golangci-lint run --help`.
130-
# Default value for this option is true.
131-
exclude-use-default: true
9+
- errcheck
10+
- gocritic
11+
- govet
12+
- ineffassign
13+
- lll
14+
- misspell
15+
- staticcheck
16+
- unconvert
17+
- unparam
18+
settings:
19+
errcheck:
20+
check-type-assertions: false
21+
check-blank: false
22+
gocritic:
23+
enabled-checks:
24+
- appendCombine
25+
- boolExprSimplify
26+
- builtinShadow
27+
- commentedOutCode
28+
- commentedOutImport
29+
- docStub
30+
- emptyFallthrough
31+
- equalFold
32+
- hexLiteral
33+
- indexAlloc
34+
- initClause
35+
- methodExprCall
36+
- nilValReturn
37+
- octalLiteral
38+
- rangeExprCopy
39+
- stringXbytes
40+
- typeAssertChain
41+
- typeUnparen
42+
- unnecessaryBlock
43+
- weakCond
44+
lll:
45+
line-length: 160
46+
tab-width: 1
47+
misspell:
48+
locale: US
49+
ignore-rules:
50+
- cancelled
51+
exclusions:
52+
generated: lax
53+
presets:
54+
- comments
55+
- common-false-positives
56+
- legacy
57+
- std-error-handling
58+
rules:
59+
- linters:
60+
- errcheck
61+
path: _test\.go$|^tests/|^samples/
62+
- linters:
63+
- staticcheck
64+
text: 'SA1019: package github.com/golang/protobuf'
65+
- path: (.+)\.go$
66+
text: composite literal uses unkeyed fields
67+
paths:
68+
- .*\.pb\.go
69+
- .*\.gen\.go
70+
- vendor$
71+
- genfiles$
72+
- third_party$
73+
- builtin$
74+
- examples$
75+
formatters:
76+
enable:
77+
- gofumpt
78+
- goimports
79+
settings:
80+
goimports:
81+
local-prefixes:
82+
- github.com/baizeai/kube-snapshot
83+
exclusions:
84+
generated: lax
85+
paths:
86+
- .*\.pb\.go
87+
- .*\.gen\.go
88+
- vendor$
89+
- genfiles$
90+
- third_party$
91+
- builtin$
92+
- examples$

internal/controller/snapshotpod_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func (r *SnapshotPodReconciler) getPod(ctx context.Context, sp *snapshotpodv1alp
5252
}
5353
if sp.Spec.Target.Name != "" {
5454
pod := corev1.Pod{}
55-
err := r.Client.Get(ctx, client.ObjectKey{
55+
err := r.Get(ctx, client.ObjectKey{
5656
Namespace: sp.Namespace,
5757
Name: sp.Spec.Target.Name,
5858
}, &pod)
5959
return &pod, err
6060
}
6161
if sp.Spec.Target.Selector != nil {
6262
podList := corev1.PodList{}
63-
err := r.Client.List(ctx, &podList, &client.ListOptions{
63+
err := r.List(ctx, &podList, &client.ListOptions{
6464
LabelSelector: labels.SelectorFromSet(sp.Spec.Target.Selector),
6565
Namespace: sp.Namespace,
6666
})
@@ -174,7 +174,7 @@ func (r *SnapshotPodReconciler) reconcileTasks(ctx context.Context, sp *snapshot
174174
},
175175
Status: snapshotpodv1alpha1.SnapshotPodTaskStatus{},
176176
}
177-
err = r.Client.Create(ctx, &spt)
177+
err = r.Create(ctx, &spt)
178178
if err != nil && !errors.IsAlreadyExists(err) {
179179
return err
180180
}
@@ -203,7 +203,7 @@ func (r *SnapshotPodReconciler) reconcileTasksStatus(ctx context.Context, sp *sn
203203
v1alpha1.SnapshotNameLabel: sp.Name,
204204
},
205205
})
206-
err := r.Client.List(ctx, &sptList, &client.ListOptions{
206+
err := r.List(ctx, &sptList, &client.ListOptions{
207207
LabelSelector: selector,
208208
})
209209
if err != nil {
@@ -313,7 +313,7 @@ func renderNewImageName(originImage, format string) (string, error) {
313313
func (r *SnapshotPodReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
314314
logger := log.FromContext(ctx)
315315
sp := snapshotpodv1alpha1.SnapshotPod{}
316-
err := r.Client.Get(ctx, req.NamespacedName, &sp)
316+
err := r.Get(ctx, req.NamespacedName, &sp)
317317
if err != nil {
318318
logger.Error(err, "get instance error")
319319
return ctrl.Result{}, err

internal/controller/snapshotpodtask_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func (r *SnapshotPodTaskReconciler) Reconcile(ctx context.Context, req ctrl.Requ
145145
logger := log.FromContext(ctx)
146146

147147
spt := snapshotpodv1alpha1.SnapshotPodTask{}
148-
err := r.Client.Get(ctx, req.NamespacedName, &spt)
148+
err := r.Get(ctx, req.NamespacedName, &spt)
149149
if err != nil {
150150
if errors.IsNotFound(err) {
151151
return ctrl.Result{}, nil

test/utils/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"os/exec"
2323
"strings"
2424

25-
. "github.com/onsi/ginkgo/v2" //nolint:golint,revive,stylecheck
25+
. "github.com/onsi/ginkgo/v2" // nolint
2626
)
2727

2828
const (

0 commit comments

Comments
 (0)