Repository navigation
ci: migrate golangci-lint to v2 - #1466
Open
Iamrushabhshahh wants to merge 2 commits into
Open
Iamrushabhshahh wants to merge 2 commits into
Iamrushabhshahh wants to merge 2 commits into
Conversation
golangci-lint v1 is no longer maintained and cannot load modules that target Go 1.25, which the pending dependency updates need. Move to v2 first, on the current Go version, so the Go bump can follow separately. - Use golangci-lint v2.14.0 with golangci-lint-action@v9. - Migrate .golangci.yml to the v2 format and keep the v1 rule set: gosimple and stylecheck are now part of staticcheck, gofumpt moves to formatters, the QF* quick fixes and govet's inline analyser stay off, and v1's default exclusions are kept through presets. - Skip prealloc in _test.go files, and match third_party, builtin and examples directories the way v1 did. - make lint and lint-fix now install GOLINTER_VERSION when the golangci-lint on PATH is missing or a different version, and fail with a clear message if an older binary still shadows it. Co-authored-by: Iamrushabhshahh <rushabhshah842@gmail.com> Signed-off-by: Iamrushabhshahh <rushabhshah842@gmail.com>
The linters bundled with golangci-lint v2 report findings that v1 did
not. All are small and do not change behaviour, except the slog calls,
which logged the error as the message and produced a !BADKEY attribute.
- govet slog: logger.Error(err.Error(), "msg", "error", err) becomes
logger.Error("msg", "error", err).
- staticcheck SA1006: fmt.Errorf(s) becomes errors.New(s), and
fmt.Printf(s) becomes fmt.Print(s).
- staticcheck S1009: drop nil checks that len() already covers.
- predeclared: rename local "max" variables, which shadow the Go 1.21
builtin, to "maxItems".
- prealloc: preallocate slices in non-test code.
- gofumpt: reformat k8s_printer.go.
Co-authored-by: Iamrushabhshahh <rushabhshah842@gmail.com>
Signed-off-by: Iamrushabhshahh <rushabhshah842@gmail.com>
This was referenced Oct 15, 2026
Contributor
Author
|
Hi @elliotxx, gentle follow-up: this is the lint-only half you asked for, on Go 1.22, with the Makefile version check. All checks are green. Could you take a look when you have time? The Go 1.25 PR is ready to go right after this one. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This is the first half of #1463, split as @elliotxx suggested. It moves golangci-lint from v1.56.2 to v2.14.0 and keeps CI on Go 1.22. The Go bump comes in a separate, smaller PR on top of this one.
golangci-lint v1 is no longer maintained and cannot load modules that target Go 1.25, so the Go bump needs v2 first. Details and error lines are in #1462 and #1463.
Changes (two commits):
ci: migrate golangci-lint to v2.github/workflows/test.yaml:golangci/golangci-lint-action@v9withversion: v2.14.0. Go stays at 1.22, and the other actions are unchanged..golangci.yml: migrated withgolangci-lint migrate, then adjusted by hand to keep the v1 behaviour:gosimpleandstylecheckare now part ofstaticcheck,gofumptmoves toformatters, andexportloopref(already inactive) is gone.QF*quick fixes and govet'sinlineanalyser stay off, as v1 did not run them.comments,common-false-positives,legacyandstd-error-handlingpresets, and the existingexcludetexts are kept as rules.(^|/)third_party($|/)as v1 did. The pattern written by the migration did not match files inside them._test.gofiles.Makefile:GOLINTER_VERSIONis v2.14.0 with the v2 module path.make lintandmake lint-fixnow go through alint-installtarget that checksgolangci-lint --version. If the binary is missing or a different version, it installsGOLINTER_VERSION. If an older binary still comes first onPATHafter that, it stops with a message saying which one, instead of running the wrong linter.style: fix findings reported by golangci-lint v2v2's bundled linters report findings that v1 did not, on Go 1.22 as well. All are small:
logger.Error(err.Error(), "msg", "error", err)becomeslogger.Error("msg", "error", err)inpkg/server/route/route.goandpkg/server/handler/endpoint/endpoint.go. The old calls logged the error as the message and produced a!BADKEYattribute, so this one is a real fix.fmt.Errorf(s)becomeserrors.New(s)(secrets providers,watch.go,tferrors.go), andfmt.Printf(s)becomesfmt.Print(s).x == nil ||beforelen(x) == 0.maxink8s_printer.gorenamed tomaxItems.k8s_printer.go.No change to
go.mod, the Dockerfile or the other workflows.How I tested it
Locally with Go 1.22.12 (
GOTOOLCHAIN=go1.22.12) and golangci-lint v2.14.0:If I leave out the slog and format-string fixes in
route.go,endpoint.go,watch.goandtferrors.go, the same run reports 13 issues, so v2 needs them on Go 1.22 too.Full repository lint and
make coveron my fork's CI, with Go 1.22.12. I added a temporary commit, not part of this PR, sotest.yamlruns on push and lint prints every finding: https://github.com/Iamrushabhshahh/kusion/actions/runs/38732820314.Golang Lintpassed with0 issues., andUnit tests with coveragepassed.make lint-install, checked in three cases:PATH: nothing is installed, exit 0.PATH: installs v2.14.0, then stops with<path> is not v2.14.0. Remove it or put $GOPATH/bin first in PATH., exit 2.PATH: installs v2.14.0, exit 0.Which issue(s) this PR fixes:
Related: #1462
Special notes for your reviewer:
@elliotxx, this is the lint-only half, on Go 1.22, with the Makefile version check you asked for. Once this is in, I'll send the Go 1.25 bump (CI, Dockerfile, mockey) as its own PR, and that one will close #1462. I'll close #1463 in favour of these two.
Does this PR introduce a user-facing change?
Additional documentation e.g., design docs, usage docs, etc.: