2

我正在使用 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 "$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
}
4

1 回答 1

0

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

于 2018-01-15T08:03:53.943 回答