Skip to content

linter: oxc/double-comparisons --fix swaps operands and changes logic #19845

@hratio

Description

@hratio

What version of Oxlint are you using?

1.50.0

What command did you run?

oxlint --fix --config oxlint.config.ts repro.ts

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

import { defineConfig } from "oxlint";
export default defineConfig({
    plugins: ["oxc"],
    rules: {
        "oxc/double-comparisons": "error"
    }
});

What happened?

It appears the autofix is changing expression semantics by swapping comparator order.

Repro:

  1. repro.ts smelly input:
export const check = (a: number, b: number) => {
  if (a === b || b < a) {
    return "invalid";
  }
  return "ok";
};
  1. Run: oxlint --fix --config oxlint.config.ts repro.ts
  2. Actual output after fix:
if (a <= b) {
  return "invalid";
}
  1. Expected equivalent simplification:
if (b <= a) {
  return "invalid";
}

The autofix changed behavior:

  • Original is true when b <= a
  • Fixed output is true when a <= b

It is not a safe autofix for this type of code smell, my question is if it should either:

  • be fixed to preserve operand order correctly, or
  • be moved behind dangerous fixes (--fix-dangerously/fix-suggestions) ?

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