Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@typescript-eslint/no-unused-vars] how does this differ from no-unused-vars? #438

Closed
gabor opened this issue Apr 18, 2019 · 1 comment
Closed
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)

Comments

@gabor
Copy link

gabor commented Apr 18, 2019

this module contains a rule called @typescript-eslint/no-unused-variables, and from a quick check it seems very similar to the no-unused-variable rule from eslint-core. what is the difference between the two?

the reason for my question is that i'm trying to combine the airbnb-rules with typescript-eslint and there are cases where it does not work. it was set up based on the official documentation ( https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#usage-with-airbnb ), and it seemed to work ok, but then i found out that for certain rules the airbnb-settings were ignored. for example, for no-unused-vars, the setting ignoreRestSiblings is true in airbnb-rules, but while programming i got linter-errors that suggested that the setting is set to false somehow. so after some debugging i found out that typescript-eslint-recommended disables the original no-unused-vars rule, and enables the rule called @typescript-eslint/no-unused-vars, which seems to be exactly the same as the no-unused-vars rule. and because the settings for that rule are not the same in typescript-eslint as in airbnb-rules, problems happen.

and now i wonder, why such rules are handled by typescript-eslint. i previously assumed this module only provides rules that are specific to typescript (and do not apply to javascript), and it is supposed to be used together with other eslint-plugins that cover other areas (accessibility etc.), but now i'm not sure. could someone explain the philosophy behind this module and how it should be used?

an idea: could this module provide a preset (similar to -recommended) that only deals with typescript-specific features?

@gabor gabor added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 18, 2019
@bradzacher bradzacher added question Questions! (i.e. not a bug / enhancment / documentation) and removed triage Waiting for maintainers to take a look labels Apr 18, 2019
@bradzacher
Copy link
Member

bradzacher commented Apr 18, 2019

The settings for the rule extension are the same, because we haven't added any. We haven't reimplemented the rule, instead have extended it so it understands the additional TS AST and the extra scope context TS introduces.

ESLint has no mechanism for extending an existing rule, so we have to add our own version of it, even if we only add additional selectors to the existing code.

In a nutshell, @typescript-eslint/eslint-plugin exists so that people have a centralised place to add rules related to typescript features, whether that be brand new rules for typescript-specific features, rules which support JS features but use type information to aid analysis, or rules that add additional handling to existing rules (see our versions of camelcase, no-unused-vars, no-useless-constructor, etc).

If you've used our recommended config, then yes, it will override airbnb's settings. This happens for two reasons:

  1. the two rules are completely separate; meaning we cannot just reuse the existing config, because eslint doesn't let you reuse config between rules.
  2. within our config, we cannot read what the existing config for no-unused-vars is, meaning that we can't infer the config on your behalf.

See: #265 for more information and discussion.

an idea: could this module provide a preset (similar to -recommended) that only deals with typescript-specific features?

Nope. Two reasons:

  • every single rule in this repo only deals with TS-specific features (i.e. that would just be the normal recommended set)
  • if we didn't disable the base rules in favour of our overrides, then we would get more people reporting that rules (that aren't supposed to work) don't work (i.e. more issues like no-useless-constructor: Cannot read property 'body' of null #420, which take up time and effort on our behalf to comment on and close).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)
Projects
None yet
Development

No branches or pull requests

2 participants