Skip to content

Instantly share code, notes, and snippets.

@pgilad
Created June 30, 2015 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pgilad/2b368d8a3bd815ba9968 to your computer and use it in GitHub Desktop.
Save pgilad/2b368d8a3bd815ba9968 to your computer and use it in GitHub Desktop.
Precommit git hook
#!/bin/sh
JS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E "(.js|.es6)$")
if [ "$JS_FILES" = "" ]; then
exit 0
fi
pass=true
for file in $JS_FILES; do
./node_modules/.bin/jscs --config .jscsrc "$file"
if [ $? -ne 0 ]; then
pass=false
fi
./node_modules/.bin/jshint --config .jshintrc "$file"
if [ $? -ne 0 ]; then
pass=false
fi
done
if [ "$pass" = true ]; then
exit 0
else
echo "\033[41mCOMMIT FAILED:\033[0m Aborting commit due to errors"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment