Skip to content

Instantly share code, notes, and snippets.

@mertkahyaoglu
Created January 4, 2019 14:11
Show Gist options
  • Save mertkahyaoglu/4919cd58b6aecaac7052c49abaf9542d to your computer and use it in GitHub Desktop.
Save mertkahyaoglu/4919cd58b6aecaac7052c49abaf9542d to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
# allow being run from somewhere other than the git rootdir
gitroot=$(git rev-parse --show-cdup)
# default gitroot to . if we're already at the rootdir
gitroot=${gitroot:-.};
nm_bin=$gitroot/node_modules/.bin
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".jsx\{0,1\}$") || files=""
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
echo "There is no file to lint"
exit 0
fi
$nm_bin/eslint $files
echo "Changed files are linted, commit correct!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment