Skip to content

Instantly share code, notes, and snippets.

@andymckay
Created April 24, 2013 02:01
Show Gist options
  • Save andymckay/5449026 to your computer and use it in GitHub Desktop.
Save andymckay/5449026 to your computer and use it in GitHub Desktop.
for file in `git diff-tree --no-commit-id --name-only -r HEAD | sort | uniq`
do
if [ ${file: -3} == ".py" ]
then
flake8 --ignore=E121,E123,E124,E125,E126,E127,E128 $file
fi
if [ ${file: -3} == ".js" ]
then
jshint $file
fi
done
@pmclanahan
Copy link

To get it to work as a pre-commit hook that would abort the commit on errors I had to do the following:

#!/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

how do you use yours?

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