ref:3df754cdfacbc228d36b503914cb87c914d30acd

build: add pre-commit hook for cargo fmt + clippy

Version-controlled `.githooks/pre-commit` runs `cargo fmt --all -- --check` and `cargo clippy --all-targets --all-features -- -D warnings` whenever a commit touches any `.rs` file. Non-Rust commits skip the hook and are not slowed down. `scripts/install-hooks.sh` wires `core.hooksPath` to `.githooks` — run once per clone. Zero external dependencies (no pre-commit framework, no husky, no lefthook). Verified: unformatted module change is blocked with a diff and an actionable "run `cargo fmt --all` and re-stage" message. Closes #5
SHA: 3df754cdfacbc228d36b503914cb87c914d30acd
Author: Cole Christensen <cole.christensen@macmillan.com>
Date: 2026-04-20 03:11
Parents: 04c8e1b
2 files changed +37 -0
Type
.githooks/pre-commit +24 −0
@@ -1,0 +1,24 @@
#!/usr/bin/env bash
# Pre-commit hook: rustfmt + clippy on Rust changes.
#
# Enable for this checkout with: ./scripts/install-hooks.sh
set -euo pipefail
staged_rust=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.rs$' || true)
if [ -z "$staged_rust" ]; then
exit 0
fi
echo "pre-commit: cargo fmt --all -- --check"
if ! cargo fmt --all -- --check; then
echo "pre-commit: formatting failed. Run 'cargo fmt --all' and re-stage."
exit 1
fi
echo "pre-commit: cargo clippy --all-targets --all-features -- -D warnings"
if ! cargo clippy --all-targets --all-features -- -D warnings; then
echo "pre-commit: clippy failed. Fix the warnings and re-stage."
exit 1
fi
scripts/install-hooks.sh +13 −0
@@ -1,0 +1,13 @@
#!/usr/bin/env bash
# Wire git hooks to the version-controlled .githooks/ directory.
# Run once per clone.
set -euo pipefail
repo_root=$(git -C "$(dirname "$0")" rev-parse --show-toplevel)
cd "$repo_root"
git config core.hooksPath .githooks
echo "core.hooksPath -> .githooks"
echo "Staged .rs files will now be checked with cargo fmt + clippy before commit."