js linting script for precommit hook

This commit is contained in:
Joshua Seigler 2017-06-06 02:48:46 -04:00 committed by mr.wong
parent 3e0612cf14
commit 8c55cdd3d5

17
_tests/git hooks/precommit Executable file
View file

@ -0,0 +1,17 @@
#!/bin/bash
jsfiles=$(git diff --cached --name-only --diff-filter=M | grep '\.js\?$')
jsfailed=0
if [[ $jsfiles != "" ]] ; then
for file in ${jsfiles}; do
git show :$file | eslint --stdin --stdin-filename "$file"
if [[ $? != 0 ]] ; then
jsfailed=1
fi
done;
fi
if [[ $jsfailed != 0 ]] ; then
echo "🚫🚫🚫ESLint must pass before committing .js files"
exit 1
fi