Skip to content

Commit 577ba30

Browse files
committed
update golangci lint v2
Signed-off-by: dongjiang <[email protected]>
1 parent 15cd7ff commit 577ba30

File tree

8 files changed

+103
-94
lines changed

8 files changed

+103
-94
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ jobs:
3131
with:
3232
go-version: ${{ steps.vars.outputs.go_version }}
3333
- name: golangci-lint
34-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # tag=v6.5.2
34+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # tag=v7.0.0
3535
with:
36-
version: v1.64.6
37-
args: --out-format=colored-line-number
36+
version: v2.0.2
37+
args: --output.text.print-linter-name=true --output.text.colors=true
3838
working-directory: ${{matrix.working-directory}}

.golangci.yml

Lines changed: 86 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1+
version: "2"
12
run:
2-
allow-parallel-runners: true
3-
modules-download-mode: readonly
4-
# Increase the default deadline from 1m as some module operations can take a
5-
# while if uncached!
6-
timeout: 10m
73
go: "1.24"
8-
4+
modules-download-mode: readonly
5+
allow-parallel-runners: true
96
linters:
107
# sync from https://github.com/kubernetes-sigs/controller-runtime/blob/main/.golangci.yml
11-
disable-all: true
8+
default: none
129
enable:
1310
- asasalint
1411
- asciicheck
@@ -25,10 +22,7 @@ linters:
2522
- goconst
2623
- gocritic
2724
- gocyclo
28-
- gofmt
29-
- goimports
3025
- goprintffuncname
31-
- gosimple
3226
- govet
3327
- importas
3428
- ineffassign
@@ -40,74 +34,91 @@ linters:
4034
- prealloc
4135
- revive
4236
- staticcheck
43-
- stylecheck
4437
- tagliatelle
45-
- typecheck
4638
- unconvert
4739
- unparam
4840
- unused
4941
- whitespace
50-
51-
issues:
52-
exclude-rules:
53-
# Dot imports for gomega and ginkgo are allowed
54-
# within test files.
55-
- path: _test\.go
56-
text: should not use dot imports
57-
# Ignore error type switch case
58-
- path: "pkg/loader/loader.go"
59-
linters:
60-
- errorlint
61-
# Ignore test files
62-
- linters:
63-
- dupl
64-
- ginkgolinter
65-
path: _test\.go
66-
- linters:
67-
- gocritic
68-
path: "pkg/markers/help.go"
69-
- linters:
70-
- exhaustive
71-
path: "pkg/markers/parse.go|pkg/deepcopy/traverse.go|pkg/genall/help/types.go|pkg/crd/schema.go|pkg/crd/flatten.go"
72-
# Ignore consider pre-allocating variables
73-
- linters:
74-
- prealloc
75-
text: Consider pre-allocating
76-
linters-settings:
77-
govet:
78-
enable-all: true
79-
disable:
80-
- fieldalignment
81-
- shadow
82-
importas:
83-
no-unaliased: true
84-
revive:
85-
# By default, revive will enable only the linting rules that are named in the configuration file.
86-
# So, it's needed to explicitly enable all required rules here.
42+
settings:
43+
govet:
44+
disable:
45+
- fieldalignment
46+
- shadow
47+
enable-all: true
48+
importas:
49+
no-unaliased: true
50+
revive:
51+
# By default, revive will enable only the linting rules that are named in the configuration file.
52+
# So, it's needed to explicitly enable all required rules here.
53+
rules:
54+
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
55+
- name: blank-imports
56+
- name: context-as-argument
57+
- name: context-keys-type
58+
- name: dot-imports
59+
- name: error-return
60+
- name: error-strings
61+
- name: error-naming
62+
- name: if-return
63+
- name: increment-decrement
64+
- name: var-naming
65+
- name: var-declaration
66+
- name: range
67+
- name: receiver-naming
68+
- name: time-naming
69+
- name: unexported-return
70+
- name: indent-error-flow
71+
- name: errorf
72+
- name: superfluous-else
73+
- name: unreachable-code
74+
- name: redefines-builtin-id
75+
#
76+
# Rules in addition to the recommended configuration above.
77+
#
78+
- name: bool-literal-in-expr
79+
- name: constant-logical-expr
80+
exclusions:
81+
generated: lax
82+
presets:
83+
- comments
84+
- common-false-positives
85+
- legacy
86+
- std-error-handling
8787
rules:
88-
# The following rules are recommended https://github.com/mgechev/revive#recommended-configuration
89-
- name: blank-imports
90-
- name: context-as-argument
91-
- name: context-keys-type
92-
- name: dot-imports
93-
- name: error-return
94-
- name: error-strings
95-
- name: error-naming
96-
- name: if-return
97-
- name: increment-decrement
98-
- name: var-naming
99-
- name: var-declaration
100-
- name: range
101-
- name: receiver-naming
102-
- name: time-naming
103-
- name: unexported-return
104-
- name: indent-error-flow
105-
- name: errorf
106-
- name: superfluous-else
107-
- name: unreachable-code
108-
- name: redefines-builtin-id
109-
#
110-
# Rules in addition to the recommended configuration above.
111-
#
112-
- name: bool-literal-in-expr
113-
- name: constant-logical-expr
88+
# Dot imports for gomega and ginkgo are allowed
89+
# within test files.
90+
- path: _test\.go
91+
text: should not use dot imports
92+
# Ignore error type switch case
93+
- linters:
94+
- errorlint
95+
path: pkg/loader/loader.go
96+
# Ignore test files
97+
- linters:
98+
- dupl
99+
- ginkgolinter
100+
path: _test\.go
101+
- linters:
102+
- gocritic
103+
path: pkg/markers/help.go
104+
- linters:
105+
- exhaustive
106+
path: pkg/markers/parse.go|pkg/deepcopy/traverse.go|pkg/genall/help/types.go|pkg/crd/schema.go|pkg/crd/flatten.go
107+
# Ignore consider pre-allocating variables
108+
- linters:
109+
- prealloc
110+
text: Consider pre-allocating
111+
paths:
112+
- third_party$
113+
- builtin$
114+
- examples$
115+
formatters:
116+
enable:
117+
- gofmt
118+
- goimports
119+
exclusions:
120+
generated: lax
121+
paths:
122+
- third_party$
123+
- builtin$
124+
- examples$

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ GO_INSTALL := ./hack/go-install.sh
6363
GOLANGCI_LINT_BIN := golangci-lint
6464
GOLANGCI_LINT_VER := $(shell cat .github/workflows/golangci-lint.yml | grep [[:space:]]version: | sed 's/.*version: //')
6565
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
66-
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
66+
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
6767

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

