-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·47 lines (39 loc) · 1.17 KB
/
Copy pathpre-commit
File metadata and controls
executable file
·47 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# pre-commit — runs the same checks as CI locally before each commit.
# Install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
# or: ln -sf ../../scripts/pre-commit .git/hooks/pre-commit
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
pass() { echo -e "${GREEN}✓${NC} $1"; }
fail() { echo -e "${RED}✗${NC} $1"; exit 1; }
warn() { echo -e "${YELLOW}!${NC} $1"; }
echo "Running pre-commit checks..."
echo ""
# 1. Format check
echo "── cargo fmt ──"
if cargo fmt --all -- --check 2>/dev/null; then
pass "Formatting OK"
else
echo " Auto-formatting..."
cargo fmt --all
pass "Formatting fixed (review the changes)"
fi
# 2. Clippy lints
echo "── cargo clippy ──"
if cargo clippy --all -- -D warnings 2>/dev/null; then
pass "Clippy OK"
else
fail "Clippy found warnings — fix them before committing"
fi
# 3. Quick test (lib tests only — skips slow integration/WASM tests)
echo "── cargo test (lib only) ──"
if cargo test --lib 2>/dev/null; then
pass "Lib tests OK"
else
fail "Lib tests failed"
fi
echo ""
echo -e "${GREEN}All pre-commit checks passed.${NC}"