预先提交时是否可以使用ESlint或其他内容禁止单词列表? [英] Is it possible to ban a list of words with ESlint or anything else when pre-commit?
问题描述
我正在用沙哑处理预先提交的东西.
I am using husky to deal with the pre-commit thing.
所以在这里,我希望新编写的程序不应包含单词列表,例如dangerouslySetInnerHTML
等.
So here I want that the newly written program should not contain a list of words, like dangerouslySetInnerHTML
, etc.
我知道eslint-plugin-react中有一条规则no-danger
,但是它只能阻止一个单词.如何在文件中写入单词列表并将其用作过滤器?
I know there is a rule no-danger
in eslint-plugin-react, but it only prevents that one word. How can I write a list of words in a file and use it as a filter?
推荐答案
所以我终于自己解决了这个问题.
So I finally solved this problem myself.
解决方案在于利用其中之一的git hook
和precommit
.
The solution lies in taking advantage of git hook
and the precommit
, which is one of those.
在这里实现这一目标的好资源:
A good resource of achieving this is here:
And with Husky, which is "Git Hooks Made Easy", we first write a script, which is exactly like what has been showed in the blog above. Then we can add the hook itself in the script
of package.json
, which is like this:
"script": {
"precommit": "./pre-commit.sh"
}
这意味着每次提交时,都会先运行pre-commit
脚本.这样就可以过滤掉不需要的单词.
This means everytime you commit, the pre-commit
script will be run first. And thus you can filter the words that are undesired.
这篇关于预先提交时是否可以使用ESlint或其他内容禁止单词列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!