golangci-lint fmt's goimports formatter deletes a used import from //go:build ignore files #1686
Notifications
Due Date
No due date set.
Depends on
Reference: sam/archie#1686
Reference in new issue
Block a user
Discovered while fixing archie-core-ebzk; unrelated to it, and it does not affect
task check(nothing in the repo runsgolangci-lint fmt).REPRO, in the repo at
64aeb6c8, on a clean tree:The removal is the whole diff — there is no re-add, so applying it (
golangci-lint fmtwith no--diff) produces a file that still dereferences the package at line 39 (var Engine = secret._Engine{) with no import for it. The three engine plugins are Yaegi-interpreted by the daemon, so a corrupted one breaks secret resolution at runtime, not at build time.Scope of the damage: exactly the three files that import internal/secret and carry
//go:build ignore—examples/secret-engines/{age,sops,vault}.go— each loses exactly 1 line. The repo's other//go:build ignorefiles are untouched:internal/webui/webui_test_missing_features.go(0 lines) andexamples/modules/log.go(0 lines).NARROWED: it is goimports, not gci and not gofumpt. On the same file,
golangci-lint fmt --no-config -E gci --diff ...and-E gofumpt --diff ...both exit 0;-E goimports --diff ...exits 1 with that hunk. It also reproduces through the full configured set,golangci-lint fmt --diff examples/secret-engines/age.go(the gofumpt + goimports + gci set from.golangci.yml).The import is genuinely used (
secret._Engineat line 39),internal/secretresolves normally (packagesecret, no build tags, files present), and the imported package name matches the selector — so goimports is dropping a used import, not reporting an unused one. Prime suspect: goimports' handling of files the build excludes. It has no package context for a//go:build ignorefile, so its unused-import pass runs without one.Impact today is latent:
task checknever runsgolangci-lint fmt, so no gate is red and the normal workflow corrupts nothing. The trap is that.golangci.ymladvertises aformatters:block, so runninggolangci-lint fmt— the obvious command for it — silently breaks three shipped example plugins.Options: keep build-ignored files out of the formatters' scope with a
formatters.exclusionsrule (mirroring the existing_test.goexclusion underlinters.exclusions), or report upstream and pin. Note.golangci.ymlalready setsformatters.exclusions.generated: strict, which does not cover build-ignored sources.Notes
CONFIRMED IN THE WILD, 2026-09-19, minutes after filing. A concurrent session in this repo ran golangci-lint fmt (no --diff) and it deleted the import from all three example engines. task check then failed at the test step with 17 failures in internal/secret, e.g.
WARN skipping secret engine file=age.go err="evaluate: 38:5: constant definition loop"
--- FAIL: TestEachEngineLoadsStandalone/age (0.03s) engines_test.go:93: LoadDir loaded 0 engines, want 1
That is the predicted runtime breakage: Yaegi cannot evaluate a file that dereferences secret._Engine with no import, and reports it as a constant definition loop rather than a missing import. task check is green again after
git restore --worktree -- examples/secret-engines/age.go examples/secret-engines/sops.go examples/secret-engines/vault.go
but nothing stops the next golangci-lint fmt from re-breaking them, so the formatters exclusion is worth landing rather than deferring. Severity is higher than the original filing suggested: it does not merely corrupt files on request, it has already reddened the gate on a shared checkout.
Close reason
Implemented one configured formatting writer, protected Yaegi secret engines from goimports, and added a read-only PR quality gate; task check passes.
Imported from beads
archie-core-z3t7· GitHub #927 · type bug · priority P2 · created 2026-09-19 · closed 2026-09-19