Skip to content

SCSS always expands comma selectors and single-line rules to multiple lines #3464

Closed

Description

@j-f1

Prettier 1.9.2
Playground link

--parser scss

Input:

h1, h2, h3, h4, h5, h6 {
  font-weight: bold;
}

h1 { font-size: 3em; }
h2 { font-size: 2.5em; }
h3 { font-size: 2em; }
h4 { font-size: 1.5em; }
h5 { font-size: 1em; }
h6 { font-size: 0.5em; }

Output:

h1,
h2,
h3,
h4,
h5,
h6 {
  font-weight: bold;
}

h1 {
  font-size: 3em;
}
h2 {
  font-size: 2.5em;
}
h3 {
  font-size: 2em;
}
h4 {
  font-size: 1.5em;
}
h5 {
  font-size: 1em;
}
h6 {
  font-size: 0.5em;
}

Expected behavior:
No changes from input

Activity

  1. lydell commented on Dec 12, 2017

    @lydell
    Member

    Sorry, the decision has already been made to put every selector on its own line. See #2047, #1962, #2057, #2213.

    Regarding single-line rules, that's consistent with how Prettier always prints if (foo) { something(); } multi-line.

    P.S. Could you try to report one thing per issue in the future? Makes things much easier to discuss. Thanks! :)

  2. added
    lang:css/scss/less
    on Dec 12, 2017
  3. j-f1 commented on Dec 12, 2017

    @j-f1
    MemberAuthor

    P.S. Could you try to report one thing per issue in the future? Makes things much easier to discuss. Thanks! :)

    Sorry about that. I kinda got carried away when making the example in the playground 😄

    Regarding single-line rules, that's consistent with how Prettier always prints if (foo) { something(); } multi-line.

    Yes, but JS also has the if (foo) something(); syntax. CSS doesn’t have that, and it would be nice IMHO to inline a CSS block with one statement (i.e. img { background: red; margin: 2px; } gets transformed, while img { background: red; } doesn’t.

  4. j-f1 commented on Dec 12, 2017

    @j-f1
    MemberAuthor

    Would a PR be accepted for making single-declaration rules like foo.bar { baz: 'quux'; } stay on one line be accepted?

  5. lydell commented on Dec 13, 2017

    @lydell
    Member

    @j-f1 I doubt that. Prettier tries to have as few options as possible. See #3038 for a CSS-option PR that went far but probably won't be merged.

  6. added
    locked-due-to-inactivity
    on Jul 6, 2018
  7. locked as resolved and limited conversation to collaborators on Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:css/scss/lesslocked-due-to-inactivity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions