trailing comma aftscss if comment on same line as last item
See original GitHub issuePrettier 1.19.1 Playground link
--parser scss
--trailing-comma all
Input:
$mediaBreakpointsUpperLimit: (
xs: map-get($mediaBreakpoints, xs) - 1px,
sm: map-get($mediaBreakpoints, md) - 1px,
md: map-get($mediaBreakpoints, lg) - 1px,
lg: map-get($mediaBreakpoints, xl) - 1px,
xl: 9007199254740991 // Number.MAX_SAFE_INTEGER
);
Output:
$mediaBreakpointsUpperLimit: (
xs: map-get($mediaBreakpoints, xs) - 1px,
sm: map-get($mediaBreakpoints, md) - 1px,
md: map-get($mediaBreakpoints, lg) - 1px,
lg: map-get($mediaBreakpoints, xl) - 1px,
xl: 9007199254740991 // Number.MAX_SAFE_INTEGER,
);
Expected behavior: The trailing comma should be added before the comment, not after.
Related issues found but already closed: #5855
Edit: Additional bug, which is related: Try moving the comment before the last entry. The last entry will become part of the last comment:
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >Setting trailingComma to "all" or "es5" breaks SCSS comment ...
It doesn't stabilize, preventing me from formatting this file properly. EDIT: I've just noticed the same happens with --traling-comma=es5 .
Read more >Trailing comma after last line in object - Stack Overflow
I noticed that when using format on save, Prettier adds trailing commas on the last line of an object every time.
Read more >Best practices for using trailing commas in JavaScript
A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of...
Read more >Code Syntax Style: Trailing Commas - JetBrains Rider
You can also press Ctrl+D to duplicate the last line. Your version control diffs are cleaner when you add a new item in...
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
I experimented changing stuff here and there for this issue, and I am stuck in solving the problem. Below are the findings I have found in the process.
I’ve tested for this particular code:
And I believe the issue is that all fields are in a single group of
value-comma_group
instead that the comments should be separate nodes.I have tried several stuff like
isLastItemComment
but I realized this wouldn’t work because it wouldn’t add the trailing comma at all.
lineSuffix
for inline comments forvalue-comment
case. But I am in doubt it would be safe to buffer every comment.It did fix a part of the issue that now it inserts trailing comma before the comment (but with a leading space before comma which is an issue too). For example,
turns to
And then there’s another problem which is preexisting right now regardless of my changes. The comment on the line gets a break.
turns to
At this point, I am confused whether the issue is in the parser or the printer. Hope my findings will be useful information for fixing this issue. If someone guides me in this, I will submit a PR.
Thank you.
@aeruhxi Thank you, go ahead!