Skip to content

Commit 91cd21b

Browse files
authored
Update golangci-lint to v2 (#3269)
Migrate and update the linter to v2 and fix some small issues.
1 parent ddb5423 commit 91cd21b

File tree

9 files changed

+102
-86
lines changed

9 files changed

+102
-86
lines changed

Diff for: .github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ jobs:
3737
go-version: stable
3838

3939
- name: Lint Go
40-
uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
40+
uses: golangci/golangci-lint-action@1481404843c368bc19ca9406f87d6e0fc97bdcfd # v7.0.0
4141
with:
4242
working-directory: ${{ matrix.directory }}
43-
version: v1.64.8 # renovate: datasource=github-tags depName=golangci/golangci-lint
43+
version: v2.0.2 # renovate: datasource=github-tags depName=golangci/golangci-lint
4444

4545
njs-lint:
4646
name: NJS Lint

Diff for: .golangci.yml

+85-69
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,6 @@
1-
linters-settings:
2-
ginkgolinter:
3-
forbid-focus-container: true
4-
goimports:
5-
local-prefixes: github.com/nginx/nginx-gateway-fabric
6-
misspell:
7-
locale: US
8-
revive:
9-
ignore-generated-header: true
10-
rules:
11-
- name: blank-imports
12-
- name: constant-logical-expr
13-
- name: context-as-argument
14-
- name: context-keys-type
15-
- name: defer
16-
- name: dot-imports
17-
arguments:
18-
- allowedPackages:
19-
- github.com/onsi/gomega
20-
- github.com/onsi/ginkgo/v2
21-
- name: duplicated-imports
22-
- name: empty-block
23-
- name: error-naming
24-
- name: error-return
25-
- name: error-strings
26-
- name: errorf
27-
- name: exported
28-
- name: import-shadowing
29-
- name: increment-decrement
30-
- name: indent-error-flow
31-
- name: package-comments
32-
- name: range
33-
- name: range-val-address
34-
- name: range-val-in-closure
35-
- name: receiver-naming
36-
- name: redefines-builtin-id
37-
- name: string-of-int
38-
- name: superfluous-else
39-
- name: time-naming
40-
- name: unchecked-type-assertion
41-
- name: unexported-return
42-
- name: unnecessary-stmt
43-
- name: unreachable-code
44-
- name: unused-parameter
45-
- name: var-declaration
46-
- name: var-naming
47-
gocyclo:
48-
min-complexity: 15
49-
govet:
50-
enable:
51-
- fieldalignment
52-
lll:
53-
line-length: 120
54-
dupword:
55-
ignore:
56-
- "test"
57-
stylecheck:
58-
dot-import-whitelist:
59-
- github.com/onsi/gomega
60-
- github.com/onsi/ginkgo/v2
1+
version: "2"
612
linters:
3+
default: none
624
enable:
635
- asasalint
646
- asciicheck
@@ -78,11 +20,7 @@ linters:
7820
- gocritic
7921
- gocyclo
8022
- godot
81-
- gofmt
82-
- gofumpt
83-
- goimports
8423
- gosec
85-
- gosimple
8624
- gosmopolitan
8725
- govet
8826
- ineffassign
@@ -103,20 +41,98 @@ linters:
10341
- revive
10442
- spancheck
10543
- staticcheck
106-
- stylecheck
10744
- tagalign
10845
- thelper
10946
- tparallel
110-
- typecheck
11147
- unconvert
11248
- unparam
11349
- unused
11450
- usestdlibvars
11551
- wastedassign
11652
- whitespace
117-
disable-all: true
53+
settings:
54+
dupword:
55+
ignore:
56+
- test
57+
ginkgolinter:
58+
forbid-focus-container: true
59+
gocyclo:
60+
min-complexity: 15
61+
govet:
62+
enable:
63+
- fieldalignment
64+
lll:
65+
line-length: 120
66+
misspell:
67+
locale: US
68+
revive:
69+
rules:
70+
- name: blank-imports
71+
- name: constant-logical-expr
72+
- name: context-as-argument
73+
- name: context-keys-type
74+
- name: defer
75+
- name: dot-imports
76+
arguments:
77+
- allowedPackages:
78+
- github.com/onsi/gomega
79+
- github.com/onsi/ginkgo/v2
80+
- name: duplicated-imports
81+
- name: empty-block
82+
- name: error-naming
83+
- name: error-return
84+
- name: error-strings
85+
- name: errorf
86+
- name: exported
87+
- name: import-shadowing
88+
- name: increment-decrement
89+
- name: indent-error-flow
90+
- name: package-comments
91+
- name: range
92+
- name: range-val-address
93+
- name: range-val-in-closure
94+
- name: receiver-naming
95+
- name: redefines-builtin-id
96+
- name: string-of-int
97+
- name: superfluous-else
98+
- name: time-naming
99+
- name: unchecked-type-assertion
100+
- name: unexported-return
101+
- name: unnecessary-stmt
102+
- name: unreachable-code
103+
- name: unused-parameter
104+
- name: var-declaration
105+
- name: var-naming
106+
staticcheck:
107+
dot-import-whitelist:
108+
- github.com/onsi/gomega
109+
- github.com/onsi/ginkgo/v2
110+
exclusions:
111+
generated: lax
112+
presets:
113+
- comments
114+
- common-false-positives
115+
- legacy
116+
- std-error-handling
117+
paths:
118+
- third_party$
119+
- builtin$
120+
- examples$
118121
issues:
119122
max-issues-per-linter: 0
120123
max-same-issues: 0
121-
run:
122-
timeout: 3m
124+
formatters:
125+
enable:
126+
- gofmt
127+
- gofumpt
128+
- goimports
129+
settings:
130+
goimports:
131+
local-prefixes:
132+
- github.com/nginx/nginx-gateway-fabric
133+
exclusions:
134+
generated: lax
135+
paths:
136+
- third_party$
137+
- builtin$
138+
- examples$

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ repos:
3939
- javascript
4040

4141
- repo: https://github.com/golangci/golangci-lint
42-
rev: v1.64.8
42+
rev: v2.0.2
4343
hooks:
4444
- id: golangci-lint-full
4545
name: golangci-lint-root

Diff for: Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ GO_LINKER_FLAGS = $(GO_LINKER_FLAGS_OPTIMIZATIONS) $(GO_LINKER_FlAGS_VARS)
2323

2424
# tools versions
2525
# renovate: datasource=github-tags depName=golangci/golangci-lint
26-
GOLANGCI_LINT_VERSION = v1.64.8
26+
GOLANGCI_LINT_VERSION = v2.0.2
2727
# renovate: datasource=docker depName=kindest/node
2828
KIND_K8S_VERSION = v1.32.3
2929
# renovate: datasource=github-tags depName=norwoodj/helm-docs
@@ -192,7 +192,7 @@ vet: ## Run go vet against code
192192

193193
.PHONY: lint
194194
lint: ## Run golangci-lint against code
195-
go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix
195+
go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) run --fix
196196

