Skip to content

linter: prefer-const false positive when reassigning with += #19973

@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" }],

async function destroyItems() {
  return Promise.resolve(4);
}


async function myFunction() {
  let nItemsDestroyed: number;
  nItemsDestroyed = await destroyItems();
  nItemsDestroyed += await destroyItems();
  console.info(`destroyItem: ${nItemsDestroyed} items destroyed.`);
}

myFunction();

And got the false positive report:

  × eslint(prefer-const): `nItemsDestroyed` is never reassigned.
   ╭─[index.ts:7:7]
 6 │ async function myFunction() {
 7 │   let nItemsDestroyed: number;
   ·       ───────────────
 8 │   nItemsDestroyed = await destroyItems();
   ╰────
  help: Use `const` instead.

ESLint does not flag on the same configuration.

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

Metadata

Metadata

Assignees

No one assigned

    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