Search code examples
javascriptgiteslinthusky

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


Solution

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