question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-unused-vars does not report error when comma operator is used

See original GitHub issue

With no-unused-vars enabled eslint does not mark a variable as unused if assignment is combined with the comma operator.

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

Both produce no warning:

let x = 0;
x++, x = 0;
let x = 0;
x++, x = 0;
x = 3;

What did you expect to happen? It should mark the last occurance of x as an unused variable.

What actually happened? Please copy-paste the actual, raw output from ESLint. eslint thinks everything is fine.

Steps to reproduce this issue:

  1. eslint demo

Are you willing to submit a pull request to fix this bug? No

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
snitin315commented, Apr 17, 2021

I will take this issue 👍🏻

2reactions
nzakascommented, Apr 16, 2021

This is occurring because of the x++, not because of the comma operator. The post fix increment operation counts as both a read and a write, which is why there is no warning.

This looks like a bug but I’d like another set of eyes. @eslint/eslint-tsc

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
Question: What's wrong with this rule and why it triggers in this case. Why eslint recognizes type declaration for functions in types/interfaces ...
Read more >
C static code analysis: Comma operator should not be used
It is especially error-prone in array subscripts where it might be misinterpreted as accessing a multidimensional array. The use of a comma in...
Read more >
Disallow Use of the Comma Operator (no-sequences) - ESLint
Disallow Use of the Comma Operator (no-sequences). The comma operator includes multiple expressions where only one is expected. It evaluates each operand ...
Read more >
comma-dangle | typescript-eslint
Examples​. This rule extends the base eslint/comma-dangle rule. It adds support for TypeScript syntax. See the ESLint documentation for more details on the ......
Read more >
Rules - JavaScript Standard Style
Rules · No unused variables. · Add a space after keywords. · Add a space before a function declaration's parentheses. · Multiple blank...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found