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): Function parameter & return type grouping #2990
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
MichaReiser
changed the base branch from
main
to
refactor/extract-any-function-formatting
August 2, 2022 13:24
MichaReiser
force-pushed
the
refactor/extract-any-function-formatting
branch
from
August 2, 2022 13:27
a47eadd
to
41be225
Compare
MichaReiser
force-pushed
the
feature/function-formatting
branch
from
August 2, 2022 13:27
d7bff1c
to
2869357
Compare
Deploying with Cloudflare Pages
|
Parser conformance results on ubuntu-latestjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
MichaReiser
force-pushed
the
feature/function-formatting
branch
from
August 2, 2022 15:33
2869357
to
961f53c
Compare
MichaReiser
changed the title
refactor(rome_js_formatter): Extract JsAnyFunction formatter into `…
feat(rome_js_formatter): Format function parameters
Aug 2, 2022
Base automatically changed from
refactor/extract-any-function-formatting
to
main
August 3, 2022 06:55
MichaReiser
changed the title
feat(rome_js_formatter): Format function parameters
feat(rome_js_formatter): Function parameter & return type grouping
Aug 3, 2022
MichaReiser
force-pushed
the
feature/function-formatting
branch
from
August 3, 2022 06:58
961f53c
to
dae7678
Compare
Implement the same heuristic as Prettier for grouping parameters with the return type annotation. This ensures that a return type will break FIRST before the parameters and the parameters only break if they don't fit on the same line together with the expanded return type annotation. This PR further unifies the formatting of methods and functions to achieve better code reuse.
MichaReiser
force-pushed
the
feature/function-formatting
branch
from
August 3, 2022 07:26
dae7678
to
777f596
Compare
!bench_formatter |
Formatter Benchmark Results
|
ematipico
approved these changes
Aug 3, 2022
crates/rome_js_formatter/src/js/declarations/function_declaration.rs
Outdated
Show resolved
Hide resolved
IWANABETHATGUY
pushed a commit
to IWANABETHATGUY/tools
that referenced
this pull request
Aug 22, 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.
Summary
This PR refines the formatting of function parameters and return type annotations by adopting Prettier's behaviour to first break the return type annotation in some situations before breaking the parentheses (see
shouldGroupCallArguments
).Implementing this change required to extract the shared method formatting logic into a
FormatMethodMember
helper struct.Test Plan
Verified that e.g. object types now break before the parentheses.
File Based Average Prettier Similarity: 78.03% -> 78.10%
Line Based Average Prettier Similarity: 73.10% -> 73.19%