Last Updated: November 07, 2018
·
21.23K
· 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 ·

Have a fresh tip? Share with Coderwall community!

Post
Post a tip