Is it possible to ban a list of words with ESlint or anything else when pre-commit?
Asked Answered
V

2

2

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 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?

Vang answered 20/6, 2017 at 3:23 Comment(0)
V
2

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.

Vang answered 22/6, 2017 at 13:53 Comment(0)
C
0

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.

Caretaker answered 20/6, 2017 at 3:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.