Skip to content
TheChatArchiveThe Chat Archive
xiaomi/mimo-v2.5-pro· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION linter: no-unused-vars false positive when constructor parameter…

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

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /oxc, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository to understand its structure and locate relevant files for the no-unused-vars rule. Let's first get a high-level view.

  3. Assistant

    Let me explore the repository structure more broadly.

  4. Assistant

    Let me look for the no-unused-vars rule in the linter crate.

  5. Assistant

    Let me look at the main module for no-unused-vars rule.

  6. Assistant

    Let me first create a reproduction script to understand the issue.

  7. Assistant

    Let me look at the usage.rs file, which likely handles how usages are tracked:

  8. Assistant

    Let me look at how decorators are handled in the scope analysis:

  9. Assistant

    Let me look at the mod.rs file which is the main entry point for the no-unused-vars rule:

  10. Assistant

    Let me see the rest of the file.

  11. Assistant

    Now let me understand the issue better. The problem is that when a constructor parameter property has the same name as an outer binding, and the outer binding is used in the decorator, the scope analysis might be resolving the decorator reference to the parameter property instead of the outer binding.

    Let me look at how the semantic analysis handles scopes, especially for decorators and constructor parameter properties.

  12. Assistant

    Let me look at the scope/resolver to understand how decorators are handled:

  13. Assistant

    Let me search for how decorators are visited in scope analysis:

  14. Assistant

    Let me look at the builder.rs file to understand how decorators are handled:

  15. Assistant

    Let me look at the visit_formal_parameter implementation:

  16. Assistant

    I can see the issue! In visit_formal_parameter, param.bind(self) is called before self.visit_decorators(&param.decorators). This means the parameter's binding is already in scope when decorators are visited. But decorators on parameters should be evaluated in the enclosing scope, not in the constructor's scope.

    Let me look at how the resolver handles this:

  17. Assistant

    Let me check the resolver to understand how reference resolution works for decorators:

  18. Assistant

    Let me look at how the scope analysis creates scopes for constructor parameters:

  19. Assistant

    Let me search for the bind method for FormalParameter to understand how it creates the binding:

  20. Assistant

    Let me search for bind in the codebase. It's a trait method likely.

  21. Assistant

    Let me look at the binder for FormalParameter:

  22. Assistant

    Let me look at how class decorators are handled in the same file:

  23. Assistant

    Let me look at the visit_class implementation:

  24. Assistant

    Now I understand the problem. In visit_formal_parameter, the parameter binding is created (param.bind(self)) BEFORE the decorators are visited (self.visit_decorators(&param.decorators)). This means the parameter binding foo shadows the outer const foo before the decorator @Inject(foo.KEY) is resolved.

    The fix is to visit decorators before binding the parameter, so the decorator expression resolves in the enclosing scope (as it should per TypeScript semantics).

    Let me first create a reproduction test to confirm the bug:

  25. Assistant

    Let me check if there are existing tests for decorators in this rule:

  26. Assistant

    Let me look at the test around line 67 to see if there's already a test for constructor parameter decorators:

  27. Assistant

    Let me look at the Binder impl for FormalParameter:

  28. Assistant

    Now I understand the issue clearly. In visit_formal_parameter, param.bind(self) creates the binding for the constructor parameter property BEFORE visiting the decorators. This means the decorator @Inject(foo.KEY) sees the constructor parameter foo (which shadows the outer const foo), so the outer foo is never referenced.

    The fix is to visit decorators BEFORE binding the parameter, just like how class decorators are visited before entering the class scope.

    Let me make the fix:

  29. Assistant

    Now I understand the issue clearly. In visit_formal_parameter, param.bind(self) is called before self.visit_decorators(&param.decorators). This means when the decorator @Inject(foo.KEY) is being resolved, the foo identifier in the decorator already resolves to the constructor parameter foo (which shadows the outer const foo), rather than the outer binding.

    The fix is to visit decorators BEFORE binding the parameter, just like how class decorators are visited before entering the class scope.

    Let me apply the fix:

  30. Assistant

    Now let me also fix visit_formal_parameter_rest for consistency:

  31. Assistant

    Now let me verify this change compiles and test it. First, let me check the existing tests:

  32. Assistant

    Let me wait for the test to finish:

  33. Assistant

    Good, the code compiles. Now let me run the linter tests for no_unused_vars:

  34. Assistant

    All 47 no-unused-vars tests pass. Let me also run the broader semantic tests to ensure nothing is broken:

  35. Assistant

    The example file seems to be broken but that's pre-existing. Let me run just the lib tests:

  36. Assistant

    Now let me build the linter and test it with the reproduction case:

  37. Assistant

    Now let me test with the reproduction case:

  38. Assistant

    The issue is still reproduced. The fix wasn't enough. Let me investigate more deeply. Let me look at how the resolver handles references:

  39. Assistant

    Let me look at how references are resolved. The issue is that reference resolution is deferred - references are resolved when leaving scopes:

  40. Assistant

    Let me look at how resolve_references_for_current_scope is called:

  41. Assistant

    Let me see the context for line 2238:

  42. Assistant

    Let me look at resolve_references_for_current_scope more carefully:

  43. Assistant

    Let me look at how function parameters and scope resolution work:

  44. Assistant

    Let me look at the visit_function method to understand how formal parameters are visited and when references are resolved:

  45. Assistant

    I see! The issue is more subtle. Even with decorators visited first, the resolve_references_for_current_scope() is called later (at line 1915), AFTER all parameter bindings have been created. So the decorator reference to foo resolves to the constructor parameter foo at that point.

    The fix needs to ensure decorator references are resolved BEFORE the parameter binding is created. Let me look at the pattern used in visit_catch_parameter which has similar behavior:

  46. Assistant

    Now I understand the full picture. The issue is:

    1. In visit_function, a checkpoint is saved (line 1894), then parameters are visited (line 1902), then resolve_references_for_current_scope() is called (line 1915).
    2. By the time resolve_references_for_current_scope() runs at line 1915, all parameter bindings have already been created. So decorator references resolve to the parameter binding, not the outer scope.

    The fix: In visit_formal_parameter, we need to use the same pattern as visit_catch_parameter - save a checkpoint, visit decorators, resolve those references immediately (before binding), then restore the checkpoint. This ensures decorator references resolve to the enclosing scope, not the parameter binding.

  47. Assistant

    Now let me also update visit_formal_parameter_rest with the same pattern:

  48. Assistant

    Now let me build and test with the reproduction case:

  49. Assistant

    Now let me test with the reproduction case:

  50. Assistant

    The fix works! No more false positive. Now let me run all the existing tests to make sure nothing is broken:

  51. Assistant

    All 47 tests pass. Let me also run the broader semantic tests and full linter tests:

  52. Assistant

    Let me also run the full linter test suite:

  53. Assistant

    All 1144 tests pass! Let me also run the semantic checker tests to verify snapshot tests:

  54. Assistant

    That's a pre-existing issue with the example file. Let me run the semantic tests specifically:

  55. Assistant

    Let me try to run the integration tests.

  56. Assistant

    All 60 semantic integration tests pass. Let me also run the main test:

  57. Assistant

    Excellent! Let me also test some more edge cases to make sure the fix is robust:

  58. Assistant

    The warnings in cases 3 and 4 are correct - they're about the parameter foo itself being unused in the constructor body (which is a separate valid warning). The important thing is that the outer const foo is NOT falsely reported as unused. Let me verify the import case more carefully:

  59. Assistant

    The import case also works correctly - no false positive. Let me also run the full linter test suite to make sure nothing is broken:

  60. Assistant

    All tests pass. Let me also verify the diff of my changes:

  61. Assistant

    Let me also run the parser tests to make sure nothing is broken:

  62. Assistant

    Let me also run the semantic checker tests which might have snapshot tests affected by our change:

  63. Assistant

    Let me also check if there are any other test suites that might be affected by this change:

  64. Assistant

    All tests pass. Let me do a final review of the changes and run a comprehensive test to make sure everything is working:

  65. Assistant

    Let me do a final comprehensive test with the original reproduction case and a few more edge cases:

  66. Assistant

    The fix works perfectly for all edge cases. Let me clean up the temporary test files:

  67. Assistant

    Let me review the final diff:

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