Skip to content

linter: prefer-const false positive on destructure assignment with existing variable #19974

@MichaelGoff

Description

@MichaelGoff

What version of Oxlint are you using?

1.51.0

What command did you run?

npx oxlint

What does your .oxlintrc.json (or oxlint.config.ts) config file look like?

{
  "env": {
    "browser": true,
    "node": true,
    "jest": true
  },
  "categories": {
    "correctness": "error"
  },
  "plugins": ["import", "unicorn", "typescript", "oxc", "vue"],
  "rules": {
    "prefer-const": ["error", { "destructuring": "all" }],
  }
}

What happened?

Ran oxlint on the following with prefer-const set to "prefer-const": ["error", { "destructuring": "all" }]

let someOuterScopeVariable : string;

async function generatorFunction() {
  return {
    inner: 'foo',
    outer: 'bar',
  };
}

async function myFunction() {
  let innerScope: string;
  // destructure assignment to existing variables
  ({inner: innerScope, outer: someOuterScopeVariable} = await generatorFunction());

  console.info(`${innerScope}, ${someOuterScopeVariable}`);
}

myFunction();

And got the false positive report:

  × eslint(prefer-const): `innerScope` is never reassigned.
    ╭─[index.ts:11:7]
 10 │ async function myFunction() {
 11 │   let innerScope: string;
    ·       ──────────
 12 │   // destructure assignment to existing variables
    ╰────
  help: Use `const` instead.

ESLint does not flag on the same configuration.

Reproduction: https://github.com/MichaelGoff/oxlint-prefer-const/tree/prefer-const-destructure-assignment

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions