git commit之后自动对代码检查,导致commit报错

报错原因

项目中使用了husky,并且配置了"precommit": "npm run lint"。因此会在你git commit的时候执行npm run lint 也就是eslint --ext .js src test
GIT_DIR/hooks/pre-commit :这个钩子被 git commit 命令调用, 而且可以通过在命令中添加--no-verify 参数来跳过。这个钩子不需要参数,在得到提交消息和开始提交前被调用。如果钩子返回值不是0,那么 git commit命令就会中止执行,即会报如下类似的错误。

报错内容

$ git commit -m "feat:add audit list page"
husky > pre-commit (node v8.11.3)
Stashing changes... [started]
Stashing changes... [skipped]
→ No partially staged files found...
Running linters... [started]
Running tasks for src/*.{js,jsx} [started]
eslint src --max-warnings=0 [started]
eslint src --max-warnings=0 [failed]
→
Running tasks for src/*.{js,jsx} [failed]
→
Running linters... [failed]

× eslint src --max-warnings=0 found some errors. Please fix them and try committ                                ing again.

E:\webStorm\demo\src\assets\iconFont\iconfont.js
1:1      error    Expected an assignment or function call and instead saw an exp                                ression  no-unused-expressions
1:54993  error    Expected an assignment or function call and instead saw an exp                                ression  no-unused-expressions
1:55142  error    Expected an assignment or function call and instead saw an exp                                ression  no-unused-expressions
1:55195  warning  Unexpected use of comma operator                                                                       no-sequences

✖ 15 problems (3 errors, 1 warnings)
husky > pre-commit hook failed (add --no-verify to bypass)

解决办法

  1. 执行npm run lint, 根据提示修改错误(推荐)
  2. git commit -m "" --no-verify 绕过了lint的检查

你可能感兴趣的:(git)