@typescript-eslint/eslint-plugin error: 'Route' is defined but never used (no-unused-vars)
Asked Answered
F

3

40

After eslint adds typescript check, there will be an error when the attribute variable in the class definition is Array. enter image description here

enter image description here

enter image description here


this is my eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true
  },
  'extends': ['plugin:vue/essential', '@vue/standard'],
  rules: {},
  parserOptions: {
    parser: '@typescript-eslint/parser',
    project: "./tsconfig.json"
  },
  plugins: ['@typescript-eslint']
};
Ferro answered 21/3, 2019 at 12:35 Comment(4)
this is my eslintrc.jsFerro
module.exports = { root: true, env: { node: true }, 'extends': [ 'plugin:vue/essential', '@vue/standard' ], rules: { }, parserOptions: { parser: '@typescript-eslint/parser', project: "./tsconfig.json" }, plugins: ['@typescript-eslint'] };Ferro
You should really put your code in your post rather than use images. It makes it easier for people to debug.Dartmoor
ok i will show my codeFerro
P
59

Updated Answer

Disable no-unused-vars and enable it with "@typescript-eslint/no-unused-vars": "error"

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

Thanks to James Middleton for the correct answer.

Outdated

Looking at the eslint repository on github, there have been lots of issues opened about the no-unused-vars rule. Here is some examples:

https://github.com/typescript-eslint/typescript-eslint/issues/45

https://github.com/typescript-eslint/typescript-eslint/issues/111

https://github.com/typescript-eslint/typescript-eslint/issues/171

It's an ongoing problem. Hopefully we can expect this to be resolved soon.

Pursuivant answered 31/3, 2019 at 9:47 Comment(1)
This worked for me as well. However, I still had to make sure to not only update @typescript-eslint/eslint-plugin, but also @typescript-eslint/parser (version 4.12.0 for both in my case) to make it work without any false positives.Bohemia
S
66

The solution is to disable the native no-unused-vars so that only the TS one is enabled. The former is likely to be enabled if you extend a config in ESLint. Add the rules below to your ESLint config.

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}
Spinnaker answered 2/7, 2019 at 8:22 Comment(2)
How can one make sure only to omit the errors on imports?Chicky
Its an old answer but this is not a solution, since via this nothing is checked for unused variables, intention is to pass the rule for the types being used in some Generics and fails the rule when someone declared the variable and not used. I want to apply the rule of _ to ignore the variable, this does not supports, if I configures it with the rules of eslint.org/docs/rules/no-unused-vars then it starts complaining for unused TYPES.Conclusion
P
59

Updated Answer

Disable no-unused-vars and enable it with "@typescript-eslint/no-unused-vars": "error"

"rules": {
  "no-unused-vars": "off",
  "@typescript-eslint/no-unused-vars": "error"
}

Thanks to James Middleton for the correct answer.

Outdated

Looking at the eslint repository on github, there have been lots of issues opened about the no-unused-vars rule. Here is some examples:

https://github.com/typescript-eslint/typescript-eslint/issues/45

https://github.com/typescript-eslint/typescript-eslint/issues/111

https://github.com/typescript-eslint/typescript-eslint/issues/171

It's an ongoing problem. Hopefully we can expect this to be resolved soon.

Pursuivant answered 31/3, 2019 at 9:47 Comment(1)
This worked for me as well. However, I still had to make sure to not only update @typescript-eslint/eslint-plugin, but also @typescript-eslint/parser (version 4.12.0 for both in my case) to make it work without any false positives.Bohemia
L
1

If someone are still having the issue, I add "extends": ["eslint:recommended", "plugin:react/recommended"], on the .eslintrc.json file and the problem get solved.

Luthanen answered 17/11, 2019 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.