Skip to content

unicorn/no-array-reduce Restriction

What it does

Disallow Array#reduce() and Array#reduceRight().

Why is this bad?

Array#reduce() and Array#reduceRight() usually result in hard-to-read and less performant code. In almost every case, it can be replaced by .map, .filter, or a for-of loop.

It's only somewhat useful in the rare case of summing up numbers, which is allowed by default.

Example

javascript
array.reduce(reducer, initialValue);
array.reduceRight(reducer, initialValue);

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/no-array-reduce
json
{
  "rules": {
    "unicorn/no-array-reduce": "error"
  }
}

References

Released under the MIT License.