This repository has been archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 660
feat(rome_js_formatter): Heuristic for fill arrays #3126
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Aug 29, 2022
Closed
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
MichaReiser
force-pushed
the
feat/array-expression
branch
from
August 29, 2022 12:15
d87e0b8
to
aa05469
Compare
ematipico
approved these changes
Aug 29, 2022
crates/rome_js_formatter/src/js/expressions/array_expression.rs
Outdated
Show resolved
Hide resolved
"TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", | ||
"TZ", "UA", "UG", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VN", "VU", | ||
"WF", "WS", "XK", "YE", "YT", "ZA", "ZM", "ZW", "ZZ", | ||
"AC", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personal thought: isn't it weird arrays of numbers fill the array, while the array of string literals does not? I suppose prettier has their reasons for doing so
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered keeping that special handling for string arrays as it isn't too hard for us to do it but then decided against it, simply to optimize for compatibility for now. I think this is something that we can consider adding again in the future.
Align Rome's heuristic with Prettier's of when use `fill` vs a group. There's one difference that I intend not to fix because I believe it is a bug in Prettier. Rome's printer automatically inserts a `group` around `fill` elements so that `fits` returns `false` if it encounters any hard line break. Prettier doesn't do so and any hard line break will result in `fits` return true. This difference is meaningful for ```javascript [ // comment2 -380014, -253951682 ] ``` where the first element contains hard line breaks because of the `//comment`. Prettier assumes that the content fits and, thus, prints `-253...` on the same line. Rome does not and istead, prints a line break after `-3800..`. I can demonstrate that this leads to issues where Prettier incorrectly exceeds the line widths: [example](https://prettier.io/playground/#N4Igxg9gdgLgprEAuEBtAOlA9FgBJAWwIRgCZMBaAZgA4AGOgRgBYq32POvufe-+ANJVIBWKgE4RjAGw1yUXLgC6mEAJAQADjACW0AM7JQAQwBOpiAHcACmYSGUxgDaXjAT0PqARqeNgA1nAwAMrGxAAyOlBwyABmzvpw3r4BQcGaflEA5sgwpgCuSSBwBF5wACblFeHGUFn5xllwAGIQpgTGMLp1yCDG+TAQaiAAFjAETgDqIzrw+hlgcMH2szoAbrNuvWD6niBRiaYw1r5ZHXEJRQBW+gAewdlOcACK+RDwF06J6hmmh70wNyaOD6MCmHTaYaacGwSY6cowEbIeg-CyJSa+TS9aEguCmNYxdQARze8BOWgcIBxhwJw1McBJOnpJ0a5yQ8S+RUSBB0uQKXMeL1JMXZl3UMGMXjhCKRSFI4t8Oic2QAwhAiMZes4nMN8okACqShwc74gNaFACSUCqsGCYIhMAAgtbgoCnp9EgBfT1AA) ```javascript [ // comment2 -380014333333333333333333333333333333333333333333333333333333333333333333, -253951682 ] ```
MichaReiser
force-pushed
the
feat/array-expression
branch
from
August 29, 2022 15:15
aa05469
to
d681b13
Compare
Co-authored-by: Emanuele Stoppa <[email protected]>
MichaReiser
changed the title
feat(rome_js_formatter): Heuristic for flat arrays
feat(rome_js_formatter): Heuristic for fill arrays
Aug 29, 2022
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
feat(rome_js_formatter): Heuristic for flat arrays
Align Rome's heuristic with Prettier's of when use
fill
vs a group.There's one difference that I intend not to fix because I believe it is a bug in Prettier.
Rome's printer automatically inserts a
group
aroundfill
elements so thatfits
returnsfalse
if it encounters any hard line break.Prettier doesn't do so and any hard line break will result in
fits
return true.This difference is meaningful for
where the first element contains hard line breaks because of the
//comment
. Prettier assumes that the content fits and, thus, prints-253...
on the same line. Rome does not and istead, prints a line break after-3800..
.I can demonstrate that this leads to issues where Prettier incorrectly exceeds the line width: example
Tests
Average compatibility: 83.70 -> 84.00
Compatible lines: 80.79 -> 81.75