Skip to content

ci: run golangci-lint with a ratcheting config (#1028) - #1216

Merged
scttfrdmn merged 2 commits into
mainfrom
ci/1028-golangci-ratchet
Oct 20, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
ci/1028-golangci-ratchet

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

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 the gofmt formatter, 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 is misspell.ignore-rules for three deliberate misspellings in tests; the reasons are commented in the file.
  • scripts/lint.sh lints the root and every nested module against the root config, passed explicitly. It discovers modules the same way scripts/check-tidy.sh does, and it fails if discovery misses the root or finds no nested module.
  • make lint pins GOLANGCI_LINT_VERSION := 2.15.0. It warns on a local version mismatch and fails if golangci-lint is missing. make check gains step 3b, check-lint, which skips a missing binary the same way check-staticcheck does. With a warm cache it takes about 11 s over all modules (about 70 s cold).
  • CI gets a new Lint job. 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 hash 9b7fe6a6…cebcea against golangci-lint-2.15.0-checksums.txt and against a local sha256 of the downloaded tarball. The job then runs make lint. No new Actions are added: it reuses the existing SHA-pinned checkout and setup-go.
  • docs/lint-ratchet.md is the record. It lists the enabled floor and gives every disabled linter its current count (root and nested) and a plan.
  • lint_ratchet_test.go is the gate. It fails if .golangci.yml's enabled linters or formatters differ from the record in either direction, if default is not none, if disable, exclusion paths or exclusion rules are used, if no CI step runs make lint, if the CI install skips the sha256 check, if the Makefile and CI versions differ, or if make lint stops calling scripts/lint.sh.
  • Small, behaviour-neutral cleanups that let four linters be enabled now:
    • govet: 2 reflect.Ptr changed to reflect.Pointer
    • copyloopvar: 9 redundant x := x removed (go 1.26 module)
    • unconvert: 6 redundant conversions removed
    • wastedassign: 5 x := "" replaced with var x string

Per-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 standard set (what you get with no config):

linter before after status
errcheck 468/8 468/8 off; most are fmt.Fprint* to a terminal
staticcheck 32/4 32/4 off; 17 of these are the repo's //lint:ignore suppressions, which golangci does not honour, and the other 19 are QF quick-fixes. The standalone staticcheck (#923) still gates SA/S/ST in CI
govet 2/0 0/0 enabled
ineffassign 0/0 0/0 enabled
unused 0/4 0/4 off; all 4 are in the dashboard-api Slack token-rotation path. Unreferenced is not unwanted, so this needs a decision about intent before anything is deleted

Enabled 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)

  • Removed govet from enable: failed with "no longer enables [govet] … The ratchet only widens".
  • Added unused without recording it: failed with "enables [unused], which docs/lint-ratchet.md does not record".
  • Set default: standard: failed with "linters.default = "standard", want "none"".
  • Added exclusions.paths: [cmd]: failed with "exclusions.paths [cmd] … exclude code from every linter".
  • Removed gofmt from formatters: failed with "no longer enables [gofmt]".
  • Changed CI run: make lint to make check-lint: failed with "no ci.yml step runs make lint".
  • Dropped the sha256sum -c line: failed with "installs golangci-lint without verifying a pinned sha256".
  • Set the Makefile version to 2.14.0: failed with "Makefile pins golangci-lint 2.14.0 but ci.yml installs 2.15.0".
  • Made lint: call golangci-lint run ./... directly: failed with "lint target does not run scripts/lint.sh".
  • Emptied the record's enabled block: failed with "the "enabled" block lists no linters — the record is broken".
  • Restored m := m in pkg/mpicohort: scripts/lint.sh reported copyloopvar and exited 1.

Checks

  • GOTOOLCHAIN=go1.26.9 make check: every step passes except check-build-tags, which fails identically on unmodified main (the /private/tmp path issue, verified on a main worktree).
  • semgrep scan --config=auto --error .: clean.
  • No help text changed, so gen-docs/check-docs are not affected. No exported symbols changed in the API-snapshot packages.

.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.
@scttfrdmn scttfrdmn added this to the v0.137.0 milestone Oct 20, 2026
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/launch_single.go 0.00% 1 Missing ⚠️
cmd/launch_sweep.go 0.00% 1 Missing ⚠️
pkg/aws/ami_checks.go 0.00% 1 Missing ⚠️
pkg/config/compliance.go 0.00% 1 Missing ⚠️
pkg/config/infrastructure.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 7ddadcb into main Oct 20, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the ci/1028-golangci-ratchet branch October 20, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

golangci-lint is not run in CI, and the root module has 439 findings (errcheck 358, staticcheck 49, unused 32)

1 participant