DEV Community

Cover image for no dislocation = no-undef
Peter Vivo
Peter Vivo

Posted on

no dislocation = no-undef

{ "rules": { "no-unused" : "warn"}}
Enter fullscreen mode Exit fullscreen mode

My dislocation lead me so many times to type wrong variable names in code. In Javascript that is don't cause immediately error, because thats name use as undeclared global. My solution is really simple under vs-code. With esLint no-unused rule help to mark red underline the typing errors.
This setup also show console.log, console.warn, which is also don't good to stay in product code. You can choose this rule set as warn or error, by own taste.

This method also good for alert outer dependency.

esLint json with no-unused example ::

  "parser": "babel-eslint",
  "plugins": ["unused-imports", "react", "react-hooks"],
  "rules": {
    "unused-imports/no-unused-imports": "warn",
    "unused-imports/no-unused-vars": [
        { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
    "no-undef" : "error",
    "react/jsx-uses-vars": "warn",
    "react/jsx-uses-react": "warn"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)