Search code examples
eslinttypescript-eslint

Eslint ignoring my rule settings "no-unused-vars"


Still getting this rule reported as an error when I run eslint. This is after I have set no-unused-vars and @typescript-eslint/no-unused-vars to warning in .eslintrc file.

I have tried both "no-unused-vars" : 1 and "no-unused-vars" : "warn" to no effect.

Why is eslint ignoring my rule settings?

.eslintrc file

{
  "root": true,
  "env": {
    "node": false,
    "browser": true
  },
  "globals": {
    "google": true,
    "process": true
  },
  "parser": "@babel/eslint-parser",
  "parserOptions": {
    "sourceType": "module",
    "ecmaVersion": "latest",
    "requireConfigFile": false
  },
  "overrides": [
    {
      "files": ["*.{ts,tsx}"],
      "parser": "@typescript-eslint/parser",
      "plugins": ["@typescript-eslint"],
      "extends": ["plugin:@typescript-eslint/recommended"] // needed for ts
    }
  ],
  "rules": {
    "@typescript-eslint/no-unused-vars": 1, // < ----- this wont set it to a warning
    "no-unused-vars": 1, // < ----- this wont set it to a warning, still error
  }
}

Solution

  • The "overrides" > "extends": ["plugin:@typescript-eslint/recommended"] is setting the rule to a new setting for you. overrides does what the name suggests: it overrides the base settings. Move the rules object into the "overrides".

    "overrides": [
        {
          // etc. etc.
          "extends": ["plugin:@typescript-eslint/recommended"],
          "rules": { /* reconfigure rules here */ }
        }
      ]
    

    See https://eslint.org/docs/latest/use/configure/configuration-files#configuration-based-on-glob-patterns for documentation on overrides in the legacy ESLint config file format that you're using.

    The new ESLint "flat" config file format makes a lot of this more clear.