'Is it possible to use Husky + lint stages to check for Console.logs?

Just wondering if it’s possible to use husky/lint stages to check for console logs during a pre-commit and fail if there are console logs? I couldn’t find anything specific to console logs.



Solution 1:[1]

this will verify if has some console.log in your code.

in your .eslintrc put this guy

"no-console": "error",

and in the husky file:

 {
      "hooks": {
        "pre-commit": "lint-staged",
        "pre-push": "yarn test:coverage"
      }
    }

Solution 2:[2]

You can do it in two ways:

  1. in .eslintrc.js file:
    module.exports = {
      plugins: ["security"],
      rules: {
        "no-console": ENV === "production" ? "error" : "off",
        "no-debugger": ENV === "production" ? "error" : "off"
      }
    }
    
  1. In .git/hooks/pre-commit file:

you can paste this code https://gist.github.com/guilherme/9604324#file-gistfile1-sh

Difference is that you can commit *.eslintrc.js* file but *pre-commit* is only for you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Filipe Prado
Solution 2 Nimish