What version of Oxlint are you using?
oxlint 1.71.0
What command did you run?
pnpm oxlint \
--config scratch/oxlint-no-useless-assignment-conditional-update-repro.oxlintrc.json \
scratch/oxlint-no-useless-assignment-conditional-update-repro.ts
What happened?
eslint/no-useless-assignment reports the conditional update expression in a for loop as unused:
function collectIds(ids: readonly string[], forward: boolean): string[] {
const collected: string[] = [];
const startIndex = forward ? 0 : ids.length - 1;
for (
let index = startIndex;
forward ? index < ids.length : index >= 0;
forward ? index++ : index--
) {
collected.push(ids[index]!);
}
return collected;
}
Oxlint reports both index++ and index-- as useless assignments.
Those updates are used by the next loop condition check and by the next iteration's body. Without them, the loop behavior changes.
What did you expect to happen?
No diagnostic. The updated value is observably used on the next iteration.
Additional context
This came up while migrating a larger codebase to oxlint.
What version of Oxlint are you using?
oxlint1.71.0What command did you run?
What happened?
eslint/no-useless-assignmentreports the conditional update expression in aforloop as unused:Oxlint reports both
index++andindex--as useless assignments.Those updates are used by the next loop condition check and by the next iteration's body. Without them, the loop behavior changes.
What did you expect to happen?
No diagnostic. The updated value is observably used on the next iteration.
Additional context
This came up while migrating a larger codebase to oxlint.