Add linting pre-commit hook and hook install script #86

Merged
merenber merged 6 commits from feature-80 into master 2023-05-29 00:14:06 -04:00
2 changed files with 8 additions and 28 deletions
Showing only changes of commit 7cec1425b3 - Show all commits

View File

@ -1,12 +1,5 @@
#!/bin/bash
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py\{0,1\}$")
docker run --rm -v "$PWD:$PWD:z" -w "$PWD" python:3.9-bullseye sh -c './lint-docker.sh'
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
docker run --rm -v "$PWD:$PWD:z" -w "$PWD" -e "STAGED_FILES=$STAGED_FILES" python:3.7-buster sh -c './lint-docker.sh "$STAGED_FILES"'
RUN_STATUS=$?
exit $RUN_STATUS
exit $?

View File

@ -2,30 +2,17 @@
. venv/bin/activate
STAGED_FILES="$1"
echo "STAGED_FILES: $STAGED_FILES"
echo -e "\nLinting Python files with Flake8:\n"
PASS=true
while IFS= read -r FILE; do
flake8 "$FILE"
if [[ "$?" != 0 ]]; then
PASS=false
fi
# echo "Linted $FILE"
done <<< "$STAGED_FILES"
flake8
PASS=$?
echo -e "\nPython linting complete!\n"
if ! $PASS; then
if [ "$PASS" -eq 0 ]; then
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
exit $?
else
echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass flake8 but do not. Please fix the flake8 errors and try again.\n"
exit 1
else
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
exit $?