ISSUE DESCRIPTION linter: no-unused-vars false positive when constructor parameter…
- User
ISSUE DESCRIPTION
linter: no-unused-vars false positive when constructor parameter property shadows an imported identifier used in its own decorator
What version of Oxlint are you using?
1.65.0 (also reproduces on 1.30.0)
What command did you run?
oxlint test.tsWhat does your
.oxlintrc.json(oroxlint.config.ts) config file look like?// default (no config file)What happened?
When a TypeScript constructor parameter property has the same name as an outer binding (import or
const), and that outer binding is used in the parameter's own decorator expression (e.g.@Inject(foo.KEY)), oxlint'sno-unused-varsreports the outer binding as declared but never used.This is a false positive. Parameter decorators are evaluated at class-decoration time in the enclosing class scope, before any parameter binding exists in the parameter scope. So
fooinside@Inject(foo.KEY)resolves to the outer binding, not to the same-named parameter property.This pattern is extremely common in NestJS code, where
@Inject(someConfig.KEY)is used to injectregisterAs(...)-style typed configs and the constructor parameter property is typically named after the config. The false positive forces a churn-y workaround: either alias the import (import { foo as _foo }) or rename the parameter property.Minimal reproduction
const foo = { KEY: 'token' }; declare function Inject(token: unknown): ParameterDecorator; export class C { constructor(@Inject(foo.KEY) private readonly foo: number) {} }Actual
! eslint(no-unused-vars): Variable 'foo' is declared but never used. Unused variables should start with a '_'. ,-[test.ts:1:7] 1 | const foo = { KEY: 'token' }; : ^|^ : `-- 'foo' is declared hereExpected
No diagnostics —
foois used in@Inject(foo.KEY).ESLint with
@typescript-eslint/parser+@typescript-eslint/eslint-plugindoes not report this — its scope analyser correctly counts the decorator expression as a use of the outer binding.Notes / related issues
- #20670 — sibling bug (type param shadowed by function arg), same family.
- #17927 — closed namespace-shadow case (
namespaceshadowed by generic). - #2180 — typescript-eslint umbrella tracker.
- Assistant
I'll start by exploring the repository structure and reproducing the reported
no-unused-varsfalse positive. - Assistant
I'll read the project guidance and locate the
no-unused-varsimplementation. - Assistant
This looks like a scope/semantic issue. I'll inspect related references and how parameter decorators are handled.
- Assistant
I’ll switch to
grep/ast-grepsincergisn’t available. - Assistant
Inspecting how the semantic builder visits parameters and existing unused-vars decorator tests.
- Assistant
The order looks wrong—parameters are bound before their decorators are visited. Checking how function/method scopes are set up and how #20670 was handled.
- Assistant
Let me look at visit_function and visit_method_definition more carefully, and also how class body and constructor parameters work regarding scopes. Also I should check if there's a related issue fix f...
- Assistant
Checking binder logic and tests around parameter shadowing next.
- Assistant
Deferred reference resolution may be the real problem — I'll dig into how unresolved references work.
- Assistant
Let me read the resolve_references_for_current_scope and how reference identification works when parameters are already bound vs when deferred.
- Assistant
Checking how method decorators and related structures are visited:
- Assistant
Hmm empty. Let me try differently.
- Assistant
So method definition uses the default visitor. Let me look at that.
- Assistant
Let me see walk_method_definition and walk_formal_parameter
- Assistant
Looking at related shadowing cases and any planned fix pattern.
- Assistant
Let me look at line 2228 in builder.rs - another param.bind something?
- Assistant
Inspecting the FormalParameter binder and symbol flags for parameter properties.
- Assistant
I'll reproduce the issue, then implement a fix.
- Assistant
Checking how semantic and linter tests are structured so I can reproduce quickly.
- Assistant
I'll write a small reproduction harness with the semantic analyzer.
- Assistant
Running the semantic example against the reproduction to inspect symbol references.
- Assistant
Confirmed: decorator
fooresolves to the parameter. I'll fix the visitor to resolve parameter decorators in the enclosing scope. - Assistant
I'll add a helper and update both formal-parameter visitors.
- Assistant
Implementing the fix: visit parameter decorators in the parent scope before binding.
- Assistant
Adding the helper method next to the other reference helpers.
- Assistant
I'll österreich add the helper to the second impl block.
- Assistant
Checking imports and whether
Decoratoris in scope. - Assistant
ast::*includesDecoratorandThere's probablyVecre-exported. Let me check how other methods typeVec stuff. - Assistant
They use
Vecwhich is likely from oxc_allocator through ast. Looking at visit.rs imports. - Assistant
Importing
Vecfrom the allocator and compressing the type annotation. - Assistant
Actually using ArenaVec in signature - let me update the method signature.
- Assistant
Need to navigate there first or use --file
- Assistant
Hmm strange. Let me try goto and then replace.
- Assistant
Let me use edit Immunology.
- Assistant
Rebuilding and verifying the fix against the reproduction.
- Assistant
Outer
fooresolves correctly. Checking edge cases and running related tests. - Assistant
Case 3 is interesting -
constructor(@dec(a) private a = a). The initializer= a- whichadoes it reference? - Assistant
Running semantic and no_unused_vars tests to check for regressions.
- Assistant
Linter tests passed. Updating semantic snapshots that record the corrected decorator scope IDs.
- Assistant
Found fixtures for this case — reviewing and accepting the updated snapshots.
- Assistant
Accepting updated snapshots that reflect decorator references living in the enclosing scope.
- Assistant
Verifying with the linter on the original repro and scanning for other affected snapshots.
- Assistant
Confirming oxlint is clean. Running a few more edge-case checks and compiling related crates.
- Assistant
Cleaning up formatting and running clippy on the changed crate.
- Assistant
Clippy is clean. Running rustfmt and doing a final snapshot review.
- Assistant
Checking whether AST nodes record scope IDs that our temporary parent-scope switch might burn.
- Assistant
Looking at create_ast_node - it records current_scope_id on the node. So decorator AST nodes will have parent (class) secope id, which is CORRECT semantically - decorators belong to enclosing scope fo...
- Assistant
Confirming decorator AST nodes belong on the enclosing scope. Formatting with cargo.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.