rustfmt on every edit, clippy before every commit touching Rust
A Claude Code hook formats each .rs file as it is edited, and the pre-commit hook runs clippy as well as the format check. Clippy only checks, so with the line-tables profile it takes under a minute (57 s after a change) at load 8. rust-analyzer, which gave the same errors as clippy for 2.8 GB of memory, is no longer used. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
#!/bin/sh
|
||||
# Refuses a commit whose Rust is not as rustfmt writes it. Clippy is left to the checks before a
|
||||
# push (CLAUDE.md, Tests): it is a build, and Tower's builds go one at a time.
|
||||
# Refuses a commit whose Rust is not as rustfmt writes it, or that clippy warns about. Clippy only
|
||||
# checks and never links, so it is light beside a test build (CLAUDE.md, Tests); with the line-tables
|
||||
# profile it takes about a minute after a change and seconds otherwise.
|
||||
git diff --cached --name-only --diff-filter=ACM | grep -q '\.rs$' || exit 0
|
||||
cargo fmt --all --check >/dev/null 2>&1 && exit 0
|
||||
echo "pre-commit: the Rust is not formatted; run cargo fmt --all" >&2
|
||||
exit 1
|
||||
if ! cargo fmt --all --check >/dev/null 2>&1; then
|
||||
echo "pre-commit: the Rust is not formatted; run cargo fmt --all" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! cargo clippy --workspace --all-targets -q -- -D warnings; then
|
||||
echo "pre-commit: clippy has warnings; fix them, or allow one where it is wrong, with a comment saying why" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user