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 ... "
if type black &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
BLACK_OUTPUT="/tmp/gc-black-output.log"
touch $BLACK_OUTPUT
black --check $STAGED_PYTHON_FILES &>$BLACK_OUTPUT
printf "OK\n"
if [ $? -ne 0 ]; then
black $STAGED_PYTHON_FILES &>$BLACK_OUTPUT
if ! black --check "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT; then
black "$STAGED_PYTHON_FILES" &>$BLACK_OUTPUT
tail -1 $BLACK_OUTPUT
formatter_updated=1
else
printf "OK\n"
fi
fi
else
@ -41,18 +41,18 @@ fi
printf "> isort ... "
if type isort &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
ISORT_OUTPUT="/tmp/gc-isort-output.log"
touch $ISORT_OUTPUT
isort --check-only $STAGED_PYTHON_FILES &>$ISORT_OUTPUT
printf "OK\n"
if [ $? -ne 0 ]; then
isort $STAGED_PYTHON_FILES &>$ISORT_OUTPUT
if ! isort --check-only "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT; then
isort "$STAGED_PYTHON_FILES" &>$ISORT_OUTPUT
printf "Reformatted.\n"
formatter_updated=1
else
printf "OK\n"
fi
fi
else
@ -65,19 +65,18 @@ fi
printf "> flake8 ... "
if type flake8 &>/dev/null; then
if [ -z $STAGED_PYTHON_FILES ]; then
if [ -z "$STAGED_PYTHON_FILES" ]; then
printf "OK\n"
else
FLAKE8_OUTPUT="/tmp/gc-flake8-output.log"
touch $FLAKE8_OUTPUT
flake8 $STAGED_PYTHON_FILES &>$FLAKE8_OUTPUT
if [ $? -eq 0 ]; then
printf "OK\n"
else
if ! flake8 "$STAGED_PYTHON_FILES" &>$FLAKE8_OUTPUT; then
printf "FAIL\n"
cat $FLAKE8_OUTPUT
checker_dirty=1
else
printf "OK\n"
fi
fi
else