如何防止 eslint 阻止 git commit?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44933306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent eslint from blocking git commit?
提问by Tevon Strand-Brown
I'm new to eslint and am using it to enforce coding style. However, when I write a 'TODO' item into my code I get an eslint warning, alright thats fine. But, now when I try to git commit, it comes back with:
我是 eslint 的新手,正在使用它来强制执行编码风格。但是,当我在我的代码中写入一个“TODO”项时,我收到了一个 eslint 警告,这很好。但是,现在当我尝试 git commit 时,它返回:
**** ESLint errors found :
line 145, col 9, Warning - Unexpected 'todo' comment. (no-warning-comments)
How can I prevent eslint from blocking me from committing? I want it to still warn me about TODOs etc, but I would like to be able to commit my code as well.
如何防止 eslint 阻止我提交?我希望它仍然警告我关于待办事项等,但我也希望能够提交我的代码。
回答by phd
You have a pre-commit hook.
你有一个预提交钩子。
git commit --no-verify
allows to avoid it once. Or you can remove it completely from .git/hooks.
允许避免它一次。或者您可以从 .git/hooks 中完全删除它。
回答by Tevon Strand-Brown
Solution
解决方案
I navigated to my .git/hooks
directory and found a pre-commit bash script. I changed the return value from 1 to 0 in the case where eslint failed and that solved the problem.
我导航到我的.git/hooks
目录并找到了一个预提交的 bash 脚本。在 eslint 失败的情况下,我将返回值从 1 更改为 0 并解决了问题。
A 0 value represents a pass and will allow the commit to continue, a non-zero represents a fail state and will cancel the commit.
0 值表示通过并允许提交继续,非零值表示失败状态并将取消提交。