zq8jlq
Last Updated: November 07, 2017
·
6.656K
· johannesboyne
100 2223

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

Say Thanks
Respond

1 Response
Add your response

29412

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.

3 months ago ·