Add linting pre-commit hook and hook install script
continuous-integration/drone/pr Build is passing
Details
continuous-integration/drone/pr Build is passing
Details
This commit is contained in:
parent
c0c9736593
commit
da51c4309c
|
@ -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 $?
|
|
@ -0,0 +1,4 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Install pre-configured git hooks
|
||||||
|
git config --local core.hooksPath .githooks/
|
Loading…
Reference in New Issue