Fix SCSS inline comment indentation in deeply nested function calls#19439
Fix SCSS inline comment indentation in deeply nested function calls#19439vasu-sachdeva wants to merge 1 commit into
Conversation
When an inline // comment is the first element of a value-comma_group inside a value-paren_group, the dedent(hardline) used to cancel the indent wrapper did not affect content after the break. By removing both the dedent and the extra indent wrapper for this specific case, arguments after inline comments are now correctly indented at the same level as other sibling arguments. Fixes prettier#19427
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Nice — this does fix the cascading over-indent in the reported nested case. One thing worth checking before it lands, though: returning Minimal repro: .c {
width: someFunction(
// pick the value
$a-really-long-variable-name + $another-really-long-variable-name + $yet-more-length,
2
);
}main: $a-really-long-variable-name + $another-really-long-variable-name +
$yet-more-length,this PR: $a-really-long-variable-name + $another-really-long-variable-name +
$yet-more-length,The continuation line loses its hanging indent. The new branch drops Might be worth dedenting only the comment-affected part (or compensating the comment's |
Description
Fixes #19427.
When a
//inline comment appeared as the first argument inside a nested SCSS function call (avalue-comma_groupinside avalue-paren_group), every subsequent argument gained an extra indent level per nesting level:Cause
In
printCommaSeparatedValueGroup.js, avalue-comma_groupinside avalue-paren_groupis returned asgroup(indent(fill(parts))). When a//inline comment triggers a break, theindentwrapper adds an indent level that persists for all subsequent content in the group. Adedent(hardline)separator was used after the comment to try to cancel it, butdedentonly affects the indentation of the line break itself — it does not unwind the indent for content on following lines. Consequently, each nesting level of function calls compounded the extra indentation.Fix
Two changes in
src/language-css/print/comma-separated-value-group.js:dedent(hardline)withhardline— thededenthad no effect on content after the break.group(fill(parts))(without theindentwrapper) when avalue-comma_groupinside avalue-paren_groupcontains an inline comment. Theindentis unnecessary here because the enclosingvalue-paren_groupalready provides the correct indentation context for its children.Tests
The existing
tests/format/scss/comments/4878.scssfixture covers this scenario with deeply nested function calls and inline comments at every level. The snapshot was updated to reflect the corrected indentation. All 20 SCSS comment tests, 137 SCSS tests, 177 CSS tests, and 43 Less tests pass.Checklist
docs/directory).changelog_unreleased/*X/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.