golangci-lint fmt's goimports formatter deletes a used import from //go:build ignore files #1686

Closed
opened 2026-10-27 13:41:23 +00:00 by sam · 0 comments
Owner

Discovered while fixing archie-core-ebzk; unrelated to it, and it does not affect task check (nothing in the repo runs golangci-lint fmt).

REPRO, in the repo at 64aeb6c8, on a clean tree:

golangci-lint fmt --no-config -E goimports --diff examples/secret-engines/age.go

diff examples/secret-engines/age.go.orig examples/secret-engines/age.go
--- examples/secret-engines/age.go.orig
+++ examples/secret-engines/age.go
@@ -32,7 +32,6 @@
 	"os"
 	"strings"

-	"github.com/samcharles93/archie-core/internal/secret"
 	"github.com/samcharles93/archie-core/internal/secret/enginehost"
 )

exit=1

The removal is the whole diff — there is no re-add, so applying it (golangci-lint fmt with 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 ignore files are untouched: internal/webui/webui_test_missing_features.go (0 lines) and examples/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._Engine at line 39), internal/secret resolves normally (package secret, 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 ignore file, so its unused-import pass runs without one.

Impact today is latent: task check never runs golangci-lint fmt, so no gate is red and the normal workflow corrupts nothing. The trap is that .golangci.yml advertises a formatters: block, so running golangci-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.exclusions rule (mirroring the existing _test.go exclusion under linters.exclusions), or report upstream and pin. Note .golangci.yml already sets formatters.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

Discovered while fixing archie-core-ebzk; unrelated to it, and it does not affect `task check` (nothing in the repo runs `golangci-lint fmt`). REPRO, in the repo at 64aeb6c8, on a clean tree: golangci-lint fmt --no-config -E goimports --diff examples/secret-engines/age.go diff examples/secret-engines/age.go.orig examples/secret-engines/age.go --- examples/secret-engines/age.go.orig +++ examples/secret-engines/age.go @@ -32,7 +32,6 @@ "os" "strings" - "github.com/samcharles93/archie-core/internal/secret" "github.com/samcharles93/archie-core/internal/secret/enginehost" ) exit=1 The removal is the whole diff — there is no re-add, so applying it (`golangci-lint fmt` with 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 ignore` files are untouched: `internal/webui/webui_test_missing_features.go` (0 lines) and `examples/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._Engine` at line 39), `internal/secret` resolves normally (package `secret`, 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 ignore` file, so its unused-import pass runs without one. Impact today is latent: `task check` never runs `golangci-lint fmt`, so no gate is red and the normal workflow corrupts nothing. The trap is that `.golangci.yml` advertises a `formatters:` block, so running `golangci-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.exclusions` rule (mirroring the existing `_test.go` exclusion under `linters.exclusions`), or report upstream and pin. Note `.golangci.yml` already sets `formatters.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_
sam added the bugmedium labels 2026-10-27 13:41:23 +00:00
sam self-assigned this 2026-10-27 13:41:23 +00:00
sam closed this issue 2026-10-27 13:41:23 +00:00
sam added a new dependency 2026-10-27 13:42:28 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Reference: sam/archie#1686