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
- 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 arr.every((item, index, ...) => ...) whose callback body indexes a second array via other[index] (computed MemberExpression whose property identifier matches the callback's second parameter), indicating element-wise array comparison. The rule already skips calls sitting inside an existing arr.length === other.length && ... guard. False positive only if you intend to compare just a prefix.
Fix prompt
Use this once validation confirms the diagnostic is real.
Wrap with a length precheck: a.length === b.length && a.every((item, index) => item === b[index]). The && short-circuits the entire per-element loop when lengths differ — the cheapest possible early exit for deep array equality. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every
Related rules
More Performance rules from the rules reference:
react-doctor/js-min-max-loop: Use `Math.min(...array)` / `Math.max(...array)` instead of sorting just to read the first or last elementreact-doctor/js-set-map-lookups: Use a `Set` or `Map` for repeated membership tests / keyed lookups — `Array.includes`/`find` is O(n) per callreact-doctor/js-tosorted-immutable: Use `array.toSorted()` (ES2023) instead of `[...array].sort()` for immutable sorting without the spread allocationreact-doctor/jsx-no-constructed-context-values: Memoize the context value with useMemo/useCallback or hoist it outside the renderreact-doctor/jsx-no-jsx-as-prop: Hoist the inline JSX out of render or memoize it with useMemo so the prop value is stable across renders.