From 38d01250f423943be061c6a3cac0035ccfce6a09 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 8 Apr 2025 12:18:17 +0200 Subject: [PATCH] Enable the `no-array-reduce` ESLint plugin rule Please see https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-reduce.md Note that this still allows "simple" usage of `Array.prototype.reduce`, however most of those cases will be possible to replace with `Math.sumPrecise` once that becomes generally available (currently not supported in Node.js or QuickJS). --- eslint.config.mjs | 1 + test/stats/statcmp.js | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/eslint.config.mjs b/eslint.config.mjs index a2fbd20fd..ffb146870 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -127,6 +127,7 @@ export default [ "perfectionist/sort-named-exports": "error", "unicorn/no-abusive-eslint-disable": "error", "unicorn/no-array-push-push": "error", + "unicorn/no-array-reduce": ["error", { allowSimpleOperations: true }], "unicorn/no-console-spaces": "error", "unicorn/no-instanceof-builtins": "error", "unicorn/no-invalid-remove-event-listener": "error", diff --git a/test/stats/statcmp.js b/test/stats/statcmp.js index eca8457bb..be8cfc9c1 100644 --- a/test/stats/statcmp.js +++ b/test/stats/statcmp.js @@ -76,10 +76,7 @@ function pad(s, length, dir /* default: 'right' */) { } function mean(array) { - function add(a, b) { - return a + b; - } - return array.reduce(add, 0) / array.length; + return array.reduce((a, b) => a + b, 0) / array.length; } /* Comparator for row key sorting. */