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
No new interfaces are introduced.
- Assistant
I’m tracing the semantic binding of parameter decorators and will add a focused regression test before fixing it. I’m also using the linter performance skill because this change touches a rule implementation and needs to preserve hot-path behavior.
- Assistant
The repository is clean. The advertised structural/text search binaries are unavailable in this environment, so I’m using narrow filesystem and source searches as the documented fallback. The likely defect is in semantic reference resolution rather than the diagnostic rule itself; I’m verifying that boundary now.
- Assistant
The scope snapshot confirms the bug: parameter-decorator references are currently recorded in the constructor’s function scope. I’ll move only decorator traversal to the enclosing class scope, leaving parameter initializers and type annotations in the function scope. This fixes both parameter properties and ordinary decorated parameters without adding work to
no-unused-varsitself. The existing semantic snapshots will change, so I’m applying the repository’s snapshot-testing skill for that update. - Assistant
The implementation and regression case are in place. This checkout also lacks the advertised
justbinary, so I’m substituting the underlying Cargo formatting and targeted test commands. - Assistant
The exact linter regression test now passes. I’m checking semantic snapshots next; the expected change is that parameter-decorator reference
scope_idvalues move from the constructor/method scope to the enclosing class scope, with symbol resolution otherwise unchanged. - Assistant
The semantic test produced exactly two expected snapshot updates: six
scope_idchanges from function scope3to class scope2, and nothing else. The snapshot skill’scargo instahelper is not installed here, so I reviewed the generated diffs and will apply those exact updates with the repository editing mechanism, then remove the pending files via the safest available cleanup. - Assistant
The linter regression remains green after refactoring the scope switch into a single empty-fast-path helper. The broad semantic command hit an unrelated repository issue—its
cfgexample has nomainwithout the feature—so I’m rerunning the complete semantic library/integration test set while explicitly excluding examples. - Assistant
All 1,145 linter tests and all 72 semantic library/integration/snapshot tests pass. Clippy reached an existing
oxc_parserlint unrelated to this change; I’m narrowing it to the two changed crates with dependency linting disabled so our code is still checked cleanly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- composer-2.5Compare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →
- fable-5Compare side by side →
- fable-5Compare side by side →