linter: no-unused-vars false positive when constructor parameter property shadows an…
- User
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.
Interface
- Assistant
I’ll trace semantic scope construction for TypeScript parameter decorators, add a focused regression test, then run the smallest relevant semantic/linter test set. Since this touches a linter rule implementation, I’m also applying the repository’s performance-lint-rules guidance.
- Assistant
The repository’s preferred search binaries aren’t available in this environment, so I’m using read-only fallback searches. The likely fix is in semantic reference resolution rather than the
no-unused-varsrule itself; if confirmed, the performance-rule skill won’t govern the edit. - Assistant
The semantic builder currently records parameter-decorator references in the function’s parameter scope, where the same-named parameter wins during resolution. I’m changing only decorator traversal to use the function’s enclosing scope; parameter initializers and type annotations will keep their existing parameter-scope behavior.
- Assistant
The focused semantic and linter regressions now pass. I’ve also added the imported-binding form from the report, and I’m formatting and checking the broader affected crates for unintended scope-resolution regressions.
- Assistant
The broader semantic snapshots correctly expose the intended scope-ID change for existing parameter-decorator fixtures. I’m applying the repository’s
insta-snapshotsworkflow now to review and accept only those two expected snapshot changes. - Assistant
The snapshot workflow’s CLI is not installed despite the repository setup note. I’m checking for an existing local binary before falling back; I won’t accept unrelated pending snapshots.
- Assistant
No local
cargo-instabinary exists. After reviewing both pending files, their only changes are the expected decorator reference scopes (3→ enclosing class scope2). I’m accepting exactly those reviewed deltas with the repository patch mechanism and removing the two generated pending files. - Assistant
All tests pass. The strict clippy run is blocked by three pre-existing
redundant_pub_crateerrors inoxc_parser; I’m rerunning clippy with dependency linting disabled so the changed semantic crate is still checked under-D warnings.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.