Skip to content

Update golangci-lint to v2 #3269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ jobs:
go-version: stable

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

njs-lint:
name: NJS Lint
Expand Down
154 changes: 85 additions & 69 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,6 @@
linters-settings:
ginkgolinter:
forbid-focus-container: true
goimports:
local-prefixes: github.com/nginx/nginx-gateway-fabric
misspell:
locale: US
revive:
ignore-generated-header: true
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
arguments:
- allowedPackages:
- github.com/onsi/gomega
- github.com/onsi/ginkgo/v2
- name: duplicated-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: superfluous-else
- name: time-naming
- name: unchecked-type-assertion
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
gocyclo:
min-complexity: 15
govet:
enable:
- fieldalignment
lll:
line-length: 120
dupword:
ignore:
- "test"
stylecheck:
dot-import-whitelist:
- github.com/onsi/gomega
- github.com/onsi/ginkgo/v2
version: "2"
linters:
default: none
enable:
- asasalint
- asciicheck
Expand All @@ -78,11 +20,7 @@ linters:
- gocritic
- gocyclo
- godot
- gofmt
- gofumpt
- goimports
- gosec
- gosimple
- gosmopolitan
- govet
- ineffassign
Expand All @@ -103,20 +41,98 @@ linters:
- revive
- spancheck
- staticcheck
- stylecheck
- tagalign
- thelper
- tparallel
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- whitespace
disable-all: true
settings:
dupword:
ignore:
- test
ginkgolinter:
forbid-focus-container: true
gocyclo:
min-complexity: 15
govet:
enable:
- fieldalignment
lll:
line-length: 120
misspell:
locale: US
revive:
rules:
- name: blank-imports
- name: constant-logical-expr
- name: context-as-argument
- name: context-keys-type
- name: defer
- name: dot-imports
arguments:
- allowedPackages:
- github.com/onsi/gomega
- github.com/onsi/ginkgo/v2
- name: duplicated-imports
- name: empty-block
- name: error-naming
- name: error-return
- name: error-strings
- name: errorf
- name: exported
- name: import-shadowing
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
- name: range
- name: range-val-address
- name: range-val-in-closure
- name: receiver-naming
- name: redefines-builtin-id
- name: string-of-int
- name: superfluous-else
- name: time-naming
- name: unchecked-type-assertion
- name: unexported-return
- name: unnecessary-stmt
- name: unreachable-code
- name: unused-parameter
- name: var-declaration
- name: var-naming
staticcheck:
dot-import-whitelist:
- github.com/onsi/gomega
- github.com/onsi/ginkgo/v2
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
issues:
max-issues-per-linter: 0
max-same-issues: 0
run:
timeout: 3m
formatters:
enable:
- gofmt
- gofumpt
- goimports
settings:
goimports:
local-prefixes:
- github.com/nginx/nginx-gateway-fabric
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ repos:
- javascript

- repo: https://github.com/golangci/golangci-lint
rev: v1.64.8
rev: v2.0.2
hooks:
- id: golangci-lint-full
name: golangci-lint-root
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GO_LINKER_FLAGS = $(GO_LINKER_FLAGS_OPTIMIZATIONS) $(GO_LINKER_FlAGS_VARS)

# tools versions
# renovate: datasource=github-tags depName=golangci/golangci-lint
GOLANGCI_LINT_VERSION = v1.64.8
GOLANGCI_LINT_VERSION = v2.0.2
# renovate: datasource=docker depName=kindest/node
KIND_K8S_VERSION = v1.32.3
# renovate: datasource=github-tags depName=norwoodj/helm-docs
Expand Down Expand Up @@ -192,7 +192,7 @@ vet: ## Run go vet against code

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

.PHONY: unit-test
unit-test: ## Run unit tests for the go code
Expand Down
4 changes: 2 additions & 2 deletions internal/mode/provisioner/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func prepareDeployment(depYAML []byte, id string, gwNsName types.NamespacedName)
return nil, fmt.Errorf("failed to unmarshal deployment: %w", err)
}

dep.ObjectMeta.Name = id
dep.Name = id
dep.Spec.Selector.MatchLabels["app"] = id
dep.Spec.Template.ObjectMeta.Labels["app"] = id
dep.Spec.Template.Labels["app"] = id

