npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-reduce

v0.1.0

Published

ESLint plugin that flags spread syntax inside Array.prototype.reduce callbacks, which can cause significant performance issues.

Readme

eslint-plugin-reduce

npm version License: MIT CI

An ESLint plugin whose no-spread-in-reduce rule flags spreading syntax (...) inside an Array.prototype.reduce() callback. Building a new accumulator with spread on every iteration allocates a new object/array and copies all existing keys, which turns an O(n) reduction into O(n²) work on large inputs.

// ✗ bad — new object allocated and copied on every iteration
items.reduce((acc, item) => ({ ...acc, [item.id]: item }), {})

// ✓ good — mutate a single accumulator instead
items.reduce((acc, item) => {
  acc[item.id] = item
  return acc
}, {})

Why this rule exists

Spread (...) is essentially a for loop that copies every element. Inside Array.prototype.reduce, using spread to rebuild the accumulator copies the whole accumulator on every iteration, turning an O(n) reduction into O(n²) work — plus one discarded allocation per step. The bigger the accumulator grows, the worse it gets.

A real-world example:

This rule flags that pattern statically. It is a heuristic: spreading an accumulator that stays small is harmless, which is why it ships as a warning by default. If you'd rather fail the build, raise it to error.

Further reading

Compatibility

  • ESLint 9 and 10 are supported (peer dependency ^9.0.0 || ^10.0.0). Flat config only, which is the default in both.
  • Works with either the CommonJS or ESM entry points: require('eslint-plugin-reduce') or import reducePlugin from 'eslint-plugin-reduce'.
  • Oxlint can run this plugin too, through its ESLint-compatible JS plugin API — see Usage with Oxlint.
  • Node.js ^20.19.0 || ^22.13.0 || >=24 — mirrors ESLint 10's own requirement (Node 18/21/23 are not supported).

Install

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

Usage (flat config, ESLint >= 9)

// eslint.config.js
import reducePlugin from 'eslint-plugin-reduce'

export default [
  reducePlugin.configs.recommended,
  // ...or enable the rule manually:
  // {
  //   plugins: { reduce: reducePlugin },
  //   rules: { 'reduce/no-spread-in-reduce': 'warn' },
  // },
]

A runnable example lives in examples/eslint.

Usage with Oxlint

Oxlint's JS plugin API is ESLint v9+ compatible, so the same plugin runs there unchanged — no separate build or fork. Oxlint does not read ESLint's flat-config presets, so register the plugin under jsPlugins and enable the rule under rules:

// .oxlintrc.json
{
  "jsPlugins": ["eslint-plugin-reduce"],
  "rules": {
    "reduce/no-spread-in-reduce": "warn"
  }
}
// oxlint.config.ts
import { defineConfig } from "oxlint"

export default defineConfig({
  jsPlugins: ["eslint-plugin-reduce"],
  rules: {
    "reduce/no-spread-in-reduce": "warn",
  },
})

The rule ID is identical in both linters (Oxlint strips the eslint-plugin- prefix). Oxlint's JS plugins are currently in alpha.

A runnable example lives in examples/oxlint.

Severity

Severity is yours to choose — it is set in your config, not by the rule. The bundled recommended preset uses warn because the rule is a heuristic (a small, non-growing accumulator is fine to spread):

rules: {
  // default from `configs.recommended`
  'reduce/no-spread-in-reduce': 'warn',
  // fail the build instead
  'reduce/no-spread-in-reduce': 'error',
}

Rule options

The rule takes no options.

Detected patterns

The rule inspects the callback body and its if / else branches of a reduce call, and reports spread syntax found in:

  • object expressions — { ...acc }
  • array expressions — [...acc, item]
  • conditional expressions — cond ? { ...acc } : acc
  • TypeScript as expressions — { ...acc } as Record<string, unknown>
  • assignments — acc = { ...acc }

It's a syntactic check with no scope analysis: it reports any spread of the returned value, so a spread that isn't the accumulator can be reported too, and some wrappers aren't seen through. If a report is intentional, silence it for the line:

// eslint-disable-next-line reduce/no-spread-in-reduce

License

MIT