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

Rule Change: Add support for suggestions for unused var #17545

Open
1 task done
edi9999 opened this issue Sep 8, 2023 · 9 comments · May be fixed by #18352
Open
1 task done

Rule Change: Add support for suggestions for unused var #17545

edi9999 opened this issue Sep 8, 2023 · 9 comments · May be fixed by #18352
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules

Comments

@edi9999
Copy link

edi9999 commented Sep 8, 2023

What rule do you want to change?

no-unused-vars

What change to do you want to make?

Implement suggestions

How do you think the change should be implemented?

A new default behavior

Example code

const util = require("util");

What does the rule currently do for this code?

Not propose any suggestion

What will the rule do after it's changed?

It will remove the line with the util.

Participation

  • I am willing to submit a pull request to implement this change.

Additional comments

No response

@edi9999 edi9999 added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Sep 8, 2023
@mdjermanovic
Copy link
Member

Thanks for the proposal. Would this only apply to variables declared with const, or to all variables this rule reports (let, var, functions, parameters, classes, imports...)?

@edi9999
Copy link
Author

edi9999 commented Sep 10, 2023

My idea would be to support all kinds of unused variables to propose the suggestion, for example :

1.

const { useState, useEffect } = require("react");
useEffect();

suggests :

const { useEffect } = require("react");
useEffect();

2.

function() {
  const { useState } = require("react");
  let a = 1 + 1;
  return a
}

suggests :

function() {
  let a = 1 + 1;
  return a
}

3.

function({ foo, bar}) {
    return bar;
}

suggests :

function({ bar}) {
    return bar;
}

4.

function({ foo, bar}) {
    return null;
}

suggests:

function() {
    return null;
}

5.

function() {
    let a = 1, b = 2;
    const x = 1;
   var c = 0;
   return 1;
}

suggests :

function() {
   return 1;
}

@mdjermanovic
Copy link
Member

I support this. There will be a lot of details (for example, #17546 (comment)) that I think we can figure out while working on the PR, or if the team prefers here in advance.

Waiting for more opinions from other team members.

Copy link

github-actions bot commented Nov 8, 2023

Oops! It looks like we lost track of this issue. What do we want to do here? This issue will auto-close in 7 days without an update.

@github-actions github-actions bot added the Stale label Nov 8, 2023
Copy link

This issue was auto-closed due to inactivity. While we wish we could keep responding to every issue, we unfortunately don't have the bandwidth and need to focus on high-value issues.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Nov 15, 2023
@fasttime
Copy link
Member

@eslint/eslint-team what do you think of this proposal?

@fasttime fasttime reopened this Nov 16, 2023
@fasttime fasttime removed the Stale label Nov 16, 2023
@nzakas nzakas added the accepted There is consensus among the team that this change meets the criteria for inclusion label Nov 22, 2023
@nzakas
Copy link
Member

nzakas commented Nov 22, 2023

I think adding suggestions is a good idea. Marking as accepted. @edi9999 would you be interested in submitting a PR?

@edi9999
Copy link
Author

edi9999 commented Nov 22, 2023

Currently, I'm not going to be able to work on this in the foreseeable future.

I don't have that much of eslint internals knowledge yet and don't have much time to do it, I'm sorry.

@Tanujkanti4441
Copy link
Contributor

I can try to implement this.
But i think it's good to work on this after #17662 PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
Status: Implementing
Development

Successfully merging a pull request may close this issue.

6 participants
@nzakas @edi9999 @fasttime @mdjermanovic @Tanujkanti4441 and others