-
-
Notifications
You must be signed in to change notification settings - Fork 105
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: stable format for if/for/while/do/catch/switch with trailing comment #595
base: main
Are you sure you want to change the base?
fix: stable format for if/for/while/do/catch/switch with trailing comment #595
Conversation
01ee02b
to
4a36754
Compare
@@ -192,12 +193,19 @@ export class BlocksAndStatementPrettierVisitor extends BaseCstPrettierPrinter { | |||
} | |||
|
|||
ifStatement(ctx: IfStatementCtx) { | |||
handleCommentsIfStatement(ctx); |
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.
Is this issue only happening on if statements ?
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 like it also happens with for/while/do loops and switch/catch statements. I'll see about fixing those cases as well.
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.
Latest push now handles for/while/do loops and switch/catch statements as well.
4a36754
to
020b09e
Compare
Thank you, @jtkiesel ! It seems that quite a lot of logic is added in order to handle this edge case. I would like to dig a bit more into the issue to see if we can simplify some things before merging this. My objective would be to look at it by the end of the week (and the other pending PR) so we could release a new version of Prettier this weekend :) |
020b09e
to
a356f53
Compare
I looked at it more closely yesterday, but was not able to wrap it up, sorry. I propose to make a new release with the changes that were made since 2.2.0 (#600), and finish this afterwards. |
Sounds good! I'll try to take another look at it this week as well, and see if I can simplify it at all. |
@clementdessoude @jtkiesel Did you find time to look into this? 😇 |
What changed with this PR:
If/for/while/do/catch/switch statements whose parentheses have trailing comments are now formatted stably, and in general are formatted more closely to the way that Prettier JavaScript does.
Example
Input
Output
Relative issues or prs:
Closes #592