eslint pre-commit hook
eslint pre-commti hook
#!/bin/zsh
function lintit () {
OUTPUT=$(git diff --name-only | grep -E '(.js)$')
a=("${(f)OUTPUT}")
e=$(eslint -c eslint.json $a)
echo $e
if [[ "$e" != *"0 problems"* ]]; then
echo "ERROR: Check eslint hints."
exit 1 # reject
fi
}
lintit
If you want to store the eslint.json config file at a different path, just change it inside the script ;-)
Written by Johannes Boyne
Related protips
1 Response
This doesn't seem to compare the file that exists within the git index, but rather within the working directory.
A condition could exist that the working directory lints perfectly, but the file within the git index is dirty.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Coffeescript
Authors
iam4x
94.17K
ericdfields
63.02K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#