1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-12 19:09:56 +03:00

add pre-commit hook for ruff (MR 2485)

Add a pre-commit hook that runs ruff.sh and tells you how to auto-fix
issues, add a section to CONTRIBUTING.md to document it.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-11-12 01:53:09 +01:00 committed by Oliver Smith
parent 314cc81016
commit ebed7abe4f
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
2 changed files with 27 additions and 0 deletions

15
.ci/hooks/pre-commit Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh -e
DID_FAIL=0
if ! git diff --staged --name-only --diff-filter=ACM | grep -qE '\.py$'; then
echo "[pre-commit] No Python files to check."
exit 0
fi
if ! .ci/ruff.sh; then
echo "[pre-commit] ruff failed. Fix it with:"
echo
echo "ruff check --fix && ruff format"
exit 1
fi

View file

@ -37,6 +37,18 @@ This is a reST style.
"""
```
#### Linting
To avoid having to fight with ruff in CI, it's recommended to enable a
pre-commit hook to run it automatically before you commit. This drastically
streamlines interacting with ruff.
Enable the git hook with:
```sh
ln -sf ../../.ci/hooks/pre-commit .git/hooks/pre-commit
```
### Shell scripts
* Must be POSIX compliant, so busybox ash can interpret them. (Exception: the