-
Notifications
You must be signed in to change notification settings - Fork 666
fix(rome_js_formatter): custom formatting for test calls #2769
Conversation
Deploying with Cloudflare Pages
|
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 think it would be good to split out the WillBreakBuffer
into its own PR as the other logic in this PR isn't using it.
4e6c0a3
to
c96d02f
Compare
Done, that's been removed |
!bench_formatter |
crates/rome_js_formatter/src/utils/member_chain/flatten_item.rs
Outdated
Show resolved
Hide resolved
Formatter Benchmark Results
|
I pushed a small refactor and it uses only references, and a better way to do checks on the arguments for the custom formatting (hooks and tests). It should improve slightly the performances. |
063e4d3
to
8a0c3af
Compare
8a0c3af
to
568aca5
Compare
!bench_formatter |
Formatter Benchmark Results
|
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.
Looks good. I've one comment around testing the match_test_call
where I believe it should be possible to improve the performance by avoiding iterating O(patterns) times overall member names for any non-test method.
c65a5f9
to
b98dc86
Compare
4380eaa
to
6f00389
Compare
6f00389
to
2f0b4df
Compare
2f0b4df
to
5654902
Compare
Summary
This PR implements gets us closer to how call arguments are formatted.
Prettier has a particular formatting just for call expressions that are used by testing frameworks, such as
This PR brings their algorithm into our code base and it uses it to do an early formatting if the criteria are met. The function explains what the criteria are.
While doing so, I added an option to
JsCallArguments
to accept an option calledcallee
, which is essentially thecallee
that belong to its parent. The reason why I added this option is because this check should not be used for call expressions of dynamic import. So instead of calling the parent, checking its type and then extracting thecallee
, I decided to pass a reference of thecallee
from the parent.It addresses a comment from closed PR, by limiting the usage of a custom buffer to a single call, instead of dragging the whole buffer across functions;
Test Plan
cargo test
and made sure that the prettier testing suite format as prettier'sPR
File Based Average Prettier Similarity: 76.09%
Line Based Average Prettier Similarity: 71.53%
main
File Based Average Prettier Similarity: 76.00%
Line Based Average Prettier Similarity: 70.84%