Skip to content

feat(anti-slop): add no-reduce-accumulator-copy rule - #86

Merged
howmanysmall merged 3 commits into
mainfrom
feat/anti-slop-no-reduce-accumulator-copy
Oct 15, 2026
Merged

howmanysmall merged 3 commits into
mainfrom
feat/anti-slop-no-reduce-accumulator-copy

Conversation

@howmanysmall

Copy link
Copy Markdown
Owner

Summary

Vendors a new anti-slop rule that flags reducers copying their accumulator each iteration, and wires it through the plugin, docs, and lint config.

 src/rules/anti-slop/
+├── no-reduce-accumulator-copy.ts   # flags Object.assign/Array.from/array-copy of the accumulator
 ├── no-module-mocking.ts
 └── ...
 src/utilities/
-└── ast-utilities.ts
+└── ast-utilities.ts                # + getReferencedVariable, + hasUninitializedWrite
 tests/rules/anti-slop/
+└── no-reduce-accumulator-copy.test.ts
 documentation/src/content/docs/rules/anti-slop/
+└── no-reduce-accumulator-copy.mdx

Rebases the vendored anti-slop snapshot onto upstream c44ef22 and lifts the shared resolveVariable/hasUninitializedWrite helpers out of individual rules into ast-utilities.ts, so no-module-mocking, no-widen-then-assert, and reflect-method reuse them instead of re-implementing.

Evidence

  • Before: no-reduce-accumulator-copy did not exist, so the fixtures in tests/rules/anti-slop/no-reduce-accumulator-copy.test.ts could not run against a rule.
    After: nr test tests/rules/anti-slop/no-reduce-accumulator-copy.test.ts
Test Files  2 passed (2)
     Tests  72 passed (72)
Type Errors  no errors

The suite covers the positive cases (Object.assign({}, acc, …), Array.from(acc), acc.concat/slice/toReversed/… with an array initial value) plus aliases, shadowed globals, non-array initial values, and nested functions.

Merge Danger

Door: two-way — the rule is additive and revertable.

Blast Radius: consumers.

Adding small-rules/no-reduce-accumulator-copy: error to the default oxlint config means existing reduce-copy code will start erroring on upgrade; the rule only fires when the reducer's initial value is provably an array, or the copy target is a fresh object literal.

Signed-off-by: howmanysmall <26746527+howmanysmall@users.noreply.github.com>
Ports the no-reduce-accumulator-copy rule from dmmulroy/anti-slop and
enables it in the oxlint configuration. The rule flags reducers that
copy their accumulator on every step (via Object.assign, Array.from, or
array copy methods), which turns a linear pass into quadratic work.

Also bumps the vendored anti-slop commit to c44ef22 and adds shared
ast-utilities helpers used by the new rule.

Signed-off-by: howmanysmall <26746527+howmanysmall@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit d8ebedb.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Bundle size

Artifact Base Pull request Change
dist/index.js 486.04 kB 489.01 kB +2.97 kB (+0.61%)

Raw, uncompressed bytes from the minified prepublishOnly build. Measured for commit d8ebedb against base 386995e.

…uce-accumulator-copy

Signed-off-by: howmanysmall <26746527+howmanysmall@users.noreply.github.com>
@howmanysmall
howmanysmall merged commit 63fbdc2 into main Oct 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant