You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-array-reduce

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-array-reduce

ESLint rule to disallow Array.reduce() method.

1.0.6
Source
npm
Version published
Weekly downloads
2.3K
-8.92%
Maintainers
1
Weekly downloads
 
Created
Source

eslint-plugin-no-array-reduce

npm version CI semantic-release TypeScript

ESLint rule to disallow Array.reduce() method.

Method reduce() in most cases can be written as map(), filter() or one of the for() loops which benefits in code readability and makes it easier to maintain for future developers.
There are many debates, discussions and other resources related to it:

Install

npm install --save-dev eslint-plugin-no-array-reduce

Then extend eslint config:

{
  "extends": [
    // ...
    "plugin:no-array-reduce/recommended"
  ]
}

Fail

const groceries = [
  { name: 'milk', type: 'dairy' },
  { name: 'cheese', type: 'dairy' },
  { name: 'beef', type: 'meat' },
];

// Filter dairy products
const dairy = groceries.reduce((acc, grocery) => (grocery.type === 'dairy' ? acc.concat(grocery) : acc), []);

Pass

// Filter dairy products
const dairy = groceries.filter((grocery) => grocery.type === 'dairy');

Subjectively there are cases where you still might want to use reduce() with eslint-disable.

Contributing

All contributions are welcome!

Keywords

javascript

FAQs

Package last updated on 28 Jul 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts