You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 11, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Feb 11, 2025. It is now read-only.
I've seen this pattern used several times where the developer is using spread inside a reduce causing a O(N^2) algorithm when avoiding the reduce would lead to O(N).
I googled "javascript spread reduce eslint" after reading an article on Tanstack Table and arrived here. I think a lot of devs (including myself) don't think about the implications of .... I'm not smart enough to help write a rule; just here to express interest :)
Activity
mrmckeb commentedon Jun 10, 2022
This is quite interesting, have you seen any lint rules around this that we could turn on?
mrmckeb commentedon Sep 21, 2022
@styfle did you have any thoughts around how we might introduce a rule like this?
Obviously this would need some discussion, as a lot of JS engineers like functional programming.
styfle commentedon Sep 21, 2022
I think there is little to discuss when we consider performance.
In fact, @pvdz just found a case where changing the spread in the loop brought the build time down from 18 min to 4 minutes.
Also see The reduce ({...spread}) anti-pattern blog post.
styfle commentedon Sep 21, 2022
I assume we need to write a eslint plugin. Something like this:
https://github.com/mkosir/eslint-plugin-no-array-reduce/blob/63b7792d1bbf3f8d3578fdb6fbde5982555f12c0/src/rules/disallowArrayMethod.ts#L11-L24
Or we could disable
.reduce()completely with no-array-reduce, but that might upset some engineers as you mentioned.AlexErrant commentedon Apr 7, 2023
I googled "javascript spread reduce eslint" after reading an article on Tanstack Table and arrived here. I think a lot of devs (including myself) don't think about the implications of
.... I'm not smart enough to help write a rule; just here to express interest :)Conaclos commentedon Dec 4, 2023
We added this rule to Biome several months ago. Any feedbacks are welcomed :)
feat(linter): cxc: no accumulating spread (#1607)