fix(css): handle trailing line comments in embedded styles#120
Merged
johnsoncodehk merged 2 commits intoMay 9, 2026
Conversation
Keep synthetic wrapper braces separate from trailing line comments when formatting embedded styles with initial indentation, without adding an extra blank line when the text already ends with a newline.
Contributor
Author
|
Pushed a follow-up commit to cover the initialIndentLevel formatting path. The synthetic wrapper suffix is now conditional, so trailing line comments do not swallow the closing brace while existing trailing newlines do not create extra blank lines. |
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes an edge case in embedded CSS formatting when the formatted content ends with a line comment.
ensureNewLines()verifies whether formatted embedded content should start or end with a newline by wrapping it in a synthetic CSS rule:However, languages such as SCSS and Less support
//line comments. WhennewTextends with a line comment, the appended closing brace becomes part of that comment instead of closing the synthetic rule:// }As a result, the verification document no longer represents the intended wrapper structure, and the trailing newline check can produce an incorrect result.
This change places the synthetic closing brace on the next line and trims the wrapper using explicit prefix/suffix lengths.
Example
For embedded SCSS or Less content like this:
the formatter should preserve the trailing newline when required by the embedding host document.
Without this fix, downstream consumers can lose that newline and merge following host content onto the final comment line. One observable downstream case is Vue SFC formatting, where the closing
</style>tag can be moved onto the same line as the final SCSS or Less comment.