Repository navigation
Open
Labels
lang:css/scss/lessIssues affecting CSS, Less or SCSS
Description
Goal: Print them more like JS. Flatten indentation and group operators. Also, space the operators (as mentioned in #2793): 1+1 → 1 + 1.
.Image {
@media (max-width: $image-width-responsive) {
padding-bottom:
(
100% *
$image-height /
($image-width-responsive + $image-margin-responsive * 2)
);
}
}.Image {
@media (max-width: $image-width-responsive) {
padding-bottom: (
100% *
$image-height / ($image-width-responsive + $image-margin-responsive * 2)
);
}
}Compare to this JS:
{
{
padding_bottom = (
100 *
$image_height /($image_width_responsive + $image_margin_responsive * 2)
);
}
}{
{
padding_bottom =
100 *
$image_height /
($image_width_responsive + $image_margin_responsive * 2);
}
}a {
b {
img {
max-height:
calc(
100vh -
#{var(--margin)} * 2 - #{var(--padding)} * 2 -
#{$extra-space-for-scrollbar}
);
}
}
}a {
b {
img {
max-height: calc(
100vh -
#{var(--margin)} *
2 -
#{var(--padding)} *
2 -
#{$extra-space-for-scrollbar}
);
}
}
}Compare to this JS:
{
{
max_height = calc(
100 -
$(car(__margin)) *
2 -
$(car(__padding)) *
2 -
$($extra_space_for_scrollbar)
);
}
}{
{
max_height = calc(
100 -
$(car(__margin)) * 2 -
$(car(__padding)) * 2 -
$($extra_space_for_scrollbar)
);
}
}Extracted from: #1805
Important comment by @vjeux:
Right now we only get a stream of tokens. We'd need to parse it to be able to reprint it properly. For this, we need to implement a small arithmetic parser and print it correctly. It shouldn't be too hard
Metadata
Metadata
Assignees
Labels
lang:css/scss/lessIssues affecting CSS, Less or SCSS
Activity
j-f1 commentedon Jan 29, 2018
Here’s the current status of this:
Prettier 1.10.2
Playground link
Input:
Output:
Is this good enough to close the issue?
lydell commentedon Jan 29, 2018
The other example does not look very good though. I exceeds the print width.
Prettier 1.10.2
Playground link
Input:
Output:
lydell commentedon Jan 29, 2018
And if you use a sane print width, the first example is not so pretty either:
Prettier 1.10.2
Playground link
Input:
Output:
j-f1 commentedon Jan 29, 2018
Looks like I forgot to change this option after adding a playground example to another issue.
TomFryersMidsummer commentedon Oct 9, 2025
Also, when
experimentalOperatorPosition: startis set, if the lines do need breaking, then the operators ought to go at the beginnings of the lines, matching JS.fix(formatter_css): print a media feature value as flat text