Add linting pre-commit hook and hook install script
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Justin Chung 2022-11-19 18:35:40 -05:00
parent c0c9736593
commit da51c4309c
Signed by: j24chung
GPG Key ID: F010CF575BA74CC3
2 changed files with 45 additions and 0 deletions

41
.githooks/pre-commit Executable file
View File

@ -0,0 +1,41 @@
#!/bin/sh
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".py\{0,1\}$")
if [[ "$STAGED_FILES" = "" ]]; then
exit 0
fi
PASS=true
# Check for flake8
which flake8 &> /dev/null
if [[ "$?" == 1 ]]; then
echo -e "\t\033[41mPlease install flake8\033[0m"
exit 1
fi
echo -e "\nLinting Python with Flake8:\n"
for FILE in $STAGED_FILES
do
flake8 "$FILE"
if [[ "$?" == 0 ]]; then
echo -e "\t\033[32mPassed: $FILE\033[0m"
else
echo -e "\t\033[41mFailed: $FILE\033[0m"
PASS=false
fi
done
echo -e "\nPython linting complete!\n"
if ! $PASS; then
echo -e "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass ESLint but do not. Please fix the ESLint errors and try again.\n"
exit 1
else
echo -e "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
exit $?

4
git-hook-install.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# Install pre-configured git hooks
git config --local core.hooksPath .githooks/