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.

End-of-line comment inside object literal moved to next line

See original GitHub issue

Prettier 1.19.1 Playground link

--parser babel

Input:

const x = {
  c: { // Very important key.
      a: 123
  }
};

Output:

const x = {
  c: {
    // Very important key.
    a: 123
  }
};

Expected behavior:

The comment should not be moved down.

Also affects TypeScript.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
thorn0commented, Dec 18, 2019

It’s not impossible, just very questionable.

1reaction
bhisoncommented, Mar 30, 2020

As someone who likes inline comments to concisely annotate the flow of my code, I’m still aware of Prettier’s stance as a somwhat opinionated formatter, this is fine and I see that the majority disagree with this as a good style, which I won’t argue against.

So, shelving the feature suggestion, I would argue that it is a bug to move an end of line comment below the line rather than above it. As @glen-84 mentioned, this is a real problem if you’re dealing with an existing codebase and is cause for potentially lots of manual labour in order to not leave your comments as actively misleading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Keep comments that are near an `if`'s condition closer to that ...
In the current output, the comments are moved into the block after ... End-of-line comment inside object literal moved to next line #7155....
Read more >
JavaScript string with new line - but not using \n - Stack Overflow
The reason it is not working is because javascript strings must be terminated before the next newline character (not a \n obviously). The...
Read more >
Options - Prettier
Developers often use whitespace to break up long lines for readability. ... Print spaces between brackets in object literals. Valid options:.
Read more >
Python: Insert New Line into String - STechies
Or you might just want to execute a statement and want the cursor to move to the next line. The newline characters are...
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
disallow await inside of loops. no-compare-neg-zero ... disallow duplicate keys in object literals ... enforce consistent newlines before and after dots.
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