-
-
Save quangnd/0e7d8ffdd589992e8cbd94d2f8cfb4ec to your computer and use it in GitHub Desktop.
ESLint git commit hook
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 | |
files=$(git diff --cached --name-only | grep '\.js$') | |
# Prevent ESLint help message if no files matched | |
if [[ $files = "" ]] ; then | |
exit 0 | |
fi | |
echo $files | xargs eslint | |
rc=$? | |
if [[ $rc != 0 ]] ; then | |
echo "ESLint check failed, commit denied" | |
exit $rc | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recommend automating ESLint to your git commits. This way you will never commit in code that doesn't pass a check.
I've created an example git hook that you can use.
Download the git hook
Place the file into .git/hooks/commit-msg. This should be where you created or cloned your git repository
Now whenever you commit, ESLint will run and check any .js files for issues. If ESLint finds any issues, it will block the commit.