pkg/applyconfiguration/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (ctx *ObjectGenCtx) generateForPackage(root *loader.Package) error {
183183
outpkg := outputPkg(ctx.Collector, root)
184184

185185
arguments.OutputDir = filepath.Join(root.Dir, outpkg)
186-
arguments.OutputPkg = filepath.Join(root.Package.PkgPath, outpkg)
186+
arguments.OutputPkg = filepath.Join(root.PkgPath, outpkg)
187187

188188
// The following code is based on gengo/v2.Execute.
189189
// We have lifted it from there so that we can adjust the markers on the types to make sure

pkg/crd/gen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,10 @@ func FixTopLevelMetadata(crd apiext.CustomResourceDefinition) {
244244
// addAttribution adds attribution info to indicate controller-gen tool was used
245245
// to generate this CRD definition along with the version info.
246246
func addAttribution(crd *apiext.CustomResourceDefinition) {
247-
if crd.ObjectMeta.Annotations == nil {
248-
crd.ObjectMeta.Annotations = map[string]string{}
247+
if crd.Annotations == nil {
248+
crd.Annotations = map[string]string{}
249249
}
250-
crd.ObjectMeta.Annotations["controller-gen.kubebuilder.io/version"] = version.Version()
250+
crd.Annotations["controller-gen.kubebuilder.io/version"] = version.Version()
251251
}
252252

253253
// FindMetav1 locates the actual package representing metav1 amongst

pkg/markers/collect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (c *Collector) parseMarkersInPackage(nodeMarkersRaw map[ast.Node][]markerCo
112112
markerVals := make(map[string][]interface{})
113113
for _, markerRaw := range markersRaw {
114114
markerText := markerRaw.Text()
115-
def := c.Registry.Lookup(markerText, target)
115+
def := c.Lookup(markerText, target)
116116
if def == nil {
117117
continue
118118
}
@@ -173,14 +173,14 @@ func (c *Collector) associateFileMarkers(file *ast.File) map[ast.Node][]markerCo
173173
continue
174174
}
175175
markerText := marker.Text()
176-
typeDef := c.Registry.Lookup(markerText, DescribesType)
176+
typeDef := c.Lookup(markerText, DescribesType)
177177
if typeDef != nil {
178178
// prefer assuming type-level markers
179179
markers[endOfMarkers] = marker
180180
endOfMarkers++
181181
continue
182182
}
183-
def := c.Registry.Lookup(markerText, DescribesPackage)
183+
def := c.Lookup(markerText, DescribesPackage)
184184
if def == nil {
185185
// assume type-level unless proven otherwise
186186
markers[endOfMarkers] = marker

pkg/markers/parse.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,12 @@ func (a *Argument) parseString(scanner *sc.Scanner, raw string, out reflect.Valu
401401
// the "hard" case -- bare tokens not including ',' (the argument
402402
// separator), ';' (the slice separator), ':' (the map separator), or '}'
403403
// (delimitted slice ender)
404-
startPos := scanner.Position.Offset
404+
startPos := scanner.Offset
405405
for hint := peekNoSpace(scanner); hint != ',' && hint != ';' && hint != ':' && hint != '}' && hint != sc.EOF; hint = peekNoSpace(scanner) {
406406
// skip this token
407407
scanner.Scan()
408408
}
409-
endPos := scanner.Position.Offset + len(scanner.TokenText())
409+
endPos := scanner.Offset + len(scanner.TokenText())
410410
castAndSet(out, reflect.ValueOf(raw[startPos:endPos]))
411411
}
412412

@@ -868,11 +868,9 @@ func (d *Definition) Parse(rawMarker string) (interface{}, error) {
868868
seen[""] = struct{}{} // mark as seen for strict definitions
869869
} else if !d.Empty() && scanner.Peek() != sc.EOF {
870870
// if we expect *and* actually have arguments passed
871-
for {
871+
for expect(scanner, sc.Ident, "argument name") {
872872
// parse the argument name
873-
if !expect(scanner, sc.Ident, "argument name") {
874-
break
875-
}
873+
876874
argName := scanner.TokenText()
877875
if !expect(scanner, '=', "equals") {
878876
break
@@ -913,7 +911,7 @@ func (d *Definition) Parse(rawMarker string) (interface{}, error) {
913911
}
914912

915913
if tok := scanner.Scan(); tok != sc.EOF {
916-
scanner.Error(scanner, fmt.Sprintf("extra arguments provided: %q", fields[scanner.Position.Offset:]))
914+
scanner.Error(scanner, fmt.Sprintf("extra arguments provided: %q", fields[scanner.Offset:]))
917915
}
918916

919917
if d.Strict {

pkg/schemapatcher/gen.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (g Generator) Generate(ctx *genall.GenerationContext) (result error) {
190190
// with them against older servers.
191191
for _, crd := range set.CRDVersions {
192192
if err := func() error {
193-
outWriter, err := ctx.OutputRule.Open(nil, crd.FileName)
193+
outWriter, err := ctx.Open(nil, crd.FileName)
194194
if err != nil {
195195
return err
196196
}

0 commit comments

Comments
 (0)