Last active
April 28, 2021 14:27
-
-
Save mroderick/333f5a1615042ddf5953 to your computer and use it in GitHub Desktop.
My current git pre-commit hook script for linting staged changes with ESLint
This file contains hidden or 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 | |
# if there are no staged changes, we can exit immediately | |
# this is fast and prevents issues when popping a stash we didn't create | |
STAGED_CHANGES=`git diff-index --cached HEAD --name-only --diff-filter ACMR` | |
if [ -z "$STAGED_CHANGES" ]; then | |
exit 0 | |
fi | |
git stash -q --keep-index | |
# Test prospective commit | |
git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.js$' | xargs $(npm bin)/eslint | |
RESULT=$? | |
git stash pop -q | |
[ $RESULT -ne 0 ] && exit 1 | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment