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

no-unused-vars false positive on increment #5671

Closed
mymoomin opened this issue Sep 10, 2024 · 1 comment · Fixed by #5722
Closed

no-unused-vars false positive on increment #5671

mymoomin opened this issue Sep 10, 2024 · 1 comment · Fixed by #5722
Assignees
Labels
C-bug Category - Bug P-high Priority - High

Comments

@mymoomin
Copy link

mymoomin commented Sep 10, 2024

Using a variable to look up a value in an object then ++ing it doesn't count as a use, but += 1 does. Eslint does not report anything in either case

const counts = {};

for (const char of "hello") {
  counts[char]++;
}

for (const char of "world") {
  counts[char] += 1;
}

gets

> npx oxlint@latest
  ⚠ eslint(no-unused-vars): Variable 'char' is declared but never used.
   ╭─[testing.js:3:12]
 2 │ 
 3 │ for (const char of "hello") {
   ·            ──┬─
   ·              ╰── 'char' is declared here
 4 │   counts[char]++;
   ╰────
  help: Consider removing this declaration.
@mymoomin mymoomin added the C-bug Category - Bug label Sep 10, 2024
@mymoomin
Copy link
Author

The same thing happens for arrays

const counts = [0, 0, 0, 0, 0, 0];

for (const index of [0, 1, 2]) {
  counts[index]++;
}

for (const char of [3, 4, 5]) {
  counts[char] += 1;
}

console.log(counts);
> npx oxlint@latest

  ⚠ eslint(no-unused-vars): Variable 'index' is declared but never used.
   ╭─[testing.js:2:12]
 1 │ const counts = [0, 0, 0, 0, 0, 0];
 2 │ for (const index of [0, 1, 2]) {
   ·            ──┬──
   ·              ╰── 'index' is declared here
 3 │   counts[index]++;
   ╰────
  help: Consider removing this declaration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug P-high Priority - High
Projects
None yet
4 participants