Skip to content

Instantly share code, notes, and snippets.

@guilhermejcgois
Created September 28, 2017 02:24
Show Gist options
  • Save guilhermejcgois/646348b2731c829ff156e74e1b96cb83 to your computer and use it in GitHub Desktop.
Save guilhermejcgois/646348b2731c829ff156e74e1b96cb83 to your computer and use it in GitHub Desktop.
Run lint on typescript files before commit (under test)
#!/bin/bash
# Based on: https://github.com/observing/pre-commit/issues/50
# Stash modified files, but keep the index tree
git stash -q --keep-index
# 1. Run diff for tree index withtou create a new index tree, showing only files names and iff the file was added or copied or deleted or renamed.
# 2. Grep only for .ts files
# 3. Execute tslint for each file that was modified with type checking enabled
git diff-index --cached HEAD --name-only --diff-filter ACMR | egrep '.ts$' | xargs $(npm bin)/tslint -p tsconfig.json --type-check
RESULT=$?
# Undo stashing
git stash pop -q
[ $RESULT -ne 0 ] && exit 1
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment