-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add braces when single-line ifs wrap #7888
Copy link
Copy link
Closed
Labels
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.type:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.Questions and support requests. Please use Stack Overflow for them, not the issue tracker.
Metadata
Metadata
Assignees
Labels
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.type:questionQuestions and support requests. Please use Stack Overflow for them, not the issue tracker.Questions and support requests. Please use Stack Overflow for them, not the issue tracker.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Prettier 1.18.2
Playground link
Input:
Output:
Expected behavior:
I like single-line if statements for early exits and early throws, and I'm really happy that Pretty doesn't try and prevent that.
However, once the line length is reached, the statement goes onto the next line. Although single-line ifs are somewhat controversial, folks seem very much against the statement being on the following line. I've seen this go wrong in the wild, where folks don't realise the braces are missing, and add an extra statement that they expect to be part of the if. Prettier's formatting would correct the indenting of course, but maybe it's better to add the braces?
This has probably been discussed already, but I couldn't find an existing issue.