预先提交时是否可以使用ESlint或其他内容禁止单词列表? [英] Is it possible to ban a list of words with ESlint or anything else when pre-commit?

查看:176
本文介绍了预先提交时是否可以使用ESlint或其他内容禁止单词列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用沙哑处理预先提交的东西.

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 hookprecommit.

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:

然后使用赫斯基("Git Hooks Made Easy" ),我们首先编写一个脚本,该脚本与上面博客中显示的脚本完全相同.然后我们可以将钩子本身添加到package.jsonscript中,如下所示:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