Skip to content

fix(css): Improve formatting of at-rules and add tests - #3828

Merged
alexander-akait merged 1 commit into
masterfrom
tests-css-at-rules
Feb 2, 2018
Merged

alexander-akait merged 1 commit into
masterfrom
tests-css-at-rules

Conversation

@alexander-akait

@alexander-akait alexander-akait commented Jan 26, 2018 •

Copy link
Copy Markdown
Member

Fixes #3875 #3721 #3282 #2852 #2594 #2158

Feel free to review 👍

@j-f1 j-f1 added the status:wip Pull requests that are a work in progress and should not be merged label Jan 26, 2018
@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 2 times, most recently from cb638be to 589e960 Compare January 26, 2018 17:18
@vjeux
vjeux removed their request for review January 26, 2018 17:23

@lydell lydell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good overall, I just have a few questions.

Awesome work as usual! 🎉

) {
if (
node.name.toLowerCase() === "counter-style" ||
node.name.toLowerCase().endsWith("keyframes") ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this one need .endsWith()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It’s probably for prefixed definitions, like -webkit-keyframes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell prefixes -webkit-keyframes and etc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks! 👍

}

if (node.name === "extend") {
node.selector = parseSelector(node.params);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is so good 👍

Comment thread src/language-css/parser-postcss.js Outdated
}

if (node.name === "at-root") {
if (/^(\(\s*(without|with)\s*:\s*.+\s*\)$)/.test(node.params)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/^\(\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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell valid with any whitespace (\t, \n, and etc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand what you mean?

@alexander-akait alexander-akait Jan 26, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell valid in scss:

@at-root 

(

without

: 

media

) {
    color: red;
}

@lydell lydell Jan 26, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let me rephrase:

  1. What do you think of my Regex suggestion? /^\(\s*(without|with)\s*:[\s\S]+\)$/
  2. Should there be \s* at the start and end? /^\s*\(\s*(without|with)\s*:[\s\S]+\)\s*$/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell

  1. Looks good. Let's do fix.
  2. 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
) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be:

@function AnotherMyCalculationFunction(
  $some-number,
  $anotherNumber,
  $BigNumber: 100px
) {
  @return $some-number + $anotherNumber + $BigNumber;
}

?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(i.e. remove a space from the beginning of the parameter lines)

@alexander-akait alexander-akait Jan 26, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@j-f1 yep, first all at rules and tests, second formatting with feedback

@alexander-akait alexander-akait Jan 26, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it is still WIP 😄 thanks for feedback, i ping you when all look good and tested

@j-f1 j-f1 changed the title [WIP] fix(css): at rules imrpove formatting and tests [WIP] fix(css): Improve formatting of at-rules and add tests Jan 26, 2018
@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 9 times, most recently from 279fc14 to 8f6287b Compare January 29, 2018 16:34
@alexander-akait

Copy link
Copy Markdown
Member Author

@lydell @j-f1 ready for feedback around improve stylistics at rules, all css/scss/less at rule tests added and passed

@j-f1 j-f1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make sense to always enforce a bank line before @at-root?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about:

@custom-selector :--heading (
  h1,
  h2,
  h3,
  h4,
  h5,
  h6
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@debug 10em + 12em;

Or would that be too difficult to support?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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) {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@each $animal, $color, $cursor in (
  (puma, black, default),
  (sea-slug, blue, pointer),
  (egret, white, move)
) {
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@extend .message, .important;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@j-f1 yep, also will add test when selector is very long

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@j-f1 done

@alexander-akait

alexander-akait commented Jan 30, 2018 •

Copy link
Copy Markdown
Member Author

@j-f1 about extension - i think no, we use IS_POSSIBLY_SCSS and it is allow tests what syntax correctly was parsed

@lydell

lydell commented Jan 30, 2018

Copy link
Copy Markdown
Member

@evilebottnawi IS_POSSIBLY_SCSS is kinda broken. If we can avoid it it’d be great.

@alexander-akait

Copy link
Copy Markdown
Member Author

@lydell hm let's open separate Issue/PR for this, i don't think it's worth putting it all in one PR

@j-f1

j-f1 commented Jan 30, 2018

Copy link
Copy Markdown
Member

@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.”

@alexander-akait

Copy link
Copy Markdown
Member Author

@j-f1 i known, habit, not all repos on github/gitlab

@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 3 times, most recently from dedf36a to e3cbc7b Compare January 30, 2018 18:25
@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 3 times, most recently from e824e2d to 81be1dd Compare January 31, 2018 15:51
@alexander-akait

alexander-akait commented Jan 31, 2018 •

Copy link
Copy Markdown
Member Author

@lydell @j-f1 friendly ping, some questions:

  1. Many of scss structure don't support parens around control directive (example @for), i.e. i think better avoid using parens where is possible. Also scss guidelines advice don't use parens too. But remove unnecessary parens i will do in next PR. This PR already very big and difficult.

  2. Should we add break line in multi line control directive.
    Input:

@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 js

  1. Some tests contain $i>0, it is also net related to this PR and will do in other next PR (problem in parse $i>0 - is value-word)

  2. Difficult @supports directives look very uglify, problem in postcss-media-parser. It should be fixed in parser. In near future i will do PR

  3. 
    
  4. mix (...) parses as value-word + parens + '...' + parent. Css don't support here space, but scss support. Will be fixed in other PR. It is also don't break code. Done in this PR

  5. @for directive
    Input:

@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
  )
{
}
  1. Also please look on @custom-selector and feedback welcome.

  2. Problem with spaces before parens (i.e. -($var) and $var-($other-var)) will be fixed in other PR, not related to this.

Why i want fix many styles in other PR? Because it is PR already very big and difficult.
Thanks for everyone!

@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 5 times, most recently from a67bb91 to e08a7a8 Compare January 31, 2018 17:28
@alexander-akait alexander-akait changed the title [WIP] fix(css): Improve formatting of at-rules and add tests fix(css): Improve formatting of at-rules and add tests Jan 31, 2018
@alexander-akait alexander-akait removed the status:wip Pull requests that are a work in progress and should not be merged label Jan 31, 2018

@lydell lydell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some extra spaces seem to be printed here. Just in case you aren't already aware of these.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Isn't the indentation odd here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell yep, fix here 👍

}
@if (($type) == (ocean)) {
}
@if (($type)==(ocean)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This == is not spaced. (Same thing for some other cases a couple of lines down.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@if $very-very-very-very-very-very-long-var ==
0 and
$very-very-very-long-var ==
0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ideally, the 0s should be on the same line as the ==s.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell yep need fix 👍

@if $base-font-size !=
16px or
$base-line-height !=
24px or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same thing here: Would be great if we could keep the comparisons together.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell 👍

@@ -308,6 +3193,12 @@ run-in
}
@supports not (transform-origin: 10em
10em
10em) {
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Something has happened here with all the newlines and stuff.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@lydell problem in parser, i will fix this in parser, but it is valid code

@alexander-akait
alexander-akait force-pushed the tests-css-at-rules branch 4 times, most recently from 5bd9d5f to f1636ea Compare February 2, 2018 14:07
@alexander-akait

Copy link
Copy Markdown
Member Author

Thanks to everyone! In near future i can do PR in parsers and fix some uglify places.

@alexander-akait
alexander-akait merged commit f5e74cd into master Feb 2, 2018
@alexander-akait
alexander-akait deleted the tests-css-at-rules branch February 2, 2018 15:06
@j-f1

j-f1 commented Feb 2, 2018

Copy link
Copy Markdown
Member

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

@alexander-akait

Copy link
Copy Markdown
Member Author

@j-f1 yep, accidentally incorrectly written fixes

@j-f1

j-f1 commented Feb 2, 2018

Copy link
Copy Markdown
Member

Don’t worry, it’s not that obvious unless you read the docs 📖 :)

lipis added a commit that referenced this pull request Feb 4, 2018
* '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)
lipis added a commit that referenced this pull request Feb 5, 2018
* '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)
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants