End-of-line comment inside object literal moved to next line
See original GitHub issuePrettier 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:
- Created 4 years ago
- Reactions:1
- Comments:9 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s not impossible, just very questionable.
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.