Skip to content
TheChatArchiveThe Chat Archive
composer-2.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

linter: no-unused-vars false positive when constructor parameter property shadows an…

  1. 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.ts
    

    What does your .oxlintrc.json (or oxlint.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's no-unused-vars reports 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 foo inside @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 inject registerAs(...)-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 here
    

    Expected

    No diagnostics — foo is used in @Inject(foo.KEY).

    ESLint with @typescript-eslint/parser + @typescript-eslint/eslint-plugin does 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 (namespace shadowed by generic).
    • #2180 — typescript-eslint umbrella tracker.

    Interface

    No new interfaces are introduced.

  2. Assistant

    Investigating how no-unused-vars handles constructor parameter decorators and shadowing — this looks like a scope-analysis bug.

  3. Assistant

    Reproducing the bug, then checking how semantic analysis orders parameter binding vs decorator visits.

  4. Assistant

    The issue is that visit_formal_parameter binds the parameter before visiting decorators, so decorator expressions resolve to the parameter instead of the outer binding. Reordering to match ast_visit.

  5. Assistant

    The reorder didn't fix it — checking when the function scope and parameter bindings are created.

  6. Assistant

    Decorator references are still resolved after all parameters are bound. Resolving them immediately after visiting each parameter's decorators.

  7. Assistant

    Fix confirmed. Running broader tests and updating snapshots.

  8. Assistant

    This was a semantic scoping bug, not a no-unused-vars rule bug. The rule was correctly reporting foo as unused because semantic analysis never recorded a read of the outer foo.

    Root cause

    In visit_formal_parameter, the builder was:

    1. Binding the parameter name into the function scope
    2. Visiting decorator expressions
    3. Deferring reference resolution until after all parameters were bound

    So in:

    constructor(@Inject(foo.KEY) private readonly foo: number) {}
    

    the foo in @Inject(foo.KEY) was resolved to the parameter foo (which has no reads), not the outer const foo.

    Fix

    In crates/oxc_semantic/src/builder.rs:

    1. Visit parameter decorators before binding the parameter (matching oxc_ast_visit order)
    2. Immediately resolve references created in those decorators, before the parameter symbol exists in scope
    3. Extract resolve_references_since_checkpoint() for reuse

    Tests added

    • Semantic integration test: test_parameter_decorator_shadowed_outer_binding
    • no-unused-vars pass case in typescript_eslint.rs for the NestJS-style pattern

    All related tests pass, and the minimal repro now reports 0 warnings.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.