-
Notifications
You must be signed in to change notification settings - Fork 15
Git Hooks
Evan Louie edited this page Jul 11, 2017
·
4 revisions
Runs ESLint against changed \.jsx?$\
files and only allows the commit if no lint errors found.
./git/hooks/pre-commit
:
#!/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 | ./node_modules/prettier/bin/prettier.js $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