Skip to content

Instantly share code, notes, and snippets.

@clinyong
Last active January 22, 2017 14:07
Show Gist options
  • Save clinyong/4e18ae44517be6906c9972433d44d7be to your computer and use it in GitHub Desktop.
Save clinyong/4e18ae44517be6906c9972433d44d7be to your computer and use it in GitHub Desktop.
use tslint to check ts or tsx file before commit
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E "\.tsx?$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
for file in ${files}; do
result=$(./node_modules/.bin/tslint ${file})
if [[ $result != "" ]]; then
pass=false
echo $result
fi
done
if ! $pass; then
echo "\033[91mCOMMIT FAILED:\033[0m Your commit contains files that should pass TSLint but do not. Please fix the TSLint errors and try again."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment