Revamp formatting and linting on commit

Remove the prepare script, and run the two stages manually. Better
handle Black reformatting by doing a check (for the errcode) then
reformat and abort commit to review.
This commit is contained in:
Joshua Boniface 2021-11-06 13:34:33 -04:00
parent 21b4bbe51a
commit 0cc3f2deab
4 changed files with 16 additions and 10 deletions

View File

@ -4,9 +4,16 @@ pushd $( git rev-parse --show-toplevel ) &>/dev/null
ex=0 ex=0
./prepare ./format check
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
echo "Aborting commit due to formatting or linting errors." ./format
echo "Black formatting change detected; review and recommit"
ex=1
fi
./lint
if [[ $? -ne 0 ]]; then
echo "Linting error detected; correct and recommit"
ex=1 ex=1
fi fi

View File

@ -32,7 +32,8 @@ pushd $( git rev-parse --show-toplevel ) &>/dev/null
# Prepare code # Prepare code
echo "Preparing code (format and lint)..." echo "Preparing code (format and lint)..."
./prepare || exit ./format || exit 1
./lint || exit 1
# Build the packages # Build the packages
echo -n "Building packages... " echo -n "Building packages... "

6
format
View File

@ -5,10 +5,14 @@ if ! which black &>/dev/null; then
exit 1 exit 1
fi fi
if [[ $1 == "check" ]]; then
check="--check"
fi
pushd $( git rev-parse --show-toplevel ) &>/dev/null pushd $( git rev-parse --show-toplevel ) &>/dev/null
echo "Formatting..." echo "Formatting..."
black --safe --exclude api-daemon/migrations . black --safe ${check} --exclude api-daemon/migrations .
ret=$? ret=$?
if [[ $ret -eq 0 ]]; then if [[ $ret -eq 0 ]]; then
echo "Successfully formatted project!" echo "Successfully formatted project!"

View File

@ -1,6 +0,0 @@
#!/usr/bin/env bash
#set -o errexit
./format
./lint