pre-commit hook: fix shellcheck's SC2086 & SC2181

This commit is contained in:
Martin Pépin 2018-10-06 15:50:49 +02:00
parent 61fbf0bc80
commit 9bc3355a21

View file

@ -17,18 +17,18 @@ STAGED_PYTHON_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".p
printf "> black ... " printf "> black ... "
if type black &>/dev/null; then if type black &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n" printf "OK\n"
else else
BLACK_OUTPUT="/tmp/gc-black-output.log" BLACK_OUTPUT="/tmp/gc-black-output.log"
touch $BLACK_OUTPUT touch $BLACK_OUTPUT
black --check $STAGED_PYTHON_FILES &>$BLACK_OUTPUT
printf "OK\n"
if [ $? -ne 0 ]; then if ! black --check "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT; then
black $STAGED_PYTHON_FILES &>$BLACK_OUTPUT black "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT
tail -1 $BLACK_OUTPUT tail -1 $BLACK_OUTPUT
formatter_updated=1 formatter_updated=1
else
printf "OK\n"
fi fi
fi fi
else else
@ -41,18 +41,18 @@ fi
printf "> isort ... " printf "> isort ... "
if type isort &>/dev/null; then if type isort &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n" printf "OK\n"
else else
ISORT_OUTPUT="/tmp/gc-isort-output.log" ISORT_OUTPUT="/tmp/gc-isort-output.log"
touch $ISORT_OUTPUT touch $ISORT_OUTPUT
isort --check-only $STAGED_PYTHON_FILES &>$ISORT_OUTPUT
printf "OK\n"
if [ $? -ne 0 ]; then if ! isort --check-only "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT; then
isort $STAGED_PYTHON_FILES &>$ISORT_OUTPUT isort "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT
printf "Reformatted.\n" printf "Reformatted.\n"
formatter_updated=1 formatter_updated=1
else
printf "OK\n"
fi fi
fi fi
else else
@ -65,19 +65,18 @@ fi
printf "> flake8 ... " printf "> flake8 ... "
if type flake8 &>/dev/null; then if type flake8 &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n" printf "OK\n"
else else
FLAKE8_OUTPUT="/tmp/gc-flake8-output.log" FLAKE8_OUTPUT="/tmp/gc-flake8-output.log"
touch $FLAKE8_OUTPUT touch $FLAKE8_OUTPUT
flake8 $STAGED_PYTHON_FILES &>$FLAKE8_OUTPUT
if [ $? -eq 0 ]; then if ! flake8 "$STAGED_PYTHON_FILES" &>$FLAKE8_OUTPUT; then
printf "OK\n"
else
printf "FAIL\n" printf "FAIL\n"
cat $FLAKE8_OUTPUT cat $FLAKE8_OUTPUT
checker_dirty=1 checker_dirty=1
else
printf "OK\n"
fi fi
fi fi
else else