Skip to content

Commit 6c69d61

Browse files
committed
update golangci-lint to v2
Signed-off-by: dongjiang <[email protected]>
1 parent 7606727 commit 6c69d61

File tree

27 files changed

+213
-214
lines changed

27 files changed

+213
-214
lines changed

.github/workflows/golangci-lint.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ jobs:
3232
with:
3333
go-version: ${{ steps.vars.outputs.go_version }}
3434
- name: golangci-lint
35-
uses: golangci/golangci-lint-action@4696ba8babb6127d732c3c6dde519db15edab9ea # tag=v6.5.1
35+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # tag=v7.0.0
3636
with:
37-
version: v1.64.6
38-
args: --out-format=colored-line-number
37+
version: v2.0.2
38+
args: --output.text.print-linter-name=true --output.text.colors=true
3939
working-directory: ${{matrix.working-directory}}

.golangci.yml

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

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ $(CONTROLLER_GEN): # Build controller-gen from tools folder.
9999
GOLANGCI_LINT_BIN := golangci-lint
100100
GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //')
101101
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
102-
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
102+
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
103103

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

examples/builtins/controller.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222

2323
appsv1 "k8s.io/api/apps/v1"
24-
"k8s.io/apimachinery/pkg/api/errors"
24+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
2626
"sigs.k8s.io/controller-runtime/pkg/log"
2727
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -43,13 +43,13 @@ func (r *reconcileReplicaSet) Reconcile(ctx context.Context, request reconcile.R
4343
// Fetch the ReplicaSet from the cache
4444
rs := &appsv1.ReplicaSet{}
4545
err := r.client.Get(ctx, request.NamespacedName, rs)
46-
if errors.IsNotFound(err) {
46+
if apierrors.IsNotFound(err) {
4747
log.Error(nil, "Could not find ReplicaSet")
4848
return reconcile.Result{}, nil
4949
}
5050

5151
if err != nil {
52-
return reconcile.Result{}, fmt.Errorf("could not fetch ReplicaSet: %+v", err)
52+
return reconcile.Result{}, fmt.Errorf("could not fetch ReplicaSet: %+w", err)
5353
}
5454

5555
// Print the ReplicaSet
@@ -67,7 +67,7 @@ func (r *reconcileReplicaSet) Reconcile(ctx context.Context, request reconcile.R
6767
rs.Labels["hello"] = "world"
6868
err = r.client.Update(ctx, rs)
6969
if err != nil {
70-
return reconcile.Result{}, fmt.Errorf("could not write ReplicaSet: %+v", err)
70+
return reconcile.Result{}, fmt.Errorf("could not write ReplicaSet: %+w", err)
7171
}
7272

7373
return reconcile.Result{}, nil

examples/crd/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (r *reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
6565
if podFound {
6666
shouldStop := chaospod.Spec.NextStop.Time.Before(time.Now())
6767
if !shouldStop {
68-
return ctrl.Result{RequeueAfter: chaospod.Spec.NextStop.Sub(time.Now()) + 1*time.Second}, nil
68+
return ctrl.Result{RequeueAfter: time.Until(chaospod.Spec.NextStop.Time) + 1*time.Second}, nil
6969
}
7070

7171
if err := r.Delete(ctx, &pod); err != nil {

examples/crd/pkg/groupversion_info.go

-3
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ package pkg
2020

2121
import (
2222
"k8s.io/apimachinery/pkg/runtime/schema"
23-
logf "sigs.k8s.io/controller-runtime/pkg/log"
2423
"sigs.k8s.io/controller-runtime/pkg/scheme"
2524
)
2625

2726
var (
28-
log = logf.Log.WithName("chaospod-resource")
29-
3027
// SchemeGroupVersion is group version used to register these objects
3128
SchemeGroupVersion = schema.GroupVersion{Group: "chaosapps.metamagical.io", Version: "v1"}
3229

0 commit comments

Comments
 (0)