Repository navigation
feat(anti-slop): add no-reduce-accumulator-copy rule - #86
Open
howmanysmall wants to merge 2 commits into
Open
howmanysmall wants to merge 2 commits into
howmanysmall wants to merge 2 commits into
Conversation
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>
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
Contributor
Bundle size
Raw, uncompressed bytes from the minified |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Rebases the vendored
anti-slopsnapshot onto upstreamc44ef22and lifts the sharedresolveVariable/hasUninitializedWritehelpers out of individual rules intoast-utilities.ts, sono-module-mocking,no-widen-then-assert, andreflect-methodreuse them instead of re-implementing.Evidence
no-reduce-accumulator-copydid not exist, so the fixtures intests/rules/anti-slop/no-reduce-accumulator-copy.test.tscould not run against a rule.After:
nr test tests/rules/anti-slop/no-reduce-accumulator-copy.test.tsThe 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: errorto 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.