Created
June 26, 2014 16:48
-
-
Save jfaissolle/c4d8a35b7ebd257df7ab to your computer and use it in GitHub Desktop.
Git Update Hook for running ESLint on updated files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
EXIT_CODE=0 | |
REFNAME="$1" | |
OLDREV="$2" | |
NEWREV="$3" | |
# find file which have been Added, Copied, Modified or Renamed | |
UPDATED=`git diff-tree --diff-filter=ACMR --name-only $OLDREV $NEWREV | grep -e '\.js$'` | |
echo "------------------------------------------------------------------------" | |
echo "Files to Lint:" | |
echo "------------------------------------------------------------------------" | |
echo "$UPDATED" | |
echo "------------------------------------------------------------------------" | |
echo | |
echo "------> Linting....." | |
echo | |
echo | |
# make tmp dir | |
TMP_DIR=`mktemp -d` | |
ESLINTRC=$TMP_DIR/.eslintc | |
# extract .eslintrc file | |
git cat-file blob $NEWREV:.eslintrc > $ESLINTRC | |
# extract all updated files | |
for FILE in $UPDATED; | |
do | |
FILE_PATH=`dirname $FILE` | |
FULL_PATH=$TMP_DIR/$FILE_PATH | |
mkdir -p $FULL_PATH | |
git cat-file blob $NEWREV:$FILE > $TMP_DIR/$FILE | |
done | |
# Run ESLint | |
eslint $TMP_DIR | |
EXIT_CODE=$? | |
# Cleanup | |
rm -rf $TMP_DIR | |
echo | |
echo | |
echo "DONE" | |
exit $EXIT_CODE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment