Skip to content

Instantly share code, notes, and snippets.

@pmclanahan
Created May 23, 2014 23:01
Show Gist options
  • Save pmclanahan/dae038bc2a5870907efd to your computer and use it in GitHub Desktop.
Save pmclanahan/dae038bc2a5870907efd to your computer and use it in GitHub Desktop.
Flake8 and jshint pre-commit git hook
#!/bin/sh
exit_code=0
for file in `git diff --cached --name-only --diff-filter=ACM | sort | uniq`
do
if [ ${file: -3} == ".py" ]; then
flake8 --ignore=E121,E123,E124,E125,E126,E127,E128,E501 $file
if [ "$?" -ne "0" ]; then
exit_code=1
fi
fi
if [ ${file: -3} == ".js" ]; then
jshint $file
if [ "$?" -ne "0" ]; then
exit_code=1
fi
fi
done
if [ "$exit_code" -ne "0" ]; then
echo "Aborting commit. Fix above errors or do 'git commit --no-verify'."
exit 1
fi
@andymckay
Copy link

I also have baked in there for python files to check import order, but its pretty much the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment