Skip to content

fix(css): handle trailing line comments in embedded styles#120

Merged
johnsoncodehk merged 2 commits into
volarjs:masterfrom
TRIS-H:fix/scss-line-comment-formatting
May 9, 2026
Merged

fix(css): handle trailing line comments in embedded styles#120
johnsoncodehk merged 2 commits into
volarjs:masterfrom
TRIS-H:fix/scss-line-comment-formatting

Conversation

@TRIS-H

@TRIS-H TRIS-H commented May 2, 2026

Copy link
Copy Markdown
Contributor

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:

'_ {' + newText + '}'

However, languages such as SCSS and Less support // line comments. When newText ends 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:

// .container {                                           
//   height: 100vh;                                                                                      
// }                                                      

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.

TRIS-H added 2 commits May 2, 2026 13:46
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.
@TRIS-H

TRIS-H commented May 4, 2026

Copy link
Copy Markdown
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.

@TRIS-H TRIS-H changed the title fix(css): preserve trailing newline after line comments fix(css): handle trailing line comments in embedded styles May 4, 2026
@johnsoncodehk

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants