Skip to content

Instantly share code, notes, and snippets.

@pmclanahan
Created May 23, 2014 23:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
@pmclanahan
Copy link
Author

Instead of including ignores and whatnot in the flake8 call above, it's better to add it to a config file in your project like a setup.cfg, like the one for basket.

@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