Last active
August 29, 2024 10:52
-
-
Save irvinlim/814690ad3bbb254b52224416a36bba61 to your computer and use it in GitHub Desktop.
Git pre-commit hook for Pylint
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 | |
## | |
## 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great, thanks for the find~