如何在tslint中添加git prehook?

hus*_*ain 0 git node.js tslint

我正在尝试添加prehook,如果代码无法提交任何棉绒问题。什么是实现它的正确方法。

tslint.sh

#!/bin/sh
sh ./npm-install.sh
if [ $? -ne 0 ]; then
  echo "npm-install error, exiting.."
  exit 1
fi
echo "Running ts lint"
npm run lint
if [ $? -ne 0 ]; then
  echo "Unit tests error, exiting.."
  exit 1
fi
Run Code Online (Sandbox Code Playgroud)

dee*_*wan 7

我在以下方面具有成功的实施经验:

  1. husky =>指定git hook
  2. lint-staged =>运行命令以在git中暂存文件(因此无需对所有文件运行tslint)

参考:

  1. https://github.com/okonet/lint-staged
  2. https://www.npmjs.com/package/husky

package.json指定lint-stagedpre-commithusky现场:

"dependencies": ...,
"devDependencies": ...,
"scripts" ...,
"husky": {
    "hooks": {
        "pre-commit": "lint-staged"
    }
},
"lint-staged": {
    "*.ts": [ // target to all typescript files in staged stage in git
      "npm run lint", // your lint command
      "git add"   
    ]
}
Run Code Online (Sandbox Code Playgroud)