Skip to content

Commit aaeb372

Browse files
chore: add git hooks for pre-commit formatting
1 parent 5ac2dbf commit aaeb372

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ htmlcov
1313
.pytest_cache/
1414
.mypy_cache/
1515
.ruff_cache/
16+
*.egg-info
1617

1718
# Visual Studio Code
1819
.vscode/

.hooks/pre-commit

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
set -euo pipefail
2+
3+
# Call block to block the commit with a message.
4+
block() {
5+
echo "$@"
6+
echo "Commit blocked - see errors above."
7+
exit 1
8+
}
9+
10+
# Add all check functions to this space separated list.
11+
# They are executed in this order (see end of file).
12+
CHECKS="fmt lint"
13+
14+
# Run fmt against changed files compared to origin/main
15+
fmt() {
16+
echo "==> Running fmt on all files"
17+
make fmt || block "Formatting failed"
18+
19+
# Re-add any files that were changed by the fixers
20+
git add -u
21+
}
22+
23+
lint() {
24+
echo "==> Running lint on all files"
25+
make lint || block "Linting failed"
26+
27+
# Re-add any files that were changed by the fixers
28+
git add -u
29+
}
30+
31+
for CHECK in $CHECKS; do
32+
# Force each check into a subshell to avoid crosstalk.
33+
( $CHECK ) || exit $?
34+
done

0 commit comments

Comments
 (0)