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

tslint precommit hook shows all the linting errors before but also allows to commit the code

我正在使用 angular-seed & husky 为 git 添加预提交挂钩。我的 package.json 有

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

当我提交代码时,husky 运行 "npm test" & "npm run lint" 正常。当 npm test 失败时,它会在控制台上显示错误并且不允许我提交。但是当 "npm run lint" 上有错误时,控制台会显示所有错误消息,但也允许提交。当出现 linting 错误时如何避免提交?任何帮助表示赞赏。先感谢您! 这就是我的 .git\hooks\pre-commit 的样子:

#!/bin/sh
#husky 0.14.3

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

has_hook_script () {
  [ -f package.json ] && cat package.json | grep -q "\"\"[[: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
}

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