src/content/docs/linter/rules/no-accumulating-spread.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/performance/noAccumulatingSpread`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). ## How to configure ```json title="biome.json" { "linter": { "rules": { "performance": { "noAccumulatingSpread": "error" } } } }## Description
Disallow the use of spread (`...`) syntax on accumulators.
Spread syntax allows an iterable to be expanded into its individual elements.
Spread syntax should be avoided on accumulators (like those in `.reduce`)
because it causes a time complexity of `O(n^2)` instead of `O(n)`.
Source: https://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/
## Examples
### Invalid
```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => [...acc, val], []);
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return [...acc, val];}, []);
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => ({...acc, [val]: val}), {});
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return Object.assign([], acc, val);}, []);
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {acc.push(val); return acc}, []);
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => Object.assign(acc, val), []);
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return Object.assign(acc, val);}, []);