Skip to content

Commit c6d6292

Browse files
committed
Add shared pre-commit hook: ruff format + ruff check
1 parent 1871dbe commit c6d6292

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/installation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ cd dapi
4242
pip install -e .
4343
```
4444

45+
### Set up pre-commit hook
46+
47+
The repo includes a pre-commit hook that auto-formats with `ruff format` and blocks commits that fail `ruff check`:
48+
49+
```bash
50+
cp scripts/pre-commit .git/hooks/pre-commit
51+
chmod +x .git/hooks/pre-commit
52+
```
53+
4554
## Update
4655

4756
```bash

scripts/pre-commit

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
# Auto-format and lint with ruff before committing
3+
ruff format . 2>/dev/null || .venv/bin/ruff format .
4+
git add -u
5+
6+
# Lint check — blocks commit on failure
7+
if ruff check . 2>/dev/null; then
8+
exit 0
9+
elif .venv/bin/ruff check . 2>/dev/null; then
10+
exit 0
11+
else
12+
echo ""
13+
echo "Commit blocked: ruff check found errors. Fix them and try again."
14+
exit 1
15+
fi

0 commit comments

Comments
 (0)