Skip to content

[prefer-spread-syntax] Fix bug: Object.assign({}, ...arrOfObjs) incorrectly auto-fixed#91

Merged
43081j merged 1 commit intoe18e:mainfrom
oBusk:assign-89
Mar 23, 2026
Merged

[prefer-spread-syntax] Fix bug: Object.assign({}, ...arrOfObjs) incorrectly auto-fixed#91
43081j merged 1 commit intoe18e:mainfrom
oBusk:assign-89

Conversation

@oBusk
Copy link
Copy Markdown
Contributor

@oBusk oBusk commented Mar 23, 2026

This PR changes ``Object.assign({}, ...myArrOfObjects)` to be treated as valid syntax as it cannot be easily fixed/replaced.

Usecase for this is collecting patches as an array and then applying all of them at a time

const arr = [{ a: 1 }, { a: 2, b: 3}, { c: 4 }];

const result = Object.assign({}, ...arr);

The easiest way (I can think of) to perform this without Object.assign() would be using many spreads in a reduce

const arr = [{ a: 1 }, { a: 2, b: 3 }, { c: 4 }];
const result = arr.reduce((acc, obj) => ({ ...acc, ...obj }), {});

But from my basic grasp of eslint fixers, that would be complicated to support, especially since it can be Object.assign({}, ...arr, another, ...arr2) and so on.

This fixes #89

@43081j
Copy link
Copy Markdown
Contributor

43081j commented Mar 23, 2026

This is the correct way to fix it 👍

thanks for the PR and good catch!

@43081j 43081j merged commit 0030c30 into e18e:main Mar 23, 2026
3 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.

bug(prefer-spread-syntax): Fixer produces invalid syntax when using spread in Object.assign()

3 participants