question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Comment after braces

See original GitHub issue

Prettier 2.7.1 Playground link

--parser babel
--print-width 2000
--tab-width 4

Input:

const value = true;
if (value) { /** Some comment about the if option that is not keeped on this line */
  
} /** This comment is keeped on this line */ else { /** Some comment about the else option that is not keeped on this line */
  console.log('hello'); /** This comment is keeped on this line */
}

Output:

const value = true;
if (value) {
    /** Some comment about the if option that is not keeped on this line */
} /** This comment is keeped on this line */ else {
    /** Some comment about the else option that is not keeped on this line */
    console.log("hello"); /** This comment is keeped on this line */
}

Expected behavior:

const value = true;
if (value) { /** Some comment about the if option that is not keeped on this line */
} /** This comment is keeped on this line */ else { /** Some comment about the else option that is not keeped on this line */
    console.log("hello"); /** This comment is keeped on this line */
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kachkaevcommented, Jul 8, 2022

This works too, does not it? Importantly, there is more space for a comment, especially in the case of a long if:

if (veryLongConditionThatNeedsALotOfSpaceAndWouldThusPushTheCommentRight) {
    // This comment tells what is done below inside the if
    
    // A comment here would explain the below console.log('hello') (not the if block)
    console.log('hello');
} else {
    // This comment tells what is done below inside the else

    // A comment here would explain the below console.log('hello2') (not the else block)
    console.log('hello2');
}
0reactions
MaxenceEpitechcommented, Jul 8, 2022

The objective of keeping a comment after { is to describe what’s done inside the else part of an ‘if / else’.

} else { // This comment tells what is done bellow inside the else
    // A comment here would explain the bellow console.log('hello2') (not the else block)
    console.log('hello2');
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Testimonials - Orthodontist Newport Beach, Laguna Beach CA
We find it very rewarding to receive nice notes and comments from patients who were so positively affected by the treatment they received...
Read more >
Curly Bracket automatic comments line – ReSharper Support
HiI'm just starting using ReSharper and need some help on some settings.If I write some code in C# and I want to write...
Read more >
Comments in if statement without curly braces - Stack Overflow
If there is no curly braces to group the code, the statement immediately after the if statement gets executed. If there is comments...
Read more >
algorithmic - Remove braces around the comment - TeX
You have two possibilitys, depending on the way you want to write your comments in the algorithmn. You can add
Read more >
Why can I not place unmatched braces in Tcl comments
Tcl recognized # as a comment and ignored ignored the rest of that line, including the trailing open-brace. After successfully evaluating foreach, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found