Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@emilyinure
Copy link
Contributor

@emilyinure emilyinure commented Jul 31, 2025

… object on every assignment

Closes #6675

Summary

Accumulating Object.Assign isn't inherently bad as not all calls create new objects which result in the O(n*n) memory usage.

#6675
#5277

Test Plan

Testing shows that only when we are creating a new object every iteration, and assigning to it from the accumulator, it gets flagged

@changeset-bot
Copy link

changeset-bot bot commented Jul 31, 2025

🦋 Changeset detected

Latest commit: 984ea89

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Jul 31, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Jul 31, 2025

CodSpeed Performance Report

Merging #7078 will not alter performance

Comparing emilyinure:fix-accumulating-object-creation (984ea89) with main (0c8349e)

Summary

✅ 58 untouched
⏩ 95 skipped1

Footnotes

  1. 95 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@ematipico
Copy link
Member

Thank you @emilyinure, there are a couple of things to address:

  • Create a changeset. Remember to write the changeset for end-users, so they can understand the fix.
  • It seems that the examples of the documentation aren't valid anymore and need to be updated.

@ematipico
Copy link
Member

@emilyinure any updates?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 20, 2025

Walkthrough

The PR adjusts the no-accumulating-spread lint: Object.assign argument parsing now requires the first argument to be a composite literal ({}, [], new ...) to be treated as a newly allocated receiver, and the accumulator identifier is taken from the second argument. Calls where the accumulator identifier is the receiver are allowed. Test fixtures (valid/invalid) and a changeset entry reflecting the rule behaviour were updated.

Suggested reviewers

arendjr

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: modifying the no-accumulating-spread rule to only flag Object.assign when it allocates a new object per iteration, directly addressing issue #6675.
Description check ✅ Passed The description is relevant, explaining the motivation (Object.assign isn't inherently bad), referencing the closed issue (#6675), and describing the test plan validating the fix.
Linked Issues check ✅ Passed The PR successfully addresses issue #6675 by refining the no-accumulating-spread rule to distinguish between in-place Object.assign (allowed) and patterns creating new objects per iteration (flagged), meeting the stated objective.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing issue #6675: rule logic updates in no_accumulating_spread.rs, test case adjustments reflecting the new behaviour, and a changeset entry documenting the patch.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d442ba and 984ea89.

📒 Files selected for processing (1)
  • .changeset/wet-jeans-repair.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Check Dependencies
  • GitHub Check: Test Node.js API
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Lint project (depot-windows-2022)
🔇 Additional comments (1)
.changeset/wet-jeans-repair.md (1)

1-20: Changeset looks solid—all prior feedback addressed.

The entry properly follows the contribution guide (past tense, linked issue, code blocks) and provides clear examples showing both the false positives that are now allowed and the patterns that still warn. The JavaScript examples are syntactically correct and illustrate the O(n²) allocation problem well.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f328e1 and de4f1e3.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • .changeset/wet-jeans-repair.md (1 hunks)
  • crates/biome_js_analyze/src/lint/performance/no_accumulating_spread.rs (2 hunks)
  • crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc (1 hunks)
  • crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/valid.jsonc (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: Test Node.js API
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: autofix
🔇 Additional comments (4)
crates/biome_js_analyze/src/lint/performance/no_accumulating_spread.rs (2)

208-227: LGTM! The logic correctly identifies allocating patterns.

The updated argument extraction logic properly distinguishes between:

  • In-place mutation: Object.assign(acc, bar) → first arg is identifier, returns None (not flagged)
  • New allocation: Object.assign({}, acc, bar) → first arg is object literal, checks second arg as reference (flagged)

The implementation correctly handles edge cases like insufficient arguments by using the ? operator throughout the iterator chain.


46-64: LGTM! Documentation examples align with the new behavior.

The updated examples correctly demonstrate:

  • Invalid: Object.assign([], acc, val) creates a new array each iteration
  • Valid: Object.assign(acc, val) mutates the accumulator in-place
crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/valid.jsonc (1)

22-36: LGTM! Comprehensive test coverage for valid in-place mutations.

The test cases correctly cover all combinations:

  • Array and Object accumulators
  • Arrow and block return styles
  • Both reduce and reduceRight

All patterns use Object.assign(acc, bar) which mutates the accumulator in-place and should not be flagged.

crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread/invalid.jsonc (1)

35-57: LGTM! Thorough test coverage for allocating patterns.

The test cases correctly demonstrate the problematic patterns that allocate a new object/array on each iteration:

  • Object.assign({}, acc, bar) - new object literal
  • Object.assign([], acc, bar) - new array literal
  • Object.assign(new Array(1), acc, bar) - new array via constructor

These patterns all cause O(n²) time complexity and should be flagged by the rule.

@emilyinure emilyinure force-pushed the fix-accumulating-object-creation branch from f027d8f to b69596a Compare November 20, 2025 08:48
@emilyinure emilyinure force-pushed the fix-accumulating-object-creation branch from b69596a to d1df564 Compare November 20, 2025 08:49
Updated tense usage at the beginning of changeset, linked back to issue.
Moved examples to the inside of codeblocks
Explains which cases aren't caught anymore and which are.
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.changeset/wet-jeans-repair.md (1)

5-8: Minor punctuation improvement.

The description reads well but could be slightly clearer. The transition from "each iteration." to "Previously" might benefit from a stronger conjunction or restructuring:

-Fixed [#6675](https://github.com/biomejs/biome/issues/6675): Only flags
+Fixed [#6675](https://github.com/biomejs/biome/issues/6675): now only flags
 noAccumulatingSpread on Object.assign when a new object is being allocated on
-each iteration. Previously all cases using Object.assign with reduce parameters
+each iteration. Before, all cases using Object.assign with reduce parameters
 were warned despite not making new allocations.

This makes the before/after contrast more explicit.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 545963c and 99403fc.

📒 Files selected for processing (1)
  • .changeset/wet-jeans-repair.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
.changeset/wet-jeans-repair.md

[uncategorized] ~7-~7: Possible missing comma found.
Context: ...t is being allocated on each iteration. Previously all cases using Object.assign with redu...

(AI_HYDRA_LEO_MISSING_COMMA)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: autofix
  • GitHub Check: End-to-end tests
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Test Node.js API

Remove example that contains syntax error
Update grammer
Co-authored-by: Carson McManus <[email protected]>
@dyc3 dyc3 added this pull request to the merge queue Nov 21, 2025
Merged via the queue into biomejs:main with commit bb7a15c Nov 21, 2025
18 checks passed
@github-actions github-actions bot mentioned this pull request Nov 20, 2025
ryan-m-walker pushed a commit to ryan-m-walker/biome that referenced this pull request Nov 23, 2025
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 Object.assign on Accumulators SHOULD Be Allowed (Sometimes)

3 participants