Created
February 6, 2015 17:46
-
-
Save jhartikainen/36a955f3bfe06557e16e 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
One liner for using at
package.json
:"lint-staged": "eslint `git diff --staged --diff-filter=AM --name-only | grep .js$ | tr '\n' ' '`"
It runs like
eslint [file1] [file2] [file3] [etc]
for all staged added/modified files