Skip to content

Instantly share code, notes, and snippets.

@broofa
Forked from wesbos/commit-msg
Created October 28, 2016 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save broofa/c6141e780df9b9c3a0a8bbc973f049be to your computer and use it in GitHub Desktop.
Save broofa/c6141e780df9b9c3a0a8bbc973f049be to your computer and use it in GitHub Desktop.
ESLint 3.0 Git Pre Commit Hook
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.jsx\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do
git show :$file | eslint $file
if [[ $? != 0 ]] ; then
failed=1
fi
done;
if [[ $failed != 0 ]] ; then
echo "🚫🚫🚫 ESLint failed, git commit denied!"
exit $failed
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment