Skip to content

Instantly share code, notes, and snippets.

@shannonwells
Created July 17, 2020 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shannonwells/61af2a797cb26d04980cc5c5ac720365 to your computer and use it in GitHub Desktop.
Save shannonwells/61af2a797cb26d04980cc5c5ac720365 to your computer and use it in GitHub Desktop.
pre-commit hook for nodejs projects in Typescript and Javascript.
#!/bin/bash
export JSNAMES='\.(js|ts)$'
export JSNAMES=$(git diff --cached --name-only --diff-filter=ACM | grep -E $JSNAMES)
function exit_err() { echo "❌ 💔" ; exit 1; }
if [[ ! -z $JSNAMES ]]
then
echo "Examining $JSNAMES"
echo $JSNAMES | xargs npm run format || exit_err
npm run lint || exit_err
echo $JSNAMES | xargs git add
else
echo "nothing to do 😑"
exit 0
fi
echo "✅ 😇"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment