Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix less/scss format error #12536

Merged
merged 2 commits into from Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/language-css/printer-postcss.js
Expand Up @@ -924,15 +924,16 @@ function genericPrint(path, options, print) {
if (
!isLast &&
child.type === "value-comma_group" &&
child.groups &&
child.groups[0].type !== "value-paren_group" &&
Copy link
Sponsor Member Author

@fisker fisker Mar 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this line is added for the same reason. Added in #12210

isNextLineEmpty(
options.originalText,
getLast(child.groups),
locEnd
)
isNonEmptyArray(child.groups)
) {
printed.push(hardline);
const last = getLast(child.groups);
if (
// `value-paren_group` missing location info
last.source &&
isNextLineEmpty(options.originalText, last, locEnd)
) {
printed.push(hardline);
}
}

return printed;
Expand Down
12 changes: 12 additions & 0 deletions tests/format/less/parens/2.less
@@ -0,0 +1,12 @@
.background-gradient(@cut) {
background: linear-gradient(
to right,


/* Should preserve empty lines */
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}
34 changes: 34 additions & 0 deletions tests/format/less/parens/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`2.less format 1`] = `
====================================options=====================================
parsers: ["less"]
printWidth: 80
| printWidth
=====================================input======================================
.background-gradient(@cut) {
background: linear-gradient(
to right,


/* Should preserve empty lines */
@white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}

=====================================output=====================================
.background-gradient(@cut) {
background: linear-gradient(
to right,

/* Should preserve empty lines */ @white 0%,
@white (@cut - 0.01%),
@portal-background @cut,
@portal-background 100%
);
}

================================================================================
`;

exports[`parens.less format 1`] = `
====================================options=====================================
parsers: ["less"]
Expand Down
15 changes: 15 additions & 0 deletions tests/format/scss/parens/2.scss
@@ -0,0 +1,15 @@
$icons: (
cal-day-group:
(
left: 253,
top: 73,
),


/* Should preserve empty lines */
cal-week-group:
(
left: 1,
top: 169,
)
);
38 changes: 38 additions & 0 deletions tests/format/scss/parens/__snapshots__/jsfmt.spec.js.snap
@@ -1,5 +1,43 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`2.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]
printWidth: 80
| printWidth
=====================================input======================================
$icons: (
cal-day-group:
(
left: 253,
top: 73,
),


/* Should preserve empty lines */
cal-week-group:
(
left: 1,
top: 169,
)
);

=====================================output=====================================
$icons: (
cal-day-group: (
left: 253,
top: 73,
),
/* Should preserve empty lines */ cal-week-group:
(
left: 1,
top: 169,
),
);

================================================================================
`;

exports[`parens.scss format 1`] = `
====================================options=====================================
parsers: ["scss"]
Expand Down