Skip to content

Linter plugins: sourceCode.markVariableAsUsed does not communicate vars marked as used to Rust rules #20350

@overlookmotel

Description

@overlookmotel

#20357 implemented sourceCode.markVariableAsUsed method. However, it has some shortcomings.

At present it doesn't communicate back to Rust that the variable is marked as used, so Rust rules like no-unused-vars will not take that into account.

Fixing this will be difficult. Currently JS rules run after Rust rules, so by the time a var is marked as used, it's too late for no-unused-vars. Only solution is to make JS rules run first, but that's hard as the AST is mutated to convert UTF-8 spans to UTF-16 before sending to JS, and that would not work on Rust side, as Rust uses UTF-8 strings.

Workaround

If it's essential for no-unused-vars to receive the signals from markVariableAsUsed, the only current solution is to run the original ESLint no-unused-vars rule as a JS plugin:

{
  "jsPlugins": ["oxlint-plugin-eslint"],
  "rules": {
    "eslint-js/no-unused-vars": "error"
  }
}

(note the eslint-js prefix on the rule name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions