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
Filed Under
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#