accumulatorCopyDo not copy the reducer accumulator on every iteration; growing copies can cause quadratic work. Mutate a fresh, locally owned accumulator and return it, or use an iterator pipeline or flatMap.small-rules/no-reduce-accumulator-copyDisallow copying growing reducer accumulators with Object.assign, Array.from, or array copy methods.
Ported from dmmulroy/anti-slop. A reduce that copies its
accumulator on each step does more work as the result grows. That turns a linear pass into quadratic work.
Build a new accumulator in the reduce call, change it in place, and return it. Pair this rule with Oxc’s
no-accumulating-spread, which catches the spread form.
accumulatorCopyDo not copy the reducer accumulator on every iteration; growing copies can cause quadratic work. Mutate a fresh, locally owned accumulator and return it, or use an iterator pipeline or flatMap.This rule does not accept options.
const byId = items.reduce((accumulator, item) => Object.assign({}, accumulator, { [item.id]: item }), {});const byId = items.reduce<Record<string, Item>>((accumulator, item) => { accumulator[item.id] = item; return accumulator;}, {});