Skip to content

Commit 9c38211

Browse files
committed
update golangci-lint to v2
Signed-off-by: dongjiang <dongjiang1989@126.com>
1 parent 7606727 commit 9c38211

File tree

11 files changed

+163
-165
lines changed

11 files changed

+163
-165
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
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@4afd733a84b1f43292c63897423277bb7f4313a9 # tag=v8.0.0
3636
with:
37-
version: v1.64.6
38-
args: --out-format=colored-line-number
37+
version: v2.1.6
38+
args: --output.text.print-linter-name=true --output.text.colors=true --timeout 10m
3939
working-directory: ${{matrix.working-directory}}

.golangci.yml

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

Makefile

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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)