Skip to content

fix(formatter): sequence expression in arrow function body collapses onto one line#21183

Merged
leaysgur merged 1 commit intooxc-project:mainfrom
jsmecham:fix/issue-21171
May 1, 2026
Merged

fix(formatter): sequence expression in arrow function body collapses onto one line#21183
leaysgur merged 1 commit intooxc-project:mainfrom
jsmecham:fix/issue-21171

Conversation

@jsmecham
Copy link
Copy Markdown
Contributor

@jsmecham jsmecham commented Apr 8, 2026

Summary

Fixes #21171

When a sequence expression (comma operator) is used as the body of a parenthesized arrow function, the formatter incorrectly collapsed all items onto a single line even when the content was too wide to fit at the arrow function's column.

Input

const result = items.reduce(
  (acc, item) => (
    isLong(item) ? (acc[item.id] = { key: item.id, value: item.value }) : undefined,
    acc
  ),
  {}
);

Before (incorrect)

const result = items.reduce(
  (acc, item) => (
    isLong(item) ? (acc[item.id] = { key: item.id, value: item.value }) : undefined, acc
  ),
  {},
);

After (matches Prettier)

const result = items.reduce(
  (acc, item) => (
    isLong(item)
      ? (acc[item.id] = { key: item.id, value: item.value })
      : undefined,
    acc
  ),
  {},
);

Short sequences that fit on one line are unaffected:

// (acc[item.id] = item.value), acc — fits at the arrow column → stays on one line
const result = items.reduce(
  (acc, item) => ((acc[item.id] = item.value), acc),
  {},
);

Root cause

The formatter wrapped sequence expression items in their own group and the arrow body handler wrapped that group in soft_block_indent. When the arrow body's (...) group broke, soft_block_indent indented the sequence group to column 4 (inside the parens). At that indented position, the items fit within the print width — so the sequence group never broke and items stayed on one line.

Prettier avoids this by placing the ( and ) outside the sequence group, so the group measures fitness starting at the arrow-function column (before (). That higher column makes long sequences exceed the print width and break correctly.

Fix

Two coordinated changes:

  1. sequence_expression.rs — when the parent is an arrow function body, wrap items in soft_block_indent inside the group. This gives the group the same break/indent semantics as Prettier's group(ifBreak([indent([softline, parts]), softline], parts)).

  2. arrow_function_expression.rs — remove the outer soft_block_indent from the sequence body handler (both Single and Chain layouts). The sequence group's own soft_block_indent is now the sole source of indentation, and the group's break decision is made at the column of ( — the correct reference point.

Prettier conformance: no regressions (745/753 JS, 590/601 TS — unchanged).

AI Disclosure

This PR was co-authored with Claude Code (AI assistant), as noted in the commit. The fix was reviewed, tested against the full Prettier conformance suite, and verified to produce no regressions.

@github-actions github-actions Bot added A-formatter Area - Formatter C-bug Category - Bug labels Apr 8, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 8, 2026

Merging this PR will not alter performance

✅ 44 untouched benchmarks
⏩ 7 skipped benchmarks1


Comparing jsmecham:fix/issue-21171 (223e598) with main (4380812)

Open in CodSpeed

Footnotes

  1. 7 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.

@leaysgur
Copy link
Copy Markdown
Member

leaysgur commented Apr 9, 2026

/oxfmt-ecosys

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Oxfmt Ecosystem CI

suite oxfmt@latest refs/pull/21183/head branch
eggjs/egg
fuma-nama/fumadocs
formatjs/formatjs
AmanVarshney01/create-better-t-stack
vuejs/core
cnpm/cnpmcore
monkeytypegame/monkeytype
actualbudget/actual
vercel/turborepo
fastify/fastify-vite
vuejs/pinia
huggingface/huggingface.js
lichess-org/lila
rolldown/rolldown
tale/headplane
Comfy-Org/ComfyUI_frontend
mastodon/mastodon
getsentry/sentry-javascript
aidenybai/react-grab
dyad-sh/dyad
openclaw/openclaw
npmx-dev/npmx.dev
cloudflare/agents

Copy link
Copy Markdown
Member

@leaysgur leaysgur left a comment

Choose a reason for hiding this comment

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

It looks good in principle.

To proceed with the merge, I would like to request the following:

  • Refine the comments
    • They feel redundant and seem to have some repetition
  • Add test patterns
    • Please add a few variations to the same test file to ensure there are no regressions?

jsmecham added a commit to jsmecham/oxc that referenced this pull request Apr 28, 2026
…im comments

Address review feedback on oxc-project#21183:
- Trim redundant comments in sequence_expression.rs and arrow_function_expression.rs
  to a single concise note pointing to the canonical site.
- Expand the issue-21171.js fixture with more variations: three-item short and long
  sequences, sequences inside arrow chains, plus non-arrow contexts (top-level
  expression statements and for-update clauses) to guard against regressions in
  unaffected paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jsmecham added a commit to jsmecham/oxc that referenced this pull request Apr 28, 2026
…im comments

Address review feedback on oxc-project#21183:
- Trim redundant comments in sequence_expression.rs and arrow_function_expression.rs
  to a single concise note pointing to the canonical site.
- Expand the issue-21171.js fixture with more variations: three-item short and long
  sequences, sequences inside arrow chains, plus non-arrow contexts (top-level
  expression statements and for-update clauses) to guard against regressions in
  unaffected paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
jsmecham added a commit to jsmecham/oxc that referenced this pull request Apr 28, 2026
…im comments

Address review feedback on oxc-project#21183:
- Trim redundant comments in sequence_expression.rs and arrow_function_expression.rs
  to a single concise note pointing to the canonical site.
- Expand the issue-21171.js fixture with more variations: three-item short and long
  sequences, sequences inside arrow chains, plus non-arrow contexts (top-level
  expression statements and for-update clauses) to guard against regressions in
  unaffected paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…to one line

When a sequence expression is the body of a parenthesized arrow function,
the break decision was made at the indented column inside the `(...)` rather
than at the column of `(`. This caused items to collapse onto one line even
when they were too long to fit, since the indented context gave them more
space than the arrow function signature context.

Fix by having the sequence expression use `soft_block_indent` inside its own
group when in an arrow body context, and removing the outer `soft_block_indent`
from the arrow function body handler. This ensures the group's break threshold
is evaluated at the correct column — matching Prettier's behavior.

Fixes oxc-project#21171

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jsmecham
Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed both points in the latest push:

  • Comments refined. Trimmed the verbose paragraph in sequence_expression.rs down to a single concise note about why the arrow-body branch owns the soft_block_indent, and removed the redundant pointer comments from arrow_function_expression.rs — the canonical explanation now lives in one place.
  • Test variations added. Expanded issue-21171.js with additional cases:
    • three-item short and long sequences,
    • sequences inside arrow chains ((a) => (b) => (c) => (..., ...), both short and long),
    • non-arrow regression guards: a top-level sequence as an expression statement and a sequence in a for-loop update clause.

Snapshot regenerated and the full oxc_formatter suite passes. Ready for another look when you have a moment.

@leaysgur leaysgur merged commit ef0db6b into oxc-project:main May 1, 2026
34 checks passed
camc314 added a commit that referenced this pull request May 5, 2026
# Oxlint
### 🚀 Features

- 1d40d60 linter: Implement SARIF formatter (#22067) (camchenry)
- c0982fe linter/eslint: Implement no-restricted-properties rule
(#22080) (AJ Bienz)
- 5699d53 linter: Add help text to `agent` formatter (#22064)
(camchenry)
- fe7194d oxlint: Add agent output mode (#21955) (Jovi De Croock)
- fb2f052 linter: Suggest moving shared branch code (#22022) (camc314)
- 5868335 linter/no-else-return: Improve nested if diagnostic spans
(#22009) (camc314)
- 8b4829b linter: Split `no-negated-condition` rule to unicorn & eslint
(#21998) (Sysix)
- fea301a linter: Split jest/prefer-to-be into separate vitest rule
(#21977) (camchenry)
- 44aa0d6 linter: Split jest/prefer-strict-equal into separate vitest
rule (#21976) (camchenry)
- 2262b27 linter: Split jest/prefer-spy-on into separate vitest rule
(#21975) (camchenry)
- fef9143 linter: Split jest/prefer-mock-return-shorthand into separate
vitest rule (#21974) (camchenry)
- 2bda504 linter: Split jest/prefer-mock-promise-shorthand into separate
vitest rule (#21973) (camchenry)
- 6ef6c7d linter: Split jest/prefer-lowercase into separate vitest rule
(#21972) (camchenry)
- f4d2498 linter: Split jest/prefer-hooks-on-top into separate vitest
rule (#21971) (camchenry)
- fb8e366 linter: Split jest/prefer-hooks-in-order into separate vitest
rule (#21970) (camchenry)
- adcd85c linter: Split jest/prefer-expect-resolves into separate vitest
rule (#21969) (camchenry)
- 8ddc7ec linter: Split jest/prefer-equality-matcher into separate
vitest rule (#21968) (camchenry)
- 46bb1f3 linter: Split jest/prefer-each into separate vitest rule
(#21967) (camchenry)
- bdbff66 linter: Implement interactive-supports-focus (#21767)
(mehm8128)
- 733b094 linter: Split `prefer-to-have-been-called-times` rule (#21898)
(Said Atrahouch)
- 8804425 linter/eslint: Implement `logical-assignment-operators` rule
(#21900) (Mikhail Baev)
- 296d147 linter: Split jest/prefer-comparison-matcher into separate
vitest rule (#21929) (camchenry)
- 38146b6 linter: Split jest/prefer-called-with into separate vitest
rule (#21927) (camchenry)
- 6f86175 linter/vue: Implement return-in-computed-property rule
(#21909) (bab)
- dc2d0e4 linter: Split jest/no-unneeded-async-expect-function into
separate vitest rule (#21878) (camchenry)
- a03fc37 linter: Split jest/no-test-return-statement into separate
vitest rule (#21877) (camchenry)
- f11313e linter: Split jest/no-test-prefixes into separate vitest rule
(#21876) (camchenry)
- 4380812 linter: Split `prefer-to-have-length` rule (#21893) (Said
Atrahouch)
- 511bcc1 linter: Split jest `require-hook` rule (#21889) (Said
Atrahouch)
- 64a8180 linter: Split `jest/prefer-snapshot-hint` into a Jest rule and
a Vitest rule. (#21881) (connorshea)
- ae7924a linter/vue: Implement no-deprecated-model-definition rule
(#21886) (bab)
- 0dfe8b3 linter: Split `jest/require-to-throw-message` into Jest and
Vitest rules. (#21879) (connorshea)
- 51229ff linter: Split jest `valid-describe-callback` rule (#21882)
(Said Atrahouch)
- 2d102fd linter: Split `no-standalone-expect` rule into jest and vitest
(#21862) (Sysix)
- ee46a29 linter: Split `no-restricted-matchers` rule into jest and
vitest (#21860) (Sysix)
- 1f29459 linter: Split `no-restricted-jest-methods` rule into jest and
vitest (#21859) (Sysix)
- e7f8d55 linter: Remove eslint prefixes from plugin names in
diagnostics (#21806) (Connor Shea)
- 89fff8b linter: Split valid-expect-in-promise/jest rule into jest and
vitest rules (#21854) (Said Atrahouch)

### 🐛 Bug Fixes

- 0b48848 linter/prefer-array-some: Make find rewrite a suggestion
(#22103) (camc314)
- d24027e linter/prefer-array-some: Preserve find comparison fixes
(#22094) (camc314)
- af2d26c linter/astro: Handle js `---` after frontmatter in .astro
files (#22091) (Andrew Powell)
- 78d4ff0 linter/jsdoc/require-returns: Only look at the nearest jsdoc
block (#22077) (camc314)
- fa88857 linter/no-map-spread: Use default codegen options for fix
(#22074) (camc314)
- 2047a35 linter: Treat adjacent fixes as overlapping (#22071) (camc314)
- 75fc551 linter: Handle no-extra-boolean-cast edge cases (#22031)
(camc314)
- e9d5284 linter/sort-keys: Don't autofix if comment could be misplaced
(#22052) (Amund Eggen Svandal)
- d7230b0 linter/no-constant-condition: Handle generator yields (#22046)
(camc314)
- e8dbc56 linter/array-type: Enable edge case tests (#22047) (camc314)
- d57b51f linter/no-constant-condition: Propagate config errors (#22045)
(camc314)
- bdb6d95 linter/typescript: Remove duplicate rule tests (#22044)
(camc314)
- 0beaffc linter: Print resolved extended config (#22040) (camc314)
- 192ad0e linter/react/only-export-components: Align rule with upstream
cases (#22039) (camc314)
- cdf4c53 linter/only-export-components: Support tanstack router
(#21937) (camc314)
- 893e18f linter: Stop gitignore lookup at repo boundary (#22033)
(camc314)
- 7100712 linter/constructor-super: Clarify duplicate super diagnostics
(#22035) (camc314)
- fce5b7c linter/constructor-super: Improve invalid `super` calls
diagnostic (#22032) (camc314)
- b3de93c linter/rules-of-hooks: Clarify conditional diagnostics
(#22030) (camc314)
- 4f9f629 linter/rules-of-hooks: Clarify loop diagnostics (#22029)
(camc314)
- e6f0978 linter/rules-of-hooks: Clarify async component diagnostics
(#22024) (camc314)
- e262f51 linter/rules-of-hooks: Improve diagnostic for hook inside
class component (#22023) (camc314)
- 7b71b0d linter/no-restricted-imports: Report once per import
declaration (#22021) (camc314)
- 3d5ae3d linter/vitest/require-mock-type-parameters: Handle chained
typed mocks (#22019) (camc314)
- 959a2db linter/reporter/github: Omit empty `file` annotations (#22017)
(camc314)
- 16003a1 linter/unicorn: Remove duplicate rule tests (#22018) (camc314)
- 86b7547 linter/no-unreachable: Suppress nested unreachable diagnostics
(#22011) (camc314)
- 1d92ae8 linter/oxc: Remove duplicate rule tests (#22013) (camc314)
- f270246 linter/branches-sharing-code: Ignore empty statements (#22012)
(camc314)
- f1c25dd linter: Stabilize debug diagnostic comparison (#22010)
(camc314)
- b6bc421 linter: Skip linting astro scripts with non JS script types
(#21954) (camc314)
- a77547d linter: Support plugin-qualified disable directives (#21999)
(camc314)
- 079cfdd linter: Match disable directive rule names exactly, not by
substring (#21906) (Christian Vuerings)
- 11a4e67 linter: Comptibles rules need to be disabled in jest and
vitest at same time (#21982) (Said Atrahouch)
- ce62f16 linter: `jsx-a11y/prefer-tag-over-role` detect more roles
(#21933) (bab)
- 024c390 linter/jest/vitest: Padding around after all blocks not
working as expected (#21952) (kapobajza)
- 05a8f75 linter/jest/no-standalone-expect: False positive with expect
in an `ObjectProperty` (#21948) (Said Atrahouch)
- 6a37c98 linter/no-unused-vars: Report unused re-exported imports
(#21938) (camc314)
- 2d5fc16 linter: `jsx-a11y/media-has-caption` report only once for
self-closing tags (#21934) (bab)
- 5adca29 linter: `jsx-a11y/no-autofocus` ignore `false` attribute
values (#21918) (Sysix)
- 2e5c18e linter/max-nested-describe: Reset nested describe depth
(#21891) (camc314)

### ⚡ Performance

- a77f0f7 linter/require-returns: Avoid jsdoc tag vec allocation
(#22081) (camc314)
- d9a1b32 linter/plugins: Avoid array lookups where possible in CFG
visitor (#21940) (overlookmotel)
- fefefd8 linter/plugins: Replace addition with bitwise OR in CFG
visitor (#21939) (overlookmotel)

### 📚 Documentation

- d58f594 oxlint/lsp: Auto generate docs for LSP options (#22082)
(Sysix)
- 9adc3b3 linter/no-misused-new: Clarify construct signatures behaviour
(#22016) (camc314)
- 1caf5ad linter/plugins: Reformat comments (#21873) (overlookmotel)
# Oxfmt
### 🐛 Bug Fixes

- ef0db6b formatter: Sequence expression in arrow function body
collapses onto one line (#21183) (Justin Mecham)
- 5d5d808 formatter: Preserve blank line after directive with trailing
comment (#21153) (Justin Mecham)

### ⚡ Performance

- 2fd907d formatter: Sort imports during IR construction (#22065)
(overlookmotel)

---------

Co-authored-by: Boshen <1430279+Boshen@users.noreply.github.com>
Co-authored-by: Cameron Clark <cameron.clark@hey.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatter: sequence expression in arrow function body collapses onto one line (differs from Prettier)

2 participants