-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Keep comments that are near an if’s condition closer to that condition #807
Copy link
Copy link
Labels
area:commentsIssues with how Prettier prints commentsIssues with how Prettier prints commentshelp wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.
Milestone
Metadata
Metadata
Assignees
Labels
area:commentsIssues with how Prettier prints commentsIssues with how Prettier prints commentshelp wantedWe're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue!lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.
The original Prettier 1.13.6 Playground link
Prettier 1.13.6
Playground link
--parser babylon --trailing-comma falsePrettier 2.1.2
Playground link
Input:
Output:
In the current output, the comments are moved into the block after the
if.As for the desired output, I'm not sure in each of the three cases where the comments should go. Either they shouldn't be moved:
Or they should be moved before the
if, rather than into the block after theif:I think the second case has a higher likelihood of deserving to be moved than the first and third cases.
Related issue
Pull request #672 “Stabilize comments inside of if/then/else before {” made a change related to the last of the three cases, but it simply made the current output stable, rather than changing what that output was.
Similar cases with acceptable output
For completeness, these similar cases are formatted in a way I am okay with, though it’s possible others would want the comment placement to always be preserved:
The original Prettier 1.13.6 Playground link
Prettier 1.13.6
Playground link
--parser babylon --trailing-comma falsePrettier 2.1.2
Playground link
Input:
Output:
Scope of this issue
All of these examples also apply to constructs other than
if, such aswhileandfor, that can have comments next to their conditions.