Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(js_formatter): array printing and grouping in arrows #917

Merged
merged 3 commits into from
Nov 27, 2023

Conversation

faultyserver
Copy link
Contributor

Summary

This fix is largely just pulled straight from astral-sh/ruff#6815, which adds a reset to the PrintMode for a group whenever it has to get remeasured. The linked PR has a more thorough description, but without this, a group that gets measured, realizes it doesn't fit, and then gets remeasured will always assume that it must print as Expanded, because the previous measuring will have failed to fit. This just resets that mode to Flat before attempting to remeasure, ensuring that it will try to fit on a single line first in whatever new context it's being printed in.

The other small change in this PR is allowing JsArrayExpression to start of the same line when used as the single expression body of an arrow function, like:

const bar = (foo) => [
  a,
  b,
];

Previously, the opening bracket would be forced onto a newline, which didn't match the existing behavior for objects, sequences, or block statement bodies.

All of this is starting an attempt to fix prettier/js/arrows/curried, but that's proven to be far more complicated.

Test Plan

The two snapshot changes show the new diff, reducing incompatibilities with Prettier.

@faultyserver faultyserver force-pushed the faulty/curried-arguments branch from 6cf384c to 664cd92 Compare November 27, 2023 20:18
@github-actions github-actions bot added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages labels Nov 27, 2023
@Conaclos Conaclos changed the title fix(formatter,printer): Fix array printing and grouping in arrows fix(js_formatter): Fix array printing and grouping in arrows Nov 27, 2023
@Conaclos Conaclos changed the title fix(js_formatter): Fix array printing and grouping in arrows fix(js_formatter): array printing and grouping in arrows Nov 27, 2023
Copy link
Member

@Conaclos Conaclos left a comment

Choose a reason for hiding this comment

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

Great fix! Feel free to merge :)

@faultyserver faultyserver merged commit c1e3f41 into main Nov 27, 2023
15 checks passed
@faultyserver faultyserver deleted the faulty/curried-arguments branch November 27, 2023 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants