Skip to content
TheChatArchiveThe Chat Archive
gpt-5.6-sol· openaiHugging 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

    I’ll trace the semantic scope construction for TypeScript parameter decorators, add a focused regression test, and run the narrow semantic/linter test suites. Since this touches a linter rule implementation, I’m also using the performance-lint-rules guidance.

  3. Assistant

    The performance guidance applies only if the fix lands inside a rule; the symptom looks more likely to come from shared semantic scope resolution, so I’ll keep the fix at the ownership layer rather than adding a rule-specific workaround.

  4. Assistant

    The bug is confirmed in semantic traversal: constructor parameters are bound in the method’s function scope before their decorators are visited, so the decorator reference incorrectly resolves to that parameter. I’m adding the reproduction to the existing TypeScript no-unused-vars pass corpus before changing traversal.

  5. Assistant

    The regression test is in place and the initial linter build is still compiling the workspace. The planned semantic change is small: visit parameter decorators with the function’s parent scope as their lexical scope, while preserving their AST parentage under the parameter.

  6. Assistant

    The new test now passes with the semantic fix. I’m extending coverage to the title’s imported-binding form as well, then I’ll format and run both the semantic crate tests and the focused linter tests.

  7. Assistant

    The repository’s documented just fmt command is unavailable in this environment (just is not installed), so I’m using the equivalent Rust formatter directly for the two Rust files changed.

  8. Assistant

    The broad cargo test -p oxc_semantic command hits an unrelated repository configuration issue: the cfg example has no main without its feature enabled. I’m narrowing it to the crate’s library and integration tests, which exercises the semantic implementation without building that feature-gated example.

  9. Assistant

    The semantic tests exposed two expected scope snapshot changes: existing parameter-decorator references move from the method function scope to the enclosing class scope. I’m using the repository’s insta-snapshots workflow now to review and update only those two snapshots.

  10. Assistant

    cargo-insta is also absent despite the repository prerequisites. I reviewed both pending files directly; their only behavioral changes are the expected scope_id: 3 → 2 moves (plus Insta’s generated assertion-line metadata). I’ll use Insta’s built-in noninteractive INSTA_UPDATE=always mode to accept them, then verify the resulting diffs.

  11. Assistant

    Both regression forms now pass, and the semantic suite confirms all existing parameter-decorator references are assigned to the enclosing class scope. I’m doing the final formatting/diff checks and a narrow Clippy pass on the semantic crate.

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