[フレーム]
Last Updated: November 07, 2018
·
22.33K
· johannesboyne

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 ;-)

1 Response
Add your 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 ·

AltStyle によって変換されたページ (->オリジナル) /