Files
Priyanshu KumarandCursor 49b5359077 Add pre-commit hook for cargo fmt and clippy checks
- scripts/hooks/pre-commit: runs fmt --check and clippy on staged .rs files
- scripts/install-hooks.sh: copies hooks into .git/hooks/
- CI: add system deps install step in preflight job
- CI: grant gh-runner sudo for apt-get via setup script

Co-authored-by: Cursor <[email protected]>
2026-02-11 09:53:38 +00:00

45 lines
1.3 KiB
Bash
Executable File

#!/bin/bash
# r2sleigh pre-commit hook
# Runs cargo fmt (check) and clippy on staged Rust files.
# Install with: ./scripts/install-hooks.sh
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m' # No color
# Only check if there are staged .rs files
STAGED_RS=$(git diff --cached --name-only --diff-filter=ACM -- '*.rs' || true)
if [ -z "$STAGED_RS" ]; then
exit 0
fi
echo -e "${YELLOW}[pre-commit]${NC} Checking staged Rust files..."
# ── 1. cargo fmt ──────────────────────────────────────────────────────
echo -n " fmt... "
if ! cargo fmt --all -- --check 2>/dev/null; then
echo -e "${RED}FAILED${NC}"
echo ""
echo -e "${RED}Formatting issues found. Run:${NC}"
echo " cargo fmt --all"
echo ""
exit 1
fi
echo -e "${GREEN}ok${NC}"
# ── 2. cargo clippy (default features only — fast) ───────────────────
echo -n " clippy... "
if ! cargo clippy --quiet --features x86 -- -D warnings 2>/dev/null; then
echo -e "${RED}FAILED${NC}"
echo ""
echo -e "${RED}Clippy warnings found. Fix them before committing.${NC}"
echo ""
exit 1
fi
echo -e "${GREEN}ok${NC}"
echo -e "${GREEN}[pre-commit] All checks passed.${NC}"