New
Introducing React Doctor for Enterprise

react-doctor/js-early-exit

Add an early `return` / `continue` to flatten deep nesting and short-circuit when the predicate is already known

  • Category: Performance
  • Severity: warn
  • Source: oxlint-plugin-react-doctor
  • Framework: global
  • Enabled when: always

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

The rule fires on a single-branch chain of nested ifs (each consequent is a block containing exactly one IfStatement) reaching depth >= 3 — i.e. if { if { if { if { ... } } } } with no else branches and no sibling statements. False positive only if you're outside a function or loop where return/continue is impossible.

Fix prompt

Use this once validation confirms the diagnostic is real.

Invert each guard up front: if (!precondition) return; if (!nextCondition) return; ..., leaving the happy path un-indented at the outermost level. In a loop use continue instead. Drops cognitive load and prevents indentation creep when new branches get added later. https://refactoring.guru/replace-nested-conditional-with-guard-clauses

More Performance rules from the rules reference:

  • react-doctor/js-flatmap-filter: Use `.flatMap(item => condition ? [value] : [])` — transforms and filters in a single pass instead of creating an intermediate array
  • react-doctor/js-hoist-intl: Hoist `new Intl.NumberFormat(...)` to module scope or wrap in `useMemo` — Intl constructors allocate dozens of objects per locale lookup
  • react-doctor/js-hoist-regexp: Hoist `new RegExp(...)` (or large regex literals) to a module-level constant so it isn't recompiled on every loop iteration
  • react-doctor/js-index-maps: Build an index `Map` once outside the loop instead of `array.find(...)` inside it
  • react-doctor/js-length-check-first: Short-circuit with `a.length === b.length && a.every((x, i) => x === b[i])` — unequal-length arrays exit immediately