Skip to content

Instantly share code, notes, and snippets.

@marcellkiss
Created June 17, 2016 12:14
Show Gist options
  • Save marcellkiss/722a2ddc38b5f695e9c3a55becc68a4d to your computer and use it in GitHub Desktop.
Save marcellkiss/722a2ddc38b5f695e9c3a55becc68a4d to your computer and use it in GitHub Desktop.
# NOTES:
# Create this file as: .git/hooks/pre-commit
# Also make it executable
#!/bin/sh
pass=true
RED='\033[1;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo "Running Linters:"
# Run tslint and get the output and return code
tslint=$(npm run tslint)
ret_code=$?
# If it didn't pass, announce it failed and print the output
if [ $ret_code != 0 ]; then
printf "\n${RED}tslint failed:${NC}"
echo "$tslint\n"
pass=false
else
printf "${GREEN}tslint passed.${NC}\n"
fi
# Run stylelint and get the output and return code
stylelint=$(npm run stylelint)
ret_code=$?
if [ $ret_code != 0 ]; then
printf "${RED}stylelint failed:${NC}"
echo "$stylelint\n"
pass=false
else
printf "${GREEN}stylelint passed.${NC}\n"
fi
# If there were no failures, it is good to commit
if $pass; then
exit 0
fi
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment