Skip to content

Commit

Permalink
Do not add trailing comma for grouped scss comments (#15217)
Browse files Browse the repository at this point in the history
* Do not add trailing comma for grouped scss comments

* add changelog
  • Loading branch information
auvred committed Aug 11, 2023
1 parent 06a8e37 commit 8a3e73c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
25 changes: 25 additions & 0 deletions changelog_unreleased/scss/15217.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#### Do not add trailing comma for grouped scss comments (#15217 by @auvred)

<!-- prettier-ignore -->
```scss
/* Input */
$foo: (
'property': (),
// comment 1
// comment 2
)

/* Prettier stable */
$foo: (
"property": (),
// comment 1
// comment 2,
);

/* Prettier main */
$foo: (
"property": (),
// comment 1
// comment 2
);
```
4 changes: 4 additions & 0 deletions src/language-css/print/parenthesized-value-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ function printTrailingComma(path, options) {

if (
path.node.type !== "value-comment" &&
!(
path.node.type === "value-comma_group" &&
path.node.groups.every((group) => group.type === "value-comment")
) &&
shouldPrintTrailingComma(options) &&
path.callParent(() => isSCSSMapItemNode(path, options))
) {
Expand Down
38 changes: 38 additions & 0 deletions tests/format/scss/scss/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,17 @@ label {
div {
margin: - pow(2, 2) * 100px;
}
$foo: (
'property1': (),
// comment 1
// comment 2
'property2': 1,
/** comment 1 */
/* comment 2 */
);
=====================================output=====================================
@media #{$g-breakpoint-tiny} {
}
Expand Down Expand Up @@ -2631,6 +2642,14 @@ div {
margin: - pow(2, 2) * 100px;
}
$foo: (
"property1": (),
// comment 1
// comment 2
"property2": 1,
/** comment 1 */ /* comment 2 */
);
================================================================================
`;

Expand Down Expand Up @@ -3732,6 +3751,17 @@ label {
div {
margin: - pow(2, 2) * 100px;
}
$foo: (
'property1': (),
// comment 1
// comment 2
'property2': 1,
/** comment 1 */
/* comment 2 */
);
=====================================output=====================================
@media #{$g-breakpoint-tiny} {
}
Expand Down Expand Up @@ -4805,6 +4835,14 @@ div {
margin: - pow(2, 2) * 100px;
}
$foo: (
"property1": (),
// comment 1
// comment 2
"property2": 1,
/** comment 1 */ /* comment 2 */
);
================================================================================
`;

Expand Down
12 changes: 11 additions & 1 deletion tests/format/scss/scss/scss.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1088,4 +1088,14 @@ label {
// #5636
div {
margin: - pow(2, 2) * 100px;
}
}

$foo: (
'property1': (),
// comment 1
// comment 2

'property2': 1,
/** comment 1 */
/* comment 2 */
);

0 comments on commit 8a3e73c

Please sign in to comment.