Skip to content

Instantly share code, notes, and snippets.

@logicaroma
Forked from pgilad/pre-commit
Created November 1, 2015 20:21
Show Gist options
  • Save logicaroma/b1bb751c458d76246062 to your computer and use it in GitHub Desktop.
Save logicaroma/b1bb751c458d76246062 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