Skip to content

Instantly share code, notes, and snippets.

@irvinlim
Created June 28, 2018 08:50
Show Gist options
  • Save irvinlim/814690ad3bbb254b52224416a36bba61 to your computer and use it in GitHub Desktop.
Save irvinlim/814690ad3bbb254b52224416a36bba61 to your computer and use it in GitHub Desktop.
Git pre-commit hook for Pylint
#!/bin/bash
##
## Pylint Git Pre-commit Hook
##
## Supports linting only staged files, or otherwise defaults to all changed files.
## Add this script in `.git/hooks/pre-commit`.
staged=`git diff --name-only --cached --diff-filter=A --diff-filter=M | cat`
pylint=".venv/bin/pylint --rcfile .pylintrc --load-plugins pylint_django --load-plugins pylint_quotes --reports=no"
if [ "$staged" ]
then
target=`cat "$staged" | grep '.py$'`
else
target=`git diff --name-only | cat | grep '.py'`
fi
if [ "$target" ]
then
$pylint "$target"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment