Skip to content

Instantly share code, notes, and snippets.

@wesvetter
Created June 8, 2017 18:24
Show Gist options
  • Save wesvetter/376007d05943a1dfc6bdda5a0d61e7cd to your computer and use it in GitHub Desktop.
Save wesvetter/376007d05943a1dfc6bdda5a0d61e7cd to your computer and use it in GitHub Desktop.
git pre-commit hook to lint staged CoffeeScript files
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".coffee$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo "\nLinting Coffeescript:\n"
for file in ${files}; do
coffeelint ${file}
result=$?
if [ "$result" == "0" ]; then
echo "\t\033[32mcoffeelint Passed: ${file}\033[0m"
else
echo "\t\033[31mcoffeelint Failed: ${file}\033[0m"
pass=false
fi
done
echo "\nCoffeescript linting complete\n"
if ! $pass; then
echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass coffeelint but do not. Please fix the coffeelint errors and try again.\n"
exit 1
else
echo "\033[42mCOMMIT SUCCEEDED\033[0m\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment