Skip to main content

Module rust_tools

Module rust_tools 

Source
Expand description

The three Rust hooks: cargo fmt --check, cargo clippy, cargo test.

Scoped like every other language hook — they fire only when the commit (or push) touches Rust, and only in a directory that actually has a Cargo.toml. A Python repo never invokes cargo.

Split across the two dispatchers by COST, matching what the other languages already do: fmt and clippy are pre-commit (as ruff and pyright are), test is pre-push (as run-tests-js is). Nobody wants to wait for a workspace test run on every commit.

Each is a separate check rather than one “rust” hook, so hook.skip can disable them individually — git config hook.skip clippy when you are mid-refactor, without losing the formatting gate.

Constants§

EXTS
What cargo fmt is handed. Exported so registry.rs declares the scope from the same constant — see lint_json_yaml::EXTS.
RUST_PATHS
Files that mean “this commit touches Rust”. Cargo.toml and Cargo.lock count: a dependency bump compiles differently without a single .rs edit, and that is exactly when clippy earns its keep.

Functions§

clippy
clippy_args
What pre-commit clippy judges (ADR-0009, hooks.clippy-scope). It runs in the package root nearest each staged .rs, and without --workspace cargo judges that package alone (the default members, at a virtual root). The whole workspace is judged when a manifest, the lockfile, a lint config or the toolchain pin is staged — they change how every package compiles — or when the file set is not the index (--all-files). Lints a change provokes in a DEPENDENT package are caught by CI’s workspace clippy, not here: a cold --workspace per worktree was the longest and most lock-hungry check of a commit.
fmt
test
pre-push. Mirrors run-tests-js: the range that is actually being pushed decides whether the suite runs, so a docs-only push costs nothing.