Skip to content

Instantly share code, notes, and snippets.

@ekoneko
Last active June 14, 2017 05:03
Show Gist options
  • Save ekoneko/fb4024c615cea9c586a16f79b12f23ab to your computer and use it in GitHub Desktop.
Save ekoneko/fb4024c615cea9c586a16f79b12f23ab to your computer and use it in GitHub Desktop.
ESLint Pre Commit Check
#!/bin/sh
# ESLint Pre Commit Check
# put to `.git/hooks/pre-commit`
eslint_check() {
files=$(git diff --cached --name-only --diff-filter=AM | grep '\.jsx\?$')
if [[ $files = "" ]] ; then
return
fi
failed=0
for file in ${files}; do
git show :$file | ./node_modules/eslint/bin/eslint.js $file
if [[ $? != 0 ]] ; then
failed=1
fi
done;
if [[ $failed != 0 ]] ; then
echo "🚫 ESLint failed, git commit denied!"
exit $failed
fi
}
eslint_check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment