tslint precommit hook显示之前的所有linting错误,但也允许提交代码

时间:2018-01-12 12:31:15

标签: githooks tslint pre-commit-hook pre-commit git-husky

我正在使用angular-seed&哈士奇为git添加一个precommit hook。我的package.json有

"scripts": {
    "precommit": "npm test && npm run lint",
  }

当我提交代码时,赫斯基运行“npm test”& “npm run lint”很好。当npm测试失败时,它会向我显示控制台上的错误。不允许我承诺。但是当“npm run lint”出现错误时,控制台会显示所有错误消息,但也允许提交。当有linting错误时如何避免提交?任何帮助表示赞赏。先感谢您! 这就是我的.git \ hooks \ pre-commit看起来的样子:

#!/bin/sh
#husky 0.14.3

command_exists () {
  command -v "$1" >/dev/null 2>&1
}

has_hook_script () {
  [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:"
}

cd "."

# Check if precommit script is defined, skip if not
has_hook_script precommit || exit 0

# Node standard installation
export PATH="$PATH:/c/Program Files/nodejs"

# Check that npm exists
command_exists npm || {
  echo >&2 "husky > can't find npm in PATH, skipping precommit script in package.json"
  exit 0
}

# Export Git hook params
export GIT_PARAMS="$*"

# Run npm script
echo "husky > npm run -s precommit (node `node -v`)"
echo

npm run -s precommit || {
  echo
  echo "husky > pre-commit hook failed (add --no-verify to bypass)"
  exit 1
}

1 个答案:

答案 0 :(得分:0)

seed.config.ts中,您应该有一个名为FORCE_TSLINT_EMIT_ERROR的布尔值。在project.config.ts中明确地将此变量的值覆盖为true。