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

Coordinating noUnusedLocals, noUnusedParameters, no-unused-vars, and prefer-const #1859

Closed
DanielRosenwasser opened this issue Apr 7, 2020 · 1 comment
Labels
awaiting response Issues waiting for a reply from the OP or another party package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin question Questions! (i.e. not a bug / enhancment / documentation)

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Apr 7, 2020

So in TypeScript we have --noUnusedLocals and --noUnusedParameters, and in ESlint we have no-unused-vars and prefer-const. So many options! But it's actually a bit overwhelming in practice.

https://twitter.com/drosenwasser/status/1247322887540760577

image

I know i can turn these off, but this is what you get as part of

    'eslint:recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',

and it's not a great out-of-the-box experience. Is there a possibility to make some of this work a little bit more gracefully? Some ideas:

  • if a variable is never used at all, you only want to elaborate on no-unused-vars - preferring const instead of let is a noisy suggestion until we actually see some use-site.
  • if an ESLint rule can detect that TypeScript has noUnusedLocals enabled, then maybe there's potential for no-unused-vars to bow out and yield to TypeScript - at that point, prefer-const might be reasonable to re-enable.

At the very least, the first point seems doable to me.

@DanielRosenwasser DanielRosenwasser added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Apr 7, 2020
@DanielRosenwasser DanielRosenwasser changed the title Coordinating noUnusedLocals, no-unused-vars, and prefer-const Coordinating noUnusedLocals, noUnusedParameters, no-unused-vars, and prefer-const Apr 7, 2020
@bradzacher bradzacher added question Questions! (i.e. not a bug / enhancment / documentation) and removed triage Waiting for maintainers to take a look labels Apr 7, 2020
@bradzacher
Copy link
Member

if an ESLint rule can detect that TypeScript has noUnusedLocals enabled, then maybe there's potential for no-unused-vars to bow out and yield to TypeScript

This is doable... kind of.
Two issues with it:

if a variable is never used at all, you only want to elaborate on no-unused-vars - preferring const instead of let is a noisy suggestion until we actually see some use-site.

We could extend prefer-const into our plugin, and add checks so that it ignores when a variable is unused, but that would be a significant departure from the base implementation, so I don't think it's something most users would expect / want.

The above work would be the only way to actually do this - lint rules are all completely isolated, so there's no way to conditionally disable a rule if another rule reports.
This is why, for the most part, rules endeavour to not step on each other's toes (doubly so for reporting contradicting errors).


prefer-const has always been a little bit contentious. Some people love it, others don't. There's arguments for turning it off entirely.

I'd love to turn no-unused-vars off completely, but it's enabled as a core recommended rule in ESLint, so we have to have it in our recommended set as well, so that users get the correct errors for TS code (uhh, well kind of correct - #1856).

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Apr 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party 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