Skip to content

test(formatter): add regression test for member chain with rest params#18835

Merged
graphite-app[bot] merged 1 commit intomainfrom
test/issue-16177
Feb 2, 2026
Merged

test(formatter): add regression test for member chain with rest params#18835
graphite-app[bot] merged 1 commit intomainfrom
test/issue-16177

Conversation

@Dunqing
Copy link
Member

@Dunqing Dunqing commented Feb 2, 2026

Closes #16177

Summary

Details

The issue was that member chains would incorrectly break when a function expression had rest parameters:

Before (incorrect):

jest
  .spyOn(Element.prototype, "getBoundingClientRect")
  .mockImplementation(function (this: Element, ...args) {

After (correct - matches Prettier):

jest.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function (
  this: Element,
  ...args
) {

This was fixed by #17354, which ensures the rest parameter is not considered "simple", allowing the member chain to stay hugged while function parameters break vertically.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 2, 2026 02:23
@github-actions github-actions bot added the A-formatter Area - Formatter label Feb 2, 2026
@github-actions github-actions bot added the C-test Category - Testing. Code is missing test cases, or a PR is adding them label Feb 2, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a regression test for issue #16177, which involved incorrect formatting of member chains when function expressions contained rest parameters. The fix (already implemented in commit 745bc5d) ensures that functions with rest parameters are not considered "simple", allowing member chains to stay hugged while function parameters break vertically, matching Prettier's behavior.

Changes:

  • Adds test input file issue-16177.ts with a member chain containing a function with rest parameters
  • Adds test snapshot issue-16177.ts.snap verifying correct formatting at different print widths

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts Test input demonstrating member chain with function expression that has rest parameters
crates/oxc_formatter/tests/fixtures/ts/member-chains/issue-16177.ts.snap Expected output snapshot showing correct formatting at printWidth 80 (chain breaks) and 100 (chain stays hugged)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member Author

Dunqing commented Feb 2, 2026


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@leaysgur leaysgur added the 0-merge Merge with Graphite Merge Queue label Feb 2, 2026
Copy link
Member

leaysgur commented Feb 2, 2026

Merge activity

  • Feb 2, 2:39 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 2, 2:39 AM UTC: leaysgur added this pull request to the Graphite merge queue.
  • Feb 2, 2:45 AM UTC: The Graphite merge queue couldn't merge this PR because it failed for an unknown reason.
  • Feb 2, 2:50 AM UTC: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Feb 2, 2:50 AM UTC: Dunqing added this pull request to the Graphite merge queue.
  • Feb 2, 2:50 AM UTC: Merged by the Graphite merge queue.

#18835)

Closes #16177

## Summary
- Adds a regression test for issue #16177

## Details

The issue was that member chains would incorrectly break when a function expression had rest parameters:

**Before (incorrect):**
```ts
jest
  .spyOn(Element.prototype, "getBoundingClientRect")
  .mockImplementation(function (this: Element, ...args) {
```

**After (correct - matches Prettier):**
```ts
jest.spyOn(Element.prototype, "getBoundingClientRect").mockImplementation(function (
  this: Element,
  ...args
) {
```

This was fixed by #17354, which ensures the `rest` parameter is not considered "simple", allowing the member chain to stay hugged while function parameters break vertically.

🤖 Generated with [Claude Code](https://claude.ai/code)
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 2, 2026
@Dunqing Dunqing added the 0-merge Merge with Graphite Merge Queue label Feb 2, 2026
@graphite-app graphite-app bot merged commit 7d35a6f into main Feb 2, 2026
19 checks passed
@graphite-app graphite-app bot deleted the test/issue-16177 branch February 2, 2026 02:50
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-test Category - Testing. Code is missing test cases, or a PR is adding them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatter: difference with prettier on chained method call with function as argument

3 participants