2016-05-06 238 views
1

我一直在環顧四周,我可以看到JSLint,JsHint爲Git預提交鉤子示例,但我找不到一個用於TSLint。我試圖適應一個沒有成功。任何幫助真的很感激!TSLint預先掛鉤鉤子

回答

2

你在這裏。它適用於全球安裝的tslint以及控制檯或VS Code Atom。由於某些原因,它不適用於SourceTree,因爲它無法找到您的tslint。如果你想通過Sourcetree使用提交,你需要硬編碼tslint路徑。

#!/bin/sh 
 

 
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep ".tsx\{0,1\}$") 
 

 
if [[ "$STAGED_FILES" = "" ]]; then 
 
    exit 0 
 
fi 
 

 
PASS=true 
 

 
echo "\nValidating Typescript:\n" 
 

 
# Check for tslint 
 
which tslint &> /dev/null 
 
if [[ "$?" == 1 ]]; then 
 
    echo "\t\033[41mPlease install TSlint\033[0m" 
 
    exit 1 
 
fi 
 

 
for FILE in $STAGED_FILES 
 
do 
 
    tslint "$FILE" 
 

 
    if [[ "$?" == 0 ]]; then 
 
    echo "\t\033[32mTSLint Passed: $FILE\033[0m" 
 
    else 
 
    echo "\t\033[41mTSLint Failed: $FILE\033[0m" 
 
    PASS=false 
 
    fi 
 
done 
 

 
echo "\nTypescript validation completed!\n" 
 

 
if ! $PASS; then 
 
    echo "\033[41mCOMMIT FAILED:\033[0m Your commit contains files that should pass TSLint but do not. Please fix the TSLint errors and try again.\n" 
 
    exit 1 
 
else 
 
    echo "\033[42mCOMMIT SUCCEEDED\033[0m\n" 
 
fi 
 

 
exit $?