197197
.PHONY: unit-test
198198
unit-test: ## Run unit tests for the go code

Diff for: internal/mode/provisioner/deployment.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ func prepareDeployment(depYAML []byte, id string, gwNsName types.NamespacedName)
1919
return nil, fmt.Errorf("failed to unmarshal deployment: %w", err)
2020
}
2121

22-
dep.ObjectMeta.Name = id
22+
dep.Name = id
2323
dep.Spec.Selector.MatchLabels["app"] = id
24-
dep.Spec.Template.ObjectMeta.Labels["app"] = id
24+
dep.Spec.Template.Labels["app"] = id
2525

2626
finalArgs := []string{
2727
"--gateway=" + gwNsName.String(),

Diff for: internal/mode/static/state/graph/backend_refs.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ func createBackendRef(
151151
}
152152

153153
ns := sourceNamespace
154-
if ref.BackendRef.Namespace != nil {
154+
if ref.Namespace != nil {
155155
ns = string(*ref.Namespace)
156156
}
157-
svcNsName := types.NamespacedName{Name: string(ref.BackendRef.Name), Namespace: ns}
157+
svcNsName := types.NamespacedName{Name: string(ref.Name), Namespace: ns}
158158
svcIPFamily, svcPort, err := getIPFamilyAndPortFromRef(ref.BackendRef, svcNsName, services, refPath)
159159
if err != nil {
160160
backendRef = BackendRef{
@@ -328,7 +328,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error {
328328
// capitalizing error message to match the rest of the error messages associated with a condition
329329
//nolint: stylecheck
330330
return errors.New(
331-
"Service configured with IPv6 family but NginxProxy is configured with IPv4",
331+
"service configured with IPv6 family but NginxProxy is configured with IPv4",
332332
)
333333
}
334334
}
@@ -337,7 +337,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error {
337337
// capitalizing error message to match the rest of the error messages associated with a condition
338338
//nolint: stylecheck
339339
return errors.New(
340-
"Service configured with IPv4 family but NginxProxy is configured with IPv6",
340+
"service configured with IPv4 family but NginxProxy is configured with IPv6",
341341
)
342342
}
343343
}
@@ -368,7 +368,7 @@ func validateBackendRef(
368368
) (valid bool, cond conditions.Condition) {
369369
// Because all errors cause same condition but different reasons, we return as soon as we find an error
370370

371-
if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") {
371+
if ref.Group != nil && (*ref.Group != "core" && *ref.Group != "") {
372372
valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""})
373373
return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error())
374374
}

Diff for: internal/mode/static/state/graph/backend_refs_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ func TestVerifyIPFamily(t *testing.T) {
362362
Valid: true,
363363
},
364364
svcIPFamily: []v1.IPFamily{v1.IPv6Protocol},
365-
expErr: errors.New("Service configured with IPv6 family but NginxProxy is configured with IPv4"),
365+
expErr: errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4"),
366366
},
367367
{
368368
name: "Invalid - IPv6 configured for NGINX, service has only IPv4",
@@ -375,7 +375,7 @@ func TestVerifyIPFamily(t *testing.T) {
375375
Valid: true,
376376
},
377377
svcIPFamily: []v1.IPFamily{v1.IPv4Protocol},
378-
expErr: errors.New("Service configured with IPv4 family but NginxProxy is configured with IPv6"),
378+
expErr: errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6"),
379379
},
380380
{
381381
name: "Valid - When NginxProxy is nil",
@@ -965,7 +965,7 @@ func TestCreateBackend(t *testing.T) {
965965
Valid: true,
966966
},
967967
expectedCondition: helpers.GetPointer(
968-
staticConds.NewRouteInvalidIPFamily(`Service configured with IPv4 family but NginxProxy is configured with IPv6`),
968+
staticConds.NewRouteInvalidIPFamily(`service configured with IPv4 family but NginxProxy is configured with IPv6`),
969969
),
970970
name: "service IPFamily doesn't match NginxProxy IPFamily",
971971
},

Diff for: internal/mode/static/state/graph/tlsroute_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func TestBuildTLSRoute(t *testing.T) {
482482
},
483483
},
484484
Conditions: []conditions.Condition{staticConds.NewRouteInvalidIPFamily(
485-
"Service configured with IPv4 family but NginxProxy is configured with IPv6",
485+
"service configured with IPv4 family but NginxProxy is configured with IPv6",
486486
)},
487487
Attachable: true,
488488
Valid: true,

Diff for: internal/mode/static/telemetry/collector_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ var _ = Describe("Collector", Ordered, func() {
527527
It("collects correct data for one node", func(ctx SpecContext) {
528528
k8sClientReader.ListCalls(createListCallsFunc(nodeList))
529529

530-
expData.Data.ClusterNodeCount = 1
530+
expData.ClusterNodeCount = 1
531531

532532
data, err := dataCollector.Collect(ctx)
533533

0 commit comments

Comments
 (0)