finalArgs := []string{
"--gateway=" + gwNsName.String(),
Expand Down
10 changes: 5 additions & 5 deletions internal/mode/static/state/graph/backend_refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ func createBackendRef(
}

ns := sourceNamespace
if ref.BackendRef.Namespace != nil {
if ref.Namespace != nil {
ns = string(*ref.Namespace)
}
svcNsName := types.NamespacedName{Name: string(ref.BackendRef.Name), Namespace: ns}
svcNsName := types.NamespacedName{Name: string(ref.Name), Namespace: ns}
svcIPFamily, svcPort, err := getIPFamilyAndPortFromRef(ref.BackendRef, svcNsName, services, refPath)
if err != nil {
backendRef = BackendRef{
Expand Down Expand Up @@ -328,7 +328,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error {
// capitalizing error message to match the rest of the error messages associated with a condition
//nolint: stylecheck
return errors.New(
"Service configured with IPv6 family but NginxProxy is configured with IPv4",
"service configured with IPv6 family but NginxProxy is configured with IPv4",
)
}
}
Expand All @@ -337,7 +337,7 @@ func verifyIPFamily(npCfg *NginxProxy, svcIPFamily []v1.IPFamily) error {
// capitalizing error message to match the rest of the error messages associated with a condition
//nolint: stylecheck
return errors.New(
"Service configured with IPv4 family but NginxProxy is configured with IPv6",
"service configured with IPv4 family but NginxProxy is configured with IPv6",
)
}
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func validateBackendRef(
) (valid bool, cond conditions.Condition) {
// Because all errors cause same condition but different reasons, we return as soon as we find an error

if ref.Group != nil && !(*ref.Group == "core" || *ref.Group == "") {
if ref.Group != nil && (*ref.Group != "core" && *ref.Group != "") {
valErr := field.NotSupported(path.Child("group"), *ref.Group, []string{"core", ""})
return false, staticConds.NewRouteBackendRefInvalidKind(valErr.Error())
}
Expand Down
6 changes: 3 additions & 3 deletions internal/mode/static/state/graph/backend_refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ func TestVerifyIPFamily(t *testing.T) {
Valid: true,
},
svcIPFamily: []v1.IPFamily{v1.IPv6Protocol},
expErr: errors.New("Service configured with IPv6 family but NginxProxy is configured with IPv4"),
expErr: errors.New("service configured with IPv6 family but NginxProxy is configured with IPv4"),
},
{
name: "Invalid - IPv6 configured for NGINX, service has only IPv4",
Expand All @@ -375,7 +375,7 @@ func TestVerifyIPFamily(t *testing.T) {
Valid: true,
},
svcIPFamily: []v1.IPFamily{v1.IPv4Protocol},
expErr: errors.New("Service configured with IPv4 family but NginxProxy is configured with IPv6"),
expErr: errors.New("service configured with IPv4 family but NginxProxy is configured with IPv6"),
},
{
name: "Valid - When NginxProxy is nil",
Expand Down Expand Up @@ -965,7 +965,7 @@ func TestCreateBackend(t *testing.T) {
Valid: true,
},
expectedCondition: helpers.GetPointer(
staticConds.NewRouteInvalidIPFamily(`Service configured with IPv4 family but NginxProxy is configured with IPv6`),
staticConds.NewRouteInvalidIPFamily(`service configured with IPv4 family but NginxProxy is configured with IPv6`),
),
name: "service IPFamily doesn't match NginxProxy IPFamily",
},
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/state/graph/tlsroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ func TestBuildTLSRoute(t *testing.T) {
},
},
Conditions: []conditions.Condition{staticConds.NewRouteInvalidIPFamily(
"Service configured with IPv4 family but NginxProxy is configured with IPv6",
"service configured with IPv4 family but NginxProxy is configured with IPv6",
)},
Attachable: true,
Valid: true,
Expand Down
2 changes: 1 addition & 1 deletion internal/mode/static/telemetry/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ var _ = Describe("Collector", Ordered, func() {
It("collects correct data for one node", func(ctx SpecContext) {
k8sClientReader.ListCalls(createListCallsFunc(nodeList))

expData.Data.ClusterNodeCount = 1
expData.ClusterNodeCount = 1

data, err := dataCollector.Collect(ctx)

Expand Down
Loading