Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_js_formatter): type alias as assignment like #2787

Merged
merged 3 commits into from
Jun 28, 2022

Conversation

ematipico
Copy link
Contributor

@ematipico ematipico commented Jun 27, 2022

Summary

This adds TsTypeAliasDeclaration to the list of assignment like expressions. Part of #2424

It also adds some additional condition, around this new variant, for the BreakLeftHandSide.

I had to change a bit how should_break_after_operator is used. The function accepts a JsAnyExpression, but with TS we have a right hand side that is not an expression. So I just created a thin wrapper to call has_new_line_before_comment for every right node.

At the moment there's a small regression around the indentation of type unions, that's because at the moment these unions are not formatted as a binary like expression.

I will make a separate PR to include them in the JsAnyBinaryLikeExpression union.

I also took the liberty to merge the formatting logic of JsObjectExpression and TsObjectType into a new union type. This will make sure that we don't diverge too much, and if we need to fix some logic, it's applied to both nodes.

Test Plan

Current test suite, and checked that the new snapshots are correct.

PR
File Based Average Prettier Similarity: 76.38%
Line Based Average Prettier Similarity: 71.92%

main
File Based Average Prettier Similarity: 76.34%
Line Based Average Prettier Similarity: 71.91%

@ematipico ematipico temporarily deployed to aws June 27, 2022 12:37 Inactive
@github-actions
Copy link

github-actions bot commented Jun 27, 2022

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jun 27, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0028a5b
Status:⚡️  Build in progress...

View logs

@ematipico ematipico force-pushed the feature/type-alias-declaration branch from c9035cc to a606eee Compare June 27, 2022 14:36
@ematipico ematipico temporarily deployed to aws June 27, 2022 14:36 Inactive
@ematipico ematipico temporarily deployed to aws June 27, 2022 14:49 Inactive
@ematipico ematipico marked this pull request as ready for review June 27, 2022 14:51
@ematipico ematipico requested review from leops and yassere June 27, 2022 14:52
semicolon_token,
} = node.as_fields();

let type_token = node.type_token()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@ematipico ematipico Jun 27, 2022

Choose a reason for hiding this comment

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

I maintained the same logic we have introduced for variable declarations. There, the kind (var/let/const) doesn't belong to left. Hence, here type_token doesn't belong to left.

@ematipico ematipico temporarily deployed to aws June 28, 2022 08:30 Inactive
@ematipico ematipico merged commit f378e33 into main Jun 28, 2022
@ematipico ematipico deleted the feature/type-alias-declaration branch June 28, 2022 08:31
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants