我正在尝试添加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

最佳答案

我有以下成功的实现经验:


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


参考:


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


package.json中,在lint-staged字段中指定pre-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"
    ]
}

关于node.js - 如何在tslint中添加git prehook?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51141949/

10-13 09:38