Skip to content

feat!: add no-reduce-accumulator-copy rule - #62

Merged
davidding merged 5 commits into
mainfrom
feature/add-no-reduce-accumulator-copy-rule
Aug 24, 2026
Merged

feat!: add no-reduce-accumulator-copy rule#62
davidding merged 5 commits into
mainfrom
feature/add-no-reduce-accumulator-copy-rule

Conversation

@davidding

@davidding davidding commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Purpose / Goal

Adds an ESLint rule that flags O(n²) accumulator copies inside reduce/reduceRight callbacks — object spreads ({ ...acc }, [...acc]), and acc.concat() — and directs developers toward a for...of loop with mutation or a purpose-built method (e.g. flatMap, Object.groupBy).

Summary of Changes 📋

  • Add plugins/hs-web-team/rules/no-reduce-accumulator-copy.js — ESM named export, implemented using context.sourceCode.getScope(node) (ESLint v9 flat config API)
  • Add plugins/hs-web-team/index.js — shared plugin registry; exposes hsWebTeamPlugin.configs.recommended (following the typescript-eslint/eslint-plugin-react pattern) so both index.js and browser.js spread a single config object rather than duplicating plugin registration. Rules are co-located under plugins/hs-web-team/rules/ following the same layout as standalone ESLint plugin packages.
  • Add eslint.config.js — repo-local config that extends the shared Node config; adds Cypress globals for cypress/** so no-undef does not false-positive on Cypress/cy
  • Remove eslint.config.js from commonIgnores in both configs — config files should meet the same lint standards as any other file
  • Update lint script to eslint . (was eslint -c ./index.js *.js) so all subdirectories are covered without an explicit include list
  • Add tests/plugins/hs-web-team/no-reduce-accumulator-copy.test.js — 10 test cases via node:test + ESLint RuleTester, covering object spread, array spread, concat, reduceRight, in-place mutation (valid), and non-accumulator spreads (valid)
  • Set npm test to node --test and add a test step to the PR workflow
  • Add files field to package.json — scopes the published tarball to only the files consumers need; excludes tests, .github/, .githooks/, eslint.config.js, and CLAUDE.md
  • Add examples/custom-rules.md — documents the bundled hs-web-team plugin rules with bad/good code examples and remediation guidance
  • Update README.md — add "Custom Rules" section and index entry linking to the new examples file

Screenshot(s) or GIF(s) 📸

N/A - No UI changes

Production Checklist ✅

  • No additional steps required

Relevant Links 🔗

  • N/A

Coding Standards Doc ⌨️

@davidding
davidding force-pushed the feature/add-no-reduce-accumulator-copy-rule branch from e129340 to 14d1c89 Compare August 18, 2026 12:36
darkmavis1980
darkmavis1980 previously approved these changes Aug 19, 2026
denisolvr
denisolvr previously approved these changes Aug 19, 2026
Comment thread plugins/hs-web-team/rules/no-reduce-accumulator-copy.js
@darkmavis1980

Copy link
Copy Markdown
Contributor

Also don't forget to set the version properly to be a minor

@davidding

Copy link
Copy Markdown
Contributor Author

Also don't forget to set the version properly to be a minor

@darkmavis1980 Version numbers are automatically handled by the release workflow, based on conventional commit messages - #52

@davidding
davidding dismissed stale reviews from denisolvr and darkmavis1980 via ede91b4 August 20, 2026 11:28

@denisolvr denisolvr left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: Is the -copy.js files on purpose named as copy?

@davidding

Copy link
Copy Markdown
Contributor Author

question: Is the -copy.js files on purpose named as copy?

@denisolvr - Yes, the new rule is no-reduce-accumulator-copy.

@davidding
davidding enabled auto-merge (squash) August 24, 2026 09:01
@davidding
davidding requested a review from denisolvr August 24, 2026 09:01
@davidding
davidding merged commit c70cab7 into main Aug 24, 2026
1 check passed
@davidding
davidding deleted the feature/add-no-reduce-accumulator-copy-rule branch August 24, 2026 09:02
@davidding davidding changed the title feat: add no-reduce-accumulator-copy rule feat!: add no-reduce-accumulator-copy rule Aug 24, 2026
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.

3 participants