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

Bug(lint): variable detected as unused when used as index accessor #5821

Closed
marvinhagemeister opened this issue Sep 17, 2024 · 3 comments
Closed
Labels
C-bug Category - Bug

Comments

@marvinhagemeister
Copy link

Steps to reproduce

  1. Create file foo.ts with these contents:
export function updateDiffStats(stats, diff, childCount) {
  const idx = getChildCountIdx(childCount);
  if (diff === 1) {
    stats.keyed[idx]++;
  } else if (diff === 2) {
    stats.unkeyed[idx]++;
  } else if (diff === 3) {
    stats.mixed[idx]++;
  }
}

const getChildCountIdx = (n) => n;
  1. Run npx oxlint foo.ts

Output:

$ npx oxlint foo.ts

  ⚠ eslint(no-unused-vars): Variable 'idx' is declared but never used.
   ╭─[foo.ts:2:8]
 1 │ export function updateDiffStats(stats, diff, childCount) {
 2 │     const idx = getChildCountIdx(childCount);
   ·           ─┬─
   ·            ╰── 'idx' is declared here
 3 │     if (diff === 1) {
   ╰────
  help: Consider removing this declaration.

Finished in 3ms on 1 file with 94 rules using 10 threads.
Found 1 warning and 0 errors.
@marvinhagemeister marvinhagemeister added the C-bug Category - Bug label Sep 17, 2024
@Boshen
Copy link
Member

Boshen commented Sep 17, 2024

This is already fixed, will release soon!

@camc314
Copy link
Collaborator

camc314 commented Sep 17, 2024

https://github.com/oxc-project/oxc/pull/5722/files

@marvinhagemeister
Copy link
Author

Awesome, closing as resolved by #5722 in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category - Bug
Projects
None yet
Development

No branches or pull requests

3 participants