Skip to content

CSS Multiline declaration should not be on the same line as the property #7039

Description

@GrimLink

Prettier 1.19.1
Playground link

--parser css

Input:

a {
  box-shadow: 0 0 0 1px rgba(30, 140, 190, 0.8), 0 0 2px 1px rgba(30, 140, 190, 0.8);
}

Output:

a {
  box-shadow: 0 0 0 1px rgba(30, 140, 190, 0.8),
    0 0 2px 1px rgba(30, 140, 190, 0.8);
}

Expected behavior:

a {
  box-shadow:
    0 0 0 1px rgba(30, 140, 190, 0.8),
    0 0 2px 1px rgba(30, 140, 190, 0.8);
}

The first value should not be on the same line as the property when wrapped to multiline declaration.

Old previous issue #6986

Activity

  1. added
    lang:css/scss/less
    status:needs discussion
    on Nov 23, 2019
  2. whatisaphone commented on May 1, 2020

    @whatisaphone

    Search keywords: newline comma multiple split lines

    I often notice this with transition too.

    Current formatting:

    .box {
      transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out,
        border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    }

    Ideal formatting:

    .box {
      transition:
        color 0.15s ease-in-out,
        background-color 0.15s ease-in-out,
        border-color 0.15s ease-in-out,
        box-shadow 0.15s ease-in-out;
    }

    To avoid some of the confusion from the last issue, this should of course continue to respect printWidth like usual.

    80 characters wide:

    .box {
      background: aaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccc;
    }

    81 characters wide:

    .box {
      background:
        aaaaaaaaaaaaaaaaaa,
        bbbbbbbbbbbbbbbbbbbbb,
        ccccccccccccccccccccccc;
    }
  3. domske commented on Sep 4, 2020

    @domske

    Yes, please implement this behavior. Either break when overflow the line width or always. I would prefer always, because it's very clean (prettier) when all values are below each other. You can change it without any confusion.

    Current behavior (BAD):

    .text {
      text-shadow: 1px 0px 0px black, 0px 1px 0px black, -1px 0px 0px black,
        0px -1px 0px black;
    }

    Wrong implementation (BAD):

    .text {
      text-shadow: 1px 0px 0px black, 
        0px 1px 0px black, 
        -1px 0px 0px black,
        0px -1px 0px black;
    }

    Correct implementation (GOOD):

    .text {
      text-shadow: 
        1px 0px 0px black, 
        0px 1px 0px black, 
        -1px 0px 0px black,
        0px -1px 0px black;
    }

    Always - If more than one value. (BEST):

    .text {
      text-shadow: 
        1px 1px 0px black, 
        -1px -1px 0px black;
    }

    Prettier could either accept an option if "always" or on line overflow. OR detect it automatically if a line break is inserted before the first value.

    Current workaround (disable prettier / BAD):

    .text {
      /* prettier-ignore */
      text-shadow: 
        1px 0px 0px black, 
        0px 1px 0px black, 
        -1px 0px 0px black,
        0px -1px 0px black;
    }
  4. alexander-akait commented on Sep 4, 2020

    @alexander-akait
    Member

    Here good example how it should work #7039 (comment)

  5. domske commented on Sep 4, 2020

    @domske

    Yes (like my example), but please consider breaking always by an option or line break detection before values start. Such behavior already exists in Prettier for other languages. I would prefer formatting multiline if more than one value.

  6. ext commented on Sep 11, 2020

    @ext

    I've recently hit this issue as well and I'm a bit surprised by the current behavior. I believe the best implementation would be to always add line-breaks when using multiple declarations since it adds clarity and makes it obvious multiple statements are present:

    .my-class {
      transition: 
        background-color 250ms ease-in-out,
        color 250ms ease-in-out,
        opacity 250ms ease-in-out;
    }
  7. y0nd0 commented on Feb 11, 2021

    @y0nd0

    Sereosly, why is this not already implemented in Prettier? Beacuase this is prettier.

    Another demo:

    Current Prettier output

    .something {
      transition: color 150ms cubic-bezier(0.4, 0, 0.2, 1),
        transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
    }

    Expected "prettier" output

    .something {
      transition:
        color 150ms cubic-bezier(0.4, 0, 0.2, 1),
        transform 150ms cubic-bezier(0.4, 0, 0.2, 1);
    }

    Only break when multiple values are assigned. Single values can be formatted like the current behavior in one line.

    I just wonder why the tag status:needs discussion? What's not clear?
    It's Prettier and not Uglier. That is a very clear case. But please explain to me.
    What's the problem here?

  8. added and removed
    status:needs discussion
    on Feb 11, 2021
  9. thorn0 commented on Feb 15, 2021

    @thorn0
    Member

    Duplicate of #6024

  10. added
    type:duplicate
    on Feb 15, 2021
  11. added
    locked-due-to-inactivity
    on May 17, 2021
  12. locked as resolved and limited conversation to collaborators on May 17, 2021
  13. added theissue type on Mar 3, 2025
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-inactivitytype:duplicate

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions