
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
eslint-plugin-no-array-reduce
Advanced tools
ESLint rule to disallow Array.reduce()
method.
Method reduce()
in most cases can be written as map()
, filter()
etc. which benefits in code readability and makes it easier to maintain for future developers.
Subjectively there are still cases where you might want to use reduce()
with eslint-disable
.
There are many debates related to it:
npm install --save-dev eslint-plugin-no-array-reduce
Then extend eslint config:
{
"extends": [
// ...
"plugin:no-array-reduce/recommended"
]
}
const products = [
{ name: 'milk', type: 'dairy' },
{ name: 'cheese', type: 'dairy' },
{ name: 'beef', type: 'meat' },
{ name: 'chicken', type: 'meat' },
];
// Add price to each product
const productsWithPrices = products.reduce((acc, product) => acc.concat({ ...product, price: 2.7 }), []);
// Filter dairy products
const dairies = products.reduce((acc, product) => (product.type === 'dairy' ? acc.concat(product) : acc), []);
// Group products by type
const productsByType = products.reduce(
(acc, product) => ({
...acc,
[product.type]: [...(acc[product.type] || []), product],
}),
[],
);
// Add price to each product
const productsWithPrices = products.map((product) => ({ ...product, price: 2.7 }));
// Filter dairy products
const dairies = products.filter((product) => product.type === 'dairy');
// Group products by type (ECMA stage 3 - https://github.com/tc39/proposal-array-grouping)
const productsByType = products.group((product) => product.type);
All contributions are welcome!
FAQs
ESLint rule to disallow Array.reduce() method.
The npm package eslint-plugin-no-array-reduce receives a total of 2,220 weekly downloads. As such, eslint-plugin-no-array-reduce popularity was classified as popular.
We found that eslint-plugin-no-array-reduce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.