Search code examples
javascripteslinthusky

Running ESLint in precommit does not stop on warnings


I'm adding some precommit and prepush scripts to my project. I'm using Husky because it keeps tracked on git any change.

On my package.json I have:

"precommit": "npm run lint && npm run test",

Which initially seems to be working fine, when any test or lint error was found I was unable to make the commit.

Now I found that if I have a warning, the commit happens anyway.

How can I configure Husky, or maybe ESLint, to stop the commit when there are warnings?

I know I could override all eslint configs to be always error [2], but I'm expecting there is something better


Solution

  • You need specify --max-warnings param.

    Something like this:

    "scripts": {
      ...
      "lint": "eslint \"**/*.js\" --max-warnings=0",
      ...
    },