Last active
June 19, 2019 15:35
-
-
Save curtischong/6f21c7d36391fe51be9443f2b8fc0ffd to your computer and use it in GitHub Desktop.
git pre-commit flake8 cancer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# TODO: Place in .git/hooks/ | |
# TODO: Run chmod +x pre-commit | |
changed-files () { | |
git diff-tree --no-commit-id --name-only -r ${@:-HEAD} | |
} | |
exists () { | |
while read line; do | |
test -f $line && echo $line | |
done | |
} | |
root=$(git rev-parse --show-toplevel) | |
cd $root | |
# To check the flake8 for the file's imports use: --builtins=func_name | |
files=$(changed-files $@ | grep '\.py$' | exists) | |
test -z "$files" || flake8 --ignore=W292,E501,E265,F404,E302,E305 $files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment