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

Exemption for for...of unused variable. #12287

Closed
dimaqq opened this issue Sep 19, 2019 · 14 comments
Closed

Exemption for for...of unused variable. #12287

dimaqq opened this issue Sep 19, 2019 · 14 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules

Comments

@dimaqq
Copy link

dimaqq commented Sep 19, 2019

In similar vein to for...in #2342
Should there be similar exemption for [async] for...of?

What rule do you want to change?
no-unused-vars

Does this change cause the rule to produce more or fewer warnings?
fewer warnings

How will the change be implemented? (New option, new default behavior, etc.)?
I don't know

Please provide some example code that this change will affect:

async function forever(x) {
  for await (const unused of x) {
    void unused;
  }
}

forever(monitor_network());

What does the rule currently do for this code?
Line 42: 'unused' is defined but never used no-unused-vars

What will the rule do after it's changed?
Nothing

Are you willing to submit a pull request to implement this change?
This seems tricky...

@dimaqq dimaqq added enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules triage An ESLint team member will look at this issue soon labels Sep 19, 2019
@mqklin
Copy link

mqklin commented Sep 26, 2019

This is broken for me after eslint update to v6 as well:

for (const x of y) { // x is defined but never used (no-unused-vars)
  console.log(x);
}

@kaicataldo
Copy link
Member

This looks like a duplicate of #12117. Can you see if the solutions there fix your issue?

@kaicataldo
Copy link
Member

Note that this issue doesn't show in the ESLint Demo .

Are you using babel-eslint?

@kaicataldo kaicataldo added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed enhancement This change enhances an existing feature of ESLint triage An ESLint team member will look at this issue soon labels Sep 26, 2019
@mqklin
Copy link

mqklin commented Sep 27, 2019

Yes, I use babel-eslint. Yes, updating babel-eslint fixed the issue, thanks a lot!

@g-plane g-plane added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules labels Sep 27, 2019
@g-plane
Copy link
Member

g-plane commented Sep 27, 2019

Closing this issue as it looks like the question has been answered. Please feel free to visit us in the ESLint Gitter if you have any other issues!

@g-plane g-plane closed this as completed Sep 27, 2019
@platinumazure
Copy link
Member

@g-plane I could be missing something, but... I'm not sure this should be closed. The original post was a rule enhancement request for "for await of", but then someone else came and asked about "for of" and we noted the babel-eslint/eslint-scope issue.

Should we still evaluate the original rule request? If not, why not?

@g-plane
Copy link
Member

g-plane commented Sep 28, 2019

Oh, it seems reasonable. Sorry.

@g-plane g-plane reopened this Sep 28, 2019
@g-plane g-plane added bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed question This issue asks a question about ESLint labels Sep 28, 2019
@kaicataldo
Copy link
Member

kaicataldo commented Sep 28, 2019

I'm not able to reproduce with our demo.

@dimaqq I see you left a reaction on my comment above - did this solve your problem (hoping it did!)?

@dimaqq
Copy link
Author

dimaqq commented Sep 28, 2019

I can only test it on Monday, sorry.
I think that with void trick it ought to work; and without it I’m not sure...

@mysticatea
Copy link
Member

I guess you can use varsIgnorePattern option to ignore unused variables by naming convention.

For example, Online Demo.

@dimaqq
Copy link
Author

dimaqq commented Sep 29, 2019

@kaicataldo
Copy link
Member

None of the rules are on in the link you provided. When I turn on no-unused-vars, it’s displaying an error as expected.

@dimaqq
Copy link
Author

dimaqq commented Sep 30, 2019

I'm so sorry for the confusion.

When I read #2342 I was left with the impression that the following is allowed:

for (unused in something) {}

But of course that's only because unused could be anything here, e.g. a global, and other rules kick in now: no-undef, prefer-const.

It didn't think that the following is semantically different wrt. the unused variable rule and treated both cases the same:

for (const unused in something) {}

Weirdly there's test case for the above, as if that's valid code:

{ code: "(function(obj) { for ( const name in obj ) { return true } })({})", parserOptions: { ecmaVersion: 6 } },

Yet, if I "enable all rules" in the eslint demo, that very example triggers no-unused-vars 😕

In any case void unused; works and keeps eslint silent.

Also, as far I can tell for await (const x of y) is treated exactly same as for (const x of y).

I guess I'm OK then :)

@kaicataldo
Copy link
Member

Thanks for following up! I'm going to go ahead and close this issue then.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Mar 30, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

6 participants