eslint-plugin-no-array-reduce
raw JSON → 1.0.62 verified Sat Apr 25 auth: no javascript
ESLint plugin that bans the usage of Array.prototype.reduce() in favor of more readable array methods like map, filter, and group. Version 1.0.62 (latest), maintained with regular updates. It provides a single rule that flags all reduce() calls, with an option to allow reduce() via eslint-disable comments. Differentiator: enforces a stylistic preference against reduce() with no configuration needed, unlike general-purpose ESLint rules that require custom configuration.
Common errors
error ESLint: Failed to load plugin 'no-array-reduce': Cannot find module 'eslint-plugin-no-array-reduce' ↓
cause The plugin is not installed or not in node_modules.
fix
Run npm install --save-dev eslint-plugin-no-array-reduce
error ESLint: Configuration for rule 'no-reduce' is invalid. Rule 'no-reduce' not found. ↓
cause Using the rule name without the plugin prefix.
fix
Use 'no-array-reduce/no-reduce' as the rule name.
error TypeError: Cannot read property 'some' of undefined (when using TypeScript parser) ↓
cause The plugin expects ESLint >=7.0.0 and may have issues with older versions or custom parsers.
fix
Ensure ESLint version is 7.0.0 or higher.
Warnings
gotcha The rule only flags Array.prototype.reduce() calls, not other reduce-like methods (e.g., Array.prototype.reduceRight()). ↓
fix If you want to disallow reduceRight(), you need a separate rule or manual linting.
gotcha The rule triggers on any .reduce() call, including those from polyfills or custom objects that happen to have a reduce method. It does not check the receiver type. ↓
fix Use eslint-disable comments to suppress false positives on non-Array objects.
deprecated There are no known breaking changes as the plugin is stable and v1.x only. Always upgrade to latest patch for TypeScript compatibility fixes. ↓
fix Run npm update eslint-plugin-no-array-reduce regularly.
Install
npm install eslint-plugin-no-array-reduce yarn add eslint-plugin-no-array-reduce pnpm add eslint-plugin-no-array-reduce Imports
- plugin wrong
const plugin = require('eslint-plugin-no-array-reduce')correct// In .eslintrc: { "plugins": ["no-array-reduce"] } - recommended config wrong
// No common wrong import; ensure correct plugin name in 'extends'.correct// In .eslintrc: { "extends": ["plugin:no-array-reduce/recommended"] } - rule itself wrong
// Using rule name without prefix: { "rules": { "no-reduce": "error" } }correct// In .eslintrc: { "rules": { "no-array-reduce/no-reduce": "error" } }
Quickstart
// Install the plugin
npm install --save-dev eslint-plugin-no-array-reduce
// Add to .eslintrc.json:
{
"plugins": ["no-array-reduce"],
"extends": ["plugin:no-array-reduce/recommended"]
}
// Example file that will fail linting:
const arr = [1, 2, 3];
const sum = arr.reduce((acc, x) => acc + x, 0);
// Example file that passes:
const sum = arr.reduce((acc, x) => acc + x, 0); // eslint-disable-line no-array-reduce/no-reduce