Files
lan-mouse/.githooks/pre-commit
Jon Stelly 4d8f7d7813 chore: developer experience - pre-commit hook, ai instructions, yaml formatting (#374)
* chore: developer experience - pre-commit hook, ai instructions, yaml formatting for prettier

* no prettierrc, editorconfig instead

* fixes from copilot suggestions

---------

Co-authored-by: Ferdinand Schober <ferdinandschober20@gmail.com>
2026-03-25 13:34:17 +01:00

35 lines
1009 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
# Ensure we're at the repo root
cd "$(git rev-parse --show-toplevel)" || exit 1
echo "Running cargo fmt (auto-format)..."
# Run formatter to apply fixes but do not stage them. If formatting changed,
# fail the commit so the user can review and stage the changes manually.
cargo fmt --all
if ! git diff --quiet --exit-code; then
echo "" >&2
echo "ERROR: cargo fmt modified files. Review changes, stage them, and commit again." >&2
git --no-pager diff --name-only
exit 1
fi
echo "Running cargo clippy..."
# Matches CI: deny warnings to keep code health strict
if ! cargo clippy --workspace --all-targets --all-features -- -D warnings; then
echo "" >&2
echo "ERROR: clippy found warnings/errors. Fix them before committing." >&2
exit 1
fi
echo "Running cargo test..."
if ! cargo test --workspace --all-features; then
echo "" >&2
echo "ERROR: Some tests failed. Fix tests before committing." >&2
exit 1
fi
echo "All pre-commit checks passed."
exit 0