Skip to content

Instantly share code, notes, and snippets.

@kgalli
Last active November 26, 2016 19:08
Show Gist options
  • Save kgalli/0781f213d5687f76fb8f903984967f42 to your computer and use it in GitHub Desktop.
Save kgalli/0781f213d5687f76fb8f903984967f42 to your computer and use it in GitHub Desktop.
Script to put under .git/hooks to run Eslint on all files which are going to be commited
#!/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 ${file}; 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