Open nex3 opened 6 years ago
It's worth noting that these are aesthetic rather than semantic concerns, so if you feel like your output is better you're allowed to leave it as-is. But it's probably better to align the implementations where possible.
Might be related to https://github.com/sass/libsass/issues/1026
Can you elaborate a bit how the formatting works? I fail to see the logic behind it!
div { a {
/*************
* a
* multiline
* comment
*/
top: 10px;
} }
div a {
/*************
* a
* multiline
* comment
*/
top: 10px;
}
div { a {
/*************
* a
* multiline
* comment
*/
top: 10px;
} }
div a {
/*************
* a
* multiline
* comment
*/
top: 10px;
}
div { a {
/*************
* a
* multiline
* comment
*/
top: 10px;
} }
div a {
/*************
* a
* multiline
* comment
*/
top: 10px;
}
div { a {
/*************
* a
* multiline
* comment
*/
top: 10px;
} }
div a {
/*************
* a
* multiline
* comment
*/
top: 10px;
}
As you can see the lines following the initial comment have different indentation every time! But I have no clue what logic this follows!
BTW. the test were made with scss syntax! sass2scss preserves original input as much as possible!
I tested with dart-sass and ruby sass and it mostly seem to correspond: One case where it differs is with ten spaces initial indentation:
div { a {
/*************
* a
* multiline
* comment
*/
top: 10px;
} }
div a {
/*************
div a {
/*************
* a
* multiline
* comment
*/
top: 10px;
}
AFAIR LibSass only adjusts the initial line to indent according to the scope and keeps the rest as is.
For loud comments that come from SCSS, the relative indentation of each line of the comment should be preserved. In your examples in https://github.com/sass/libsass/issues/2566#issuecomment-373906449, the subsequent lines of the comment are indented seven, four, two, and zero levels deeper than the opening line, and that relative depth is preserved in the output when the entire comment is re-indented so that the shallowest line appears at the current indentation level.
In cases like https://github.com/sass/libsass/issues/2566#issuecomment-373906863, where the first line is deeper than the subsequent lines, it looks like neither Ruby nor Dart Sass handle that ideally. I'd expect this output:
div a {
/*************
* a
* multiline
* comment
*/
top: 10px; }
which preserves the relative indentation and places the shallowest line at the current indentation level. But I think these types of comments are unlikely to appear in practice, so I wouldn't sweat their formatting too much.
There are a few cases where LibSass's formatting of loud comments in the indented syntax differs from Dart Sass's (and Ruby Sass's):
Asterisks aren't added on each line. For example, for:
Dart and Ruby Sass produce
but LibSass produces
Comments that don't start on the same line as the opening
/*
have an empty line at the beginning. For example, for:Dart and Ruby Sass produce
but LibSass produces
Empty lines aren't preserved. For example, for:
Dart and Ruby Sass produce
but LibSass produces
I'm adding specs for this in sass/sass-spec#1215.