ITADN

`no-array-reduce`: prefer Math.sumPrecise

#3252Closedfregante 创建于 2026-06-15
evaluatingchange request
F
fregantecommented
### Description This is currently allowed by default by `no-array-reduce` but it can now be replaced by `Math.sumPrecise` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sumPrecise ### Examples ```js // ❌ array.reduce((total, item) => total + item) // ✅ Math.sumPrecise(array) ``` ### Additional Info The problem is that it's very new and in no versions of Node yet. At a minimum, for 2026, the rule could: - provide a suggestion for the code _if_ `allowSimpleOperations === false` In the future it could just: - be a default - autofix it Note that in cases where `array` isn't a simple `number[]`, the solution would still require a loop: ```js // ❌ array.reduce((total, item.length) => total + item.length) // ✅ Math.sumPrecise(array.map((item) => item.length))
关闭于 2026-06-15 0 条评论