Skip to content Skip to sidebar Skip to footer

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. So here I want that the newly written program should not contain a list of words, like dangerouslySetInnerHTML, etc. I know the

Solution 1:

So I finally solved this problem myself.

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:

Pre-commit Git Hook that Prevents Commits with Undesired Words

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"
}

This means everytime you commit, the pre-commit script will be run first. And thus you can filter the words that are undesired.


Solution 2:

This is possible, You should be able to write a new Eslint rule that takes in an array of prohibited words then run Eslint in a pre-commit script. I've done this using a git pre-commit script (not sure about husky, sorry). For a starting point I would look at eslint-plugin-jasmine. The no focused test rule sets a list of prohibited words (ddescribe, iit, fdescribe, and fit) and checks code for these words. You could do the same thing but change the prohibited array to contain the words you want to ban.


Post a Comment for "Is It Possible To Ban A List Of Words With Eslint Or Anything Else When Pre-commit?"