Repository navigation
ci: run golangci-lint with a ratcheting config (#1028) - #1216
Merged
Merged
Conversation
.golangci.yml enables only the 23 linters (+ gofmt) that pass today across all 10 modules; a Lint CI job runs make lint (golangci-lint v2.15.0, pinned version + sha256) via scripts/lint.sh; docs/lint-ratchet.md records the floor and every disabled linter's count; lint_ratchet_test.go keeps the config from narrowing. Behaviour-neutral cleanups to enable govet, copyloopvar, unconvert and wastedassign.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…nneeded on 64-bit linux
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.
golangci-lint ran nowhere in CI. This adds it as a ratchet, which is the default the owner agreed on #1028: commit a narrowing config that passes today, run it in CI, and widen it one linter at a time.
Fixes #1028
What changed
.golangci.yml(v2 schema):default: none, plus 23 linters and thegofmtformatter, all of which report zero findings across all 10 modules. There are no path exclusions, no exclusion rules and no new//nolint. The only per-linter setting ismisspell.ignore-rulesfor three deliberate misspellings in tests; the reasons are commented in the file.scripts/lint.shlints the root and every nested module against the root config, passed explicitly. It discovers modules the same wayscripts/check-tidy.shdoes, and it fails if discovery misses the root or finds no nested module.make lintpinsGOLANGCI_LINT_VERSION := 2.15.0. It warns on a local version mismatch and fails if golangci-lint is missing.make checkgains step 3b,check-lint, which skips a missing binary the same waycheck-staticcheckdoes. With a warm cache it takes about 11 s over all modules (about 70 s cold).Lintjob. It installs golangci-lint v2.15.0 with the version and sha256 pinned in the workflow, the same pattern as staticcheck and gitleaks. I cross-checked the hash9b7fe6a6…cebceaagainstgolangci-lint-2.15.0-checksums.txtand against a local sha256 of the downloaded tarball. The job then runsmake lint. No new Actions are added: it reuses the existing SHA-pinned checkout and setup-go.docs/lint-ratchet.mdis the record. It lists the enabled floor and gives every disabled linter its current count (root and nested) and a plan.lint_ratchet_test.gois the gate. It fails if.golangci.yml's enabled linters or formatters differ from the record in either direction, ifdefaultis notnone, ifdisable, exclusion paths or exclusion rules are used, if no CI step runsmake lint, if the CI install skips the sha256 check, if the Makefile and CI versions differ, or ifmake lintstops callingscripts/lint.sh.govet: 2reflect.Ptrchanged toreflect.Pointercopyloopvar: 9 redundantx := xremoved (go 1.26 module)unconvert: 6 redundant conversions removedwastedassign: 5x := ""replaced withvar x stringPer-linter counts, before → after
These were measured with golangci-lint v2.15.0, uncapped, with
uniq-by-line: false. Before is main at 94c68a4; after is this branch. Each cell is root/nested.golangci-lint's built-in
standardset (what you get with no config):fmt.Fprint*to a terminal//lint:ignoresuppressions, which golangci does not honour, and the other 19 are QF quick-fixes. The standalone staticcheck (#923) still gates SA/S/ST in CIEnabled after small fixes: copyloopvar 8/1 → 0, unconvert 5/1 → 0, wastedassign 5/0 → 0.
Enabled with zero findings before and after: asasalint, asciicheck, bidichk, durationcheck, exptostd, fatcontext, gocheckcompilerdirectives, gochecksumtype, loggercheck, makezero, mirror, misspell (4 → 0 via the three ignore-rules), nolintlint (0 under this config), reassign, recvcheck, sloglint, testifylint, tparallel, and the gofmt formatter.
Candidates I left off, with root/nested counts: nilnesserr 0/2 (a real ttl-reaper bug, filed as #1211), nosprintfhostport 2/0, canonicalheader 1/0, bodyclose 7/0, predeclared 19/2, errorlint 23/0, nilerr 21/17, thelper 13/0. The full table, including the style linters that are not planned, is in docs/lint-ratchet.md.
Gate verification (each revert compiles and runs; the test failed for the stated reason each time)
govetfromenable: failed with "no longer enables [govet] … The ratchet only widens".unusedwithout recording it: failed with "enables [unused], which docs/lint-ratchet.md does not record".default: standard: failed with "linters.default = "standard", want "none"".exclusions.paths: [cmd]: failed with "exclusions.paths [cmd] … exclude code from every linter".gofmtfrom formatters: failed with "no longer enables [gofmt]".run: make linttomake check-lint: failed with "no ci.yml step runsmake lint".sha256sum -cline: failed with "installs golangci-lint without verifying a pinned sha256".lint:callgolangci-lint run ./...directly: failed with "lint target does not run scripts/lint.sh".m := min pkg/mpicohort:scripts/lint.shreported copyloopvar and exited 1.Checks
GOTOOLCHAIN=go1.26.9 make check: every step passes exceptcheck-build-tags, which fails identically on unmodified main (the /private/tmp path issue, verified on a main worktree).semgrep scan --config=auto --error .: clean.