Skip to content

fix: keep an arrow function's call or template literal body on the same line as the arrow when it hugs its last argument or is on multiple lines - #861

Merged
dsherret merged 1 commit into
mainfrom
fix-arrow-body-same-line
Nov 3, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix-arrow-body-same-line

Conversation

@dsherret

@dsherret dsherret commented Nov 3, 2026

Copy link
Copy Markdown
Member

An arrow function's expression body was always moved to the next line when it was on multiple lines, even when only a hugged last argument or a template literal made it multi-line:

// before
colors.map(color =>
  darken({
    color,
    opacity: 1,
  })
);
const render = () =>
  html`
    <div>${addKid}</div>
`;

// after
colors.map(color => darken({
  color,
  opacity: 1,
}));
const render = () => html`
    <div>${addKid}</div>
`;
  • Calls and new expressions stay on the same line as the arrow when they're written that way with their last argument starting on that line and continuing on the next ones (ex. a => b({, a => foo(x, () => {, or a => new Foo([). Those last arguments keep their line breaks, so this is decided from how the code is written, like the other explicit newlines, and is stable. The body still moves to the next line when the text before the last argument doesn't fit, when it's written on one line (the next line fits it on one line when it can), or when it's already on the next line.
  • Template literals and tagged template literals on multiple lines stay on the same line as the arrow, because the template's text isn't indented when it moves to the next line. Before, only template literals starting with a new line did. With an embedded formatter (ex. html in the external formatter spec), the template is now indented from the arrow's line.

This is a fix rather than an option like #528, which kept every call and tagged template on the arrow's line.

In the regression corpus from #13 (about 19,000 files with six configurations), this changes 16 files, all tagged or multi-line templates that stay with the arrow (ex. (entry) =>\n html\`` becomes (entry) => html``). The calls don't change there because the corpus has already been formatted with them on the next line.

Closes #107

…me line as the arrow when it hugs its last argument or is on multiple lines
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.

Multi-line arrow-function expression body should not add line break after arrow in certain circumstances

1 participant