Skip to content

Instantly share code, notes, and snippets.

@irvinlim
Last active August 29, 2024 10:52
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=`echo "$staged" | grep '.py$'`
else
target=`git diff --name-only | cat | grep '.py'`
fi
if [ "$target" ]
then
$pylint "$target"
fi
@irvinlim
Copy link
Author

Great, thanks for the find~

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