Last active
April 20, 2016 22:16
-
-
Save rjz/1483c68a37efa2dcaa39ee88ea26c0c4 to your computer and use it in GitHub Desktop.
pre-push hook for linting JS / CoffeeScript
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 | |
set -e | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
FILENAME="$( basename "${BASH_SOURCE[0]}" )" | |
PROJECTDIR="$(readlink "${DIR}/../..")" # $DIR == ${PROJECTDIR}/.git/hooks | |
log () { | |
echo -e "\e[90m[`date -u +"%Y-%m-%dT%H:%M:%SZ"`]\e[39m - \e[36m$FILENAME\e[39m - $1" | |
} | |
diff_files_by_ext () { | |
git diff-tree --no-commit-id --name-only -r master HEAD | grep "\.${1}$" | |
} | |
log 'jshint-ing .js files' | |
jshint `diff_files_by_ext js` | |
log 'coffeelint-ing .coffee files' | |
for f in `diff_files_by_ext coffee`; do | |
coffeelint -f "${PROJECTDIR}coffeelint.json" $f; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment