Repository navigation
fix(css): Improve formatting of at-rules and add tests - #3828
Conversation
cb638be to
589e960
Compare
589e960 to
bc569d0
Compare
lydell
left a comment
There was a problem hiding this comment.
Looks good overall, I just have a few questions.
Awesome work as usual! 🎉
| ) { | ||
| if ( | ||
| node.name.toLowerCase() === "counter-style" || | ||
| node.name.toLowerCase().endsWith("keyframes") || |
There was a problem hiding this comment.
Why does this one need .endsWith()?
There was a problem hiding this comment.
It’s probably for prefixed definitions, like -webkit-keyframes.
| } | ||
|
|
||
| if (node.name === "extend") { | ||
| node.selector = parseSelector(node.params); |
| } | ||
|
|
||
| if (node.name === "at-root") { | ||
| if (/^(\(\s*(without|with)\s*:\s*.+\s*\)$)/.test(node.params)) { |
There was a problem hiding this comment.
/^\(\s*(without|with)\s*:[\s\S]+\)$/?
Can there be whitespace at the start and end? Or is that something the parser has taken care of?
There was a problem hiding this comment.
@lydell valid with any whitespace (\t, \n, and etc)
There was a problem hiding this comment.
I don't understand what you mean?
There was a problem hiding this comment.
@lydell valid in scss:
@at-root
(
without
:
media
) {
color: red;
}There was a problem hiding this comment.
Let me rephrase:
- What do you think of my Regex suggestion?
/^\(\s*(without|with)\s*:[\s\S]+\)$/ - Should there be
\s*at the start and end?/^\s*\(\s*(without|with)\s*:[\s\S]+\)\s*$/
There was a problem hiding this comment.
- Looks good. Let's do fix.
- Node (at rule, decl and etc) contain whitespaces before and after in
raws, it does not have sense to handle before and after spaces.
| $some-number, | ||
| $anotherNumber, | ||
| $BigNumber: 100px | ||
| ) { |
There was a problem hiding this comment.
Should this be:
@function AnotherMyCalculationFunction(
$some-number,
$anotherNumber,
$BigNumber: 100px
) {
@return $some-number + $anotherNumber + $BigNumber;
}?
There was a problem hiding this comment.
(i.e. remove a space from the beginning of the parameter lines)
There was a problem hiding this comment.
@j-f1 yep, first all at rules and tests, second formatting with feedback
There was a problem hiding this comment.
it is still WIP 😄 thanks for feedback, i ping you when all look good and tested
279fc14 to
8f6287b
Compare
j-f1
left a comment
There was a problem hiding this comment.
A couple of things. Also, can you update the file extensions to match the variant of CSS they're using?
| @media print { | ||
| .page { | ||
| width: 8in; | ||
| @at-root (with: media) { |
There was a problem hiding this comment.
Would it make sense to always enforce a bank line before @at-root?
There was a problem hiding this comment.
@j-f1 i think add blank line is bad practice, i am working in many project where people don't add newlines before at rules and always add newline before at rules. I think better output as is. If many contributors vote for the newline can add in the future.
| h3, | ||
| h4, | ||
| h5, | ||
| h6; |
There was a problem hiding this comment.
How about:
@custom-selector :--heading (
h1,
h2,
h3,
h4,
h5,
h6
);There was a problem hiding this comment.
@j-f1 invalid syntax, spec don't allow add ( and )
| @debug $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var + $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var; | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| @debug 10em + 12em; | ||
| @debug 10em+12em; |
There was a problem hiding this comment.
@debug 10em + 12em;Or would that be too difficult to support?
There was a problem hiding this comment.
@j-f1 no, problems in https://github.com/prettier/prettier/blob/master/src/language-css/printer-postcss.js#L341, when i use two space or newlines all look good, seems it is separate issue, i do PR and when rebase
| @debug 10em + 12em; | ||
| @debug 10em + 12em; | ||
| @debug $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var + | ||
| $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var; |
There was a problem hiding this comment.
@debug (
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var +
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var
);| } | ||
| @each $animal, $color, $cursor in (puma, black, default), | ||
| (sea-slug, blue, pointer), (egret, white, move) { | ||
| } |
There was a problem hiding this comment.
@each $animal, $color, $cursor in (
(puma, black, default),
(sea-slug, blue, pointer),
(egret, white, move)
) {
}There was a problem hiding this comment.
@j-f1 do you think it normal to add ( and ) if they are not necessary (we don't output ( and ) they are unnecessary in js)?
| } | ||
| .message-error { | ||
| @extend .message, | ||
| .important; |
There was a problem hiding this comment.
@j-f1 yep, also will add test when selector is very long
|
@j-f1 about extension - i think no, we use |
|
@evilebottnawi |
|
@lydell hm let's open separate Issue/PR for this, i don't think it's worth putting it all in one PR |
8f6287b to
db47e2b
Compare
|
@evilebottnawi FYI you don’t have to squash your commits before you merge — GitHub will do that for you when you click “Squash and merge.” |
|
@j-f1 i known, habit, not all repos on github/gitlab |
dedf36a to
e3cbc7b
Compare
e824e2d to
81be1dd
Compare
|
@lydell @j-f1 friendly ping, some questions:
@while $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var > $other-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var
{
}Output: @while
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var >
$other-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var
{
}We always move on new line variables in control directive into
@for $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var from ($very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var1 + $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var1) through ($very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var-2 + $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var-2) {}Output: @for $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var
from
(
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var1 +
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var1
)
through
// Should we add indent after keywords when they multi line?
(
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var-2 +
$very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var-2
)
{
}
Why i want fix many styles in other PR? Because it is PR already very big and difficult. |
a67bb91 to
e08a7a8
Compare
e08a7a8 to
686dd9f
Compare
lydell
left a comment
There was a problem hiding this comment.
I made some comments on random things I found in the snapshots. You've probably already mentioned some of them yourself. Feel free to merge when you think it makes sense.
| } | ||
| @each $animal in ( (puma), (sea-slug), (egret), (salamander)) { | ||
| } | ||
| @each $animal in ( (puma), (sea-slug), (egret), (salamander)) { |
There was a problem hiding this comment.
Some extra spaces seem to be printed here. Just in case you aren't already aware of these.
There was a problem hiding this comment.
@lydell yep, known, will be fixed in other PR with fix spaces around ( and )
| @each $very-very-very-very-very-very-very-very-very-very-very-very-very-very-very-long-var | ||
| in | ||
| puma, | ||
| sea-slug, egret, salamander |
| } | ||
| @if (($type) == (ocean)) { | ||
| } | ||
| @if (($type)==(ocean)) { |
There was a problem hiding this comment.
This == is not spaced. (Same thing for some other cases a couple of lines down.)
There was a problem hiding this comment.
@lydell problem in postcss-values-parser. Issue https://github.com/shellscape/postcss-values-parser/issues/42.
| @if $very-very-very-very-very-very-long-var == | ||
| 0 and | ||
| $very-very-very-long-var == | ||
| 0 |
There was a problem hiding this comment.
Ideally, the 0s should be on the same line as the ==s.
| @if $base-font-size != | ||
| 16px or | ||
| $base-line-height != | ||
| 24px or |
There was a problem hiding this comment.
Same thing here: Would be great if we could keep the comparisons together.
| @@ -308,6 +3193,12 @@ run-in | |||
| } | |||
| @supports not (transform-origin: 10em | |||
| 10em | |||
| 10em) { | |||
| } | |||
There was a problem hiding this comment.
Something has happened here with all the newlines and stuff.
There was a problem hiding this comment.
@lydell problem in parser, i will fix this in parser, but it is valid code
5bd9d5f to
f1636ea
Compare
f1636ea to
e806d19
Compare
|
Thanks to everyone! In near future i can do PR in parsers and fix some uglify places. |
|
FYI the reason the issues weren’t automatically closed is because you have to put “fixes” before each issue reference, i.e. fixes #1 fixes #2 fixes #3 |
|
@j-f1 yep, accidentally incorrectly written |
|
Don’t worry, it’s not that obvious unless you read the docs 📖 :) |
* 'master' of github.com:prettier/prettier: tests(css): custom media (#3879) Add 3YOURMIND to users.yml (#3881) fix(css): stringify unquoted data urls (#3877) fix(css): at rules improve formatting and tests (#3828) Add option philosophy to docs (#3855) docs: add information about precise-commits (#3818) Remove redundant quotes from image links in .yml files (#3860)
* 'master' of github.com:prettier/prettier: Remove commented out code (#3886) feat: Add support for no-response-bot (#3873) refactor(printer-postcss): use `node` name and implement helper functions (#3893) tests(css): custom media (#3879) Add 3YOURMIND to users.yml (#3881) fix(css): stringify unquoted data urls (#3877) fix(css): at rules improve formatting and tests (#3828) Add option philosophy to docs (#3855) docs: add information about precise-commits (#3818)
Fixes #3875 #3721 #3282 #2852 #2594 #2158
Feel free to review 👍