Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek/deepseek-v4-pro· deepseekHugging 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.

    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. DeepSeek Assistant

    Let me start by understanding the issue:

    1. There's a false positive in no-unused-vars rule when a TypeScript constructor parameter property shadows an imported identifier used in its own decorator.
    2. The example: const foo = { KEY: 'token' }; and then constructor(@Inject(foo.KEY) private readonly foo: number) {} - foo in the decorator resolves to the outer foo, not the parameter foo, because decorators are evaluated at class-decoration time before parameter bindings exist.

    Let me explore the repository structure first.

  3. DeepSeek Assistant

    Let me explore the relevant crates and find the no-unused-vars rule implementation

  4. DeepSeek Assistant

    The linter is in oxc_linter. Let me find the no-unused-vars rule.

  5. DeepSeek Assistant

    Hmm, no files found. Let me search more broadly.

  6. DeepSeek Assistant

    The no_unused_vars rule doesn't have its own file. Let me search for the main rule implementation

  7. DeepSeek Assistant

    Let me look for the main rule file.

  8. DeepSeek Assistant

    Let me look at the directory structure and the relevant source

  9. DeepSeek Assistant

    Let me first reproduce the issue, then explore the relevant code.

  10. DeepSeek Assistant

    Let me run oxlint on this file.

  11. DeepSeek Assistant

    Let me find the oxlint binary.

  12. DeepSeek Assistant

    That's a node wrapper. Let me check if there's a cargo-built binary. Let me also check what's available via cargo.

  13. DeepSeek Assistant

    Good, it built. Now let me run the test to reproduce the issue

  14. DeepSeek Assistant

    I've reproduced the issue. Now let me explore the relevant source code to understand how the analysis

  15. DeepSeek Assistant

    Let me use the correct command to open the file.

  16. DeepSeek Assistant

    Let me look at more of the file, especially the run function

  17. DeepSeek Assistant

    Let me scroll down to see the Rule implementation

  18. DeepSeek Assistant

    Let me continue reading the file

  19. DeepSeek Assistant

    Let me look at symbol.rs to understand how usages are tracked

  20. DeepSeek Assistant

    Let me continue reading this file

  21. DeepSeek Assistant

    Let me see more of the file, specifically has_usages

  22. DeepSeek Assistant

    Let me see the rest of the file

  23. DeepSeek Assistant

    I don't see has_usages in this file. Let me search for it

  24. DeepSeek Assistant

    Let me look at usage.rs

  25. DeepSeek Assistant

    Let me continue reading

  26. DeepSeek Assistant

    Let me understand the issue better by looking at how the semantic analysis handles scoping for class constructor parameters with decorators. Let me check the semantic crate

  27. DeepSeek Assistant

    Let me look at the semantic builder, particularly how it handles scopes

  28. DeepSeek Assistant

    Let me look at the visit_function in builder

  29. DeepSeek Assistant

    Let me look at how classes are handled

  30. DeepSeek Assistant

    Let me look at the visit_class method

  31. DeepSeek Assistant

    Let me look at visit_formal_parameters and `visit_formal_

  32. DeepSeek Assistant

    Let me look at the visit_formal_parameter function

  33. DeepSeek Assistant

    Now I can see the issue. In visit_formal_parameter, the parameter is bound first, then decorators are visited. But decorators should be evaluated in the enclosing scope before the parameter binding is created. Let me verify this by looking at how class elements/methods are visited

  34. DeepSeek Assistant

    Let me look at how class elements are visited

  35. DeepSeek Assistant

    Let me check how class elements are visited - maybe there's a generated visitor

  36. DeepSeek Assistant

    Let me check the AST visit crate for the generated

  37. DeepSeek Assistant

    Let me check how the semantic builder overrides the class element

  38. DeepSeek Assistant

    Now I understand the issue. In visit_formal_parameter, the parameter is bound BEFORE decorators are visited. This means that when @Inject(foo.KEY) is visited, foo resolves to the just-created parameter binding, not the outer one. The fix should be to swap the order: visit decorators first, then bind the parameter.

    But first, let me verify my understanding by looking at how reference resolution works and whether the scope is already active when visiting parameters

  39. DeepSeek Assistant

    Let me look at resolve_references_for_current_scope

  40. DeepSeek Assistant

    Let me look at walk_up_resolve_reference

  41. DeepSeek Assistant

    Let me look at the walk_up_resolve_reference function

  42. DeepSeek 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 a decorator like @Inject(foo.KEY) references foo, it resolves to the just-created parameter binding instead of the outer variable.

    The fix is to swap the order: visit decorators before binding the parameter. Let me make this change.

  43. DeepSeek Assistant

    Now let me make the fix. I'll swap the order of param.bind(self) and self.visit_decorators(&param.decorators) in both visit_formal_parameter and visit_formal_parameter_rest.

  44. DeepSeek Assistant

    Let me use the replace command with --file option

  45. DeepSeek Assistant

    Now let me fix visit_formal_parameter_rest as well

  46. DeepSeek Assistant

    Good. Now let me rebuild and test the fix

  47. DeepSeek Assistant

    Now let me test with the reproduction case

  48. DeepSeek Assistant

    The fix didn't work because references are resolved deferredly - by the time resolve_references_for_current_scope is called, all parameters have already been bound. Let me investigate more carefully

  49. DeepSeek Assistant

    Let me look at the walk_method_definition function

  50. DeepSeek Assistant

    Let me look at walk_method_definition

  51. DeepSeek Assistant

    Let me look at how references are created and their scope IDs are set

  52. DeepSeek Assistant

    Let me look at these

  53. DeepSeek Assistant

    Let me look at reference_identifier to understand how scope IDs are assigned to

  54. DeepSeek Assistant

    Now I understand the core issue. The reference is created with self.current_scope_id as its scope (line 2644). When visiting decorators inside visit_formal_parameter, the current scope is the function scope. So decorator references are scoped to the function scope, and they resolve to the parameter binding instead of the outer one.

    I need a different approach: temporarily change the current scope to the parent scope while visiting parameter decorators. Let me implement this.

  55. DeepSeek Assistant

    Now I need to modify the approach. Instead of just swapping, I need to temporarily change the scope while visiting decorators. Let me implement this

  56. DeepSeek Assistant

    Now do the same for visit_formal_parameter_rest

  57. DeepSeek Assistant

    Now let me build and test

  58. DeepSeek Assistant

    Let me test with the reproduction case

  59. DeepSeek Assistant

    The fix works! Now let me test with more edge cases to make sure nothing is broken

  60. DeepSeek Assistant

    Now let me actually think about this more carefully. Let me test the edge case file I created and also run the existing test suite to make sure I didn't break anything.

    But first, let me also verify: does the shadowed case still report correctly? Let me update the test file:

  61. DeepSeek Assistant

    Excellent! The fix works correctly:

    • foo used in @Inject(foo.KEY) → no warning ✓
    • bar used in @Inject(bar.KEY) → no warning ✓
    • notUsed with no decorator reference → correctly flagged as unused ✓

    Now let me run the existing test suite to make sure nothing is broken

  62. DeepSeek Assistant

    That error is unrelated to our changes. Let me run the tests without examples

  63. DeepSeek Assistant

    Now let me run the linter tests, specifically for no_unused_vars

  64. DeepSeek Assistant

    All 47 no_unused_vars tests pass. Let me run a broader set of tests to ensure nothing is broken

  65. DeepSeek Assistant

    Let me run with all features that are needed

  66. DeepSeek Assistant

    There are snapshot test failures. Let me check what they are about

  67. DeepSeek Assistant

    The snapshot differences are exactly what we'd expect: the decorator reference's scope_id changed from 3 (function scope) to 2 (parent/class scope). This is the correct behavior. Let me update the snapshots and verify the test inputs.

  68. DeepSeek Assistant

    Let me check the parameter-property test

  69. DeepSeek Assistant

    The snapshot changes are expected and correct. Let me accept the new snapshots

  70. DeepSeek Assistant

    Let me copy the new snapshots over the old ones

  71. DeepSeek Assistant

    Let me verify the updated snapshots look correct

  72. DeepSeek Assistant

    Let me re-run the tests

  73. DeepSeek Assistant

    Let me now run a broader set of tests to ensure nothing else is broken

  74. DeepSeek Assistant

    All 61 tests pass. Let me also run the linter tests again

  75. DeepSeek Assistant

    Let me also run the oxc_linter unit tests specifically

  76. DeepSeek Assistant

    All tests pass. Let me also search for any other places where parameter decorators are visited, to make sure I haven't missed any

  77. DeepSeek Assistant

    Good - only visit_formal_parameter and visit_formal_parameter_rest handle parameter decorators, and I've fixed both. Let me verify class/method decorators are already handled correctly by looking at the generated walk_method_definition again

  78. DeepSeek Assistant

    Let me run a quick comprehensive test to ensure nothing is broken, including some more edge cases

  79. DeepSeek Assistant

    Let me fix the test

  80. DeepSeek Assistant

    Let me check if the H class unused warning is pre-existing or caused by my change

  81. DeepSeek Assistant

    The H class unused warning is a pre-existing issue (same behavior before and after my change). My change correctly fixes the reported issue. Let me now run the full test suite

  82. DeepSeek Assistant

    Let me also run the linter tests one more time

  83. DeepSeek Assistant

    All tests pass. Let me view the diff of my

  84. DeepSeek Assistant

    The diff looks clean and correct. Let me do a final verification with the original reproduction case

  85. DeepSeek Assistant

    Wait, the binary might not be rebuilt. Let me rebuild and test again

  86. DeepSeek Assistant

    The fix works correctly. Let me clean up the temporary files and do a final review.

  87. DeepSeek Assistant

    Let me do a final review of the changes

  88. DeepSeek Assistant

    Let me also run a broader linter test to make sure nothing else breaks

  89. DeepSeek Assistant

    Let me also test with an import case to make sure it works as well

  90. DeepSeek Assistant

    Let me verify the snapshots look good without the assertion_line additions

  91. DeepSeek Assistant

    Let me check if other snapshot files have the assertion_line too

  92. DeepSeek Assistant

    Let me check

  93. DeepSeek Assistant

    Let me check if the assertion_line is present in other unmodified snap

  94. DeepSeek Assistant

    Let me verify the tests pass one final

  95. DeepSeek Assistant

    All tests pass. Let me clean up and submit.

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