From ec522f49eccf8794922dff08dfd068f083772c0d Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Wed, 3 Jun 2026 20:46:55 -0700 Subject: [PATCH] infra(prek): add cargo fmt as a pre-commit hook Run `cargo fmt --all` in place over the workspace on any staged .rs change, matching the repo's other in-place formatters (ruff-format, stylua, shfmt). Unformatted Rust now fails the commit locally (it reformats + reports "files were modified"), so the fmt-dirty commits that slipped through this session can't recur. CI still enforces `cargo fmt --check` via Dagger as the backstop. Verified: passes clean, catches + fixes a deviation. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/changelog.d/v1-prek-cargo-fmt.infra.md | 1 + prek.toml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 docs/changelog.d/v1-prek-cargo-fmt.infra.md diff --git a/docs/changelog.d/v1-prek-cargo-fmt.infra.md b/docs/changelog.d/v1-prek-cargo-fmt.infra.md new file mode 100644 index 0000000..bfe9c18 --- /dev/null +++ b/docs/changelog.d/v1-prek-cargo-fmt.infra.md @@ -0,0 +1 @@ +- **`cargo fmt` is now a prek hook** — `cargo fmt --all` runs in place over the workspace on any staged `.rs` change (grouped with the other in-place formatters), so unformatted Rust can't be committed locally. CI already enforced `cargo fmt --check` via `dagger call check`; this catches it at commit time instead. diff --git a/prek.toml b/prek.toml index 7de95ab..c6a3a8f 100644 --- a/prek.toml +++ b/prek.toml @@ -83,6 +83,20 @@ repo = "https://github.com/JohnnyMorganz/StyLua" rev = "v2.4.1" hooks = [{ id = "stylua-system" }] +# Rust formatting - cargo fmt over the whole workspace, in place (like the other +# formatters above). Uses the system toolchain; CI also enforces it via +# `dagger call check` (cargo fmt --check). Runs whenever a .rs file is staged. +[[repos]] +repo = "local" + +[[repos.hooks]] +id = "cargo-fmt" +name = "cargo-fmt" +entry = "cargo fmt --all" +language = "system" +files = '\.rs$' +pass_filenames = false + # GitHub/Forgejo Actions workflow linting [[repos]] repo = "https://github.com/rhysd/actionlint"