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

linter: no-unused-vars false positive w/TS overload #5406

Closed
eventualbuddha opened this issue Sep 2, 2024 · 0 comments · Fixed by #5470
Closed

linter: no-unused-vars false positive w/TS overload #5406

eventualbuddha opened this issue Sep 2, 2024 · 0 comments · Fixed by #5470
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers

Comments

@eventualbuddha
Copy link
Contributor

no-unused-vars warns on the following code:

export function log(message: string, ...interpolations: unknown[]): void;
export function log(message: string, ...interpolations: unknown[]): void {
  console.log(message, interpolations);
}

It claims interpolations in the overload signature is unused. However, it only makes sense to check for unused vars in functions with bodies. Here's the output:

❯ npx oxlint@latest test.ts

  ⚠ eslint(no-unused-vars): Variable 'interpolations' is declared but never used.
   ╭─[test.ts:1:38]
 1 │ export function log(message: string, ...interpolations: unknown[]): void;
   ·                                      ──────────────┬─────────────
   ·                                                    ╰── 'interpolations' is declared here
 2 │ export function log(message: string, ...interpolations: unknown[]): void {
   ╰────
  help: Consider removing this declaration.

Finished in 84ms on 1 file with 93 rules using 3 threads.
Found 1 warning and 0 errors.
@eventualbuddha eventualbuddha added the C-bug Category - Bug label Sep 2, 2024
@Boshen Boshen added the good first issue Experience Level - Good for newcomers label Sep 4, 2024
@Boshen Boshen changed the title no-unused-vars false positive w/TS overload linter: no-unused-vars false positive w/TS overload Sep 4, 2024
@DonIsaac DonIsaac added the A-linter Area - Linter label Sep 5, 2024
camc314 pushed a commit that referenced this issue Sep 6, 2024
…n overloads (#5470)

- Fixes #5406

This implements a fix for the `BindingRestElement` symbol, which is
currently unhandled and gets automatically marked as unused. If we
happen to find that it is a child of declaration, then we will
automatically allow the binding rest element.

The code for this was based on what we currently do in
`is_allowed_param_because_of_method`:
https://github.com/oxc-project/oxc/blob/5187f384cb38b1ba69acc2cb9b677d72ef175e3e/crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs#L258

I opted not to refactor this to re-use the same code though, as I think
the duplication is still incidental and the implementations could
diverge in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Area - Linter C-bug Category - Bug good first issue Experience Level - Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants