Skip to content

Bring the workspace back to rustfmt, and keep it there - #44

Merged
JamesKane merged 2 commits into
mainfrom
chore/rustfmt-workspace
Aug 2, 2026
Merged

Bring the workspace back to rustfmt, and keep it there#44
JamesKane merged 2 commits into
mainfrom
chore/rustfmt-workspace

Conversation

@JamesKane

@JamesKane JamesKane commented Aug 2, 2026

Copy link
Copy Markdown
Owner

cargo fmt --all had drifted far enough that running it touches 116 files. That made it a tax on every feature branch: either carry a pile of unrelated reformatting into review, or de-noise the diff by hand before opening the PR (which is what #43 had to do). Two commits — clear the drift, then stop it coming back.

main is genuinely drifted, not misconfigured — stable rustfmt disagrees with main too, so this isn't a nightly-toolchain artifact.

1. 7c4fbf6 — the reformat

Almost all mechanical cargo fmt --all output, skimmable. There are two places I did not simply take what the tool produced, and those are the only spots worth a real look:

20 hand-inserted blank lines, across 13 files. Where a standalone comment block directly follows a line that already ends in a trailing comment, rustfmt aligns the block to that comment's column — pushing text out to column 50–90 and, in a few cases, past the 120 the config asks for:

let _ = tx.send(Command::LoadAssetStatus); // ancestry/IBD "data sources" line
                                           // Check for a newer installer at startup (unless the user opted out). Non-fatal — a failed
                                           // check just logs to the status line; the app never auto-updates.

That is worse than the drift it replaces, so a blank line breaks the association and the comments sit at their natural indent. Two of these artifacts already existed on main (ui/mod.rs, domain/src/consensus.rs) — fixed here too.

One comment rewrittennavigator-analysis/src/archaic.rs. The // 400 absent entirely note documented a panel site deliberately missing from the genotype list, and rustfmt could only render it at a bad indent inside the vec![]. It is now a sentence above the binding. This is the only content change in the branch.

2. 2534c37 — the hook

.githooks/pre-commit runs cargo fmt --all --check and rejects a commit that would reintroduce drift. Local, not CI — the useful moment to catch this is before it is committed, not after a build fails. ~0.6s, compiles nothing, so there is no incentive to disable it.

It only ever checks; it never reformats your tree mid-commit, because a commit whose contents you did not read is a worse failure than the one being prevented. It reports the offending files and the fix.

Stays out of the way where it has no business: no cargo on PATH exits 0, and so does a commit with no staged .rs files — which also covers merges and reverts. --no-verify is the escape hatch.

Enable once per clone (hooks are per-clone git config, so this is not automatic on checkout — CLAUDE.md documents it):

git config core.hooksPath .githooks

Testing

cargo fmt --all --check clean and idempotent · cargo clippy --all-targets clean · cargo test --workspace green, 0 failures.

Hook exercised on both paths: clean tree passes, staged drift is rejected with the file list, and the rejected commit is genuinely not created. The no-staged-.rs path is exercised by 2534c37 itself, which the hook correctly let through.

🤖 Generated with Claude Code

JamesKane and others added 2 commits August 2, 2026 13:28
`cargo fmt --all` had drifted far enough that running it touched 116 files, which
meant every feature branch either carried a pile of unrelated reformatting or had
to be de-noised by hand before review. This is that reformat, on its own, so the
next one does not have to be.

Pure `cargo fmt --all` output, with one class of exception. Where a standalone
comment block directly follows a line that already ends in a trailing comment,
rustfmt aligns the block to that comment's column — pushing text out to column
50-90 and, in a few cases, past the 120 the config asks for. That is worse than
the drift it replaces, so 20 blank lines were inserted by hand to break the
association and let the comments sit at their natural indent. Two of those
artifacts predate this commit; they are fixed here too.

One comment changed wording rather than position: the `// 400 absent entirely`
note in `archaic::tests` documented a panel site deliberately missing from the
genotype list, and rustfmt could only render it at a bad indent inside the
`vec![]`. It is now a sentence above the binding, which is where it belonged.

`cargo fmt --all --check` is clean and idempotent; clippy `--all-targets` clean;
`cargo test --workspace` green.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`cargo fmt` clean was already a per-commit gate for this repo, but nothing
enforced it, and the drift that accumulated once reached 116 files — at which
point every feature branch either carried a pile of unrelated reformatting into
review or had to be de-noised by hand before it was readable. The preceding
commit clears the drift; this stops it coming back.

Local rather than CI, deliberately: the useful moment to catch this is before it
is committed, not after a build fails. `cargo fmt --all --check` costs ~0.6s and
compiles nothing, so it is cheap enough that nobody has a reason to disable it.

The hook only ever *checks*. A hook that reformats your files mid-commit
produces a commit whose contents you did not read, which is a worse failure than
the one it prevents. It reports the offending files and the command to fix them.

It stays out of the way where it has no business: no cargo on PATH (docs-only
checkout) exits 0, and so does a commit with no staged `.rs` files — which also
covers merges and reverts, where the tree is whatever the other side wrote and
blocking helps nobody. `--no-verify` remains the escape hatch.

Hooks live in per-clone git config, so this is not automatic on checkout;
CLAUDE.md documents the one-time `git config core.hooksPath .githooks`.

Verified by exercising both paths: a clean tree passes, staged drift is
rejected with the file list, and the rejected commit is genuinely not created.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@JamesKane JamesKane changed the title Bring the workspace back to rustfmt Bring the workspace back to rustfmt, and keep it there Aug 2, 2026
@JamesKane
JamesKane merged commit 8f7f833 into main Aug 2, 2026
3 checks passed
@JamesKane
JamesKane deleted the chore/rustfmt-workspace branch August 2, 2026 18:49
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.

1 participant