Skip to content

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

Closed

Description

@GrimLink

Prettier 1.17.0
Playground link

--parser scss

Input:

@font-face {
  @each $format in $formats {
    @if $format == local {
      $format-local: local(if($suffix == "Regular", "#{$name}", "#{$name $suffix}")), local("#{$full-name}");
    } @else {
      $format-url: url("#{$path}/#{$file-name}.#{$format}") format("#{$format}");
      $format-src: append($format-src, $format-url, comma);
    }
  }
}

.class {
  background: #eee linear-gradient(100deg, $color-theme 40%, adjust-color($color-theme, $lightness: -4%) 70%, adjust-color($color-theme, $lightness: -9%)) center/cover no-repeat;
}

Output:

@font-face {
  @each $format in $formats {
    @if $format == local {
      $format-local: local(
          if($suffix == "Regular", "#{$name}", "#{$name $suffix}")
        ),
        local("#{$full-name}");
    } @else {
      $format-url: url("#{$path}/#{$file-name}.#{$format}")
        format("#{$format}");
      $format-src: append($format-src, $format-url, comma);
    }
  }
}

.class {
  background: #eee
    linear-gradient(
      100deg,
      $color-theme 40%,
      adjust-color($color-theme, $lightness: -4%) 70%,
      adjust-color($color-theme, $lightness: -9%)
    )
    center/cover no-repeat;
}

Expected behavior:

The first value should not be on the same line as the property.
This is also the default behavior with stylelint-config-recommended.
Which follows the common stylistic conventions found within a handful of CSS styleguides, including: The Idiomatic CSS Principles, Google's CSS Style Guide, Airbnb's Styleguide, and @mdo's Code Guide.

The stylelint rule affected by this.

@font-face {
  @each $format in $formats {
    @if $format == local {
      $format-local:
        local(if($suffix == "Regular", "#{$name}", "#{$name $suffix}")),
        local("#{$full-name}");
    } @else {
      $format-url:
        url("#{$path}/#{$file-name}.#{$format}")
        format("#{$format}");
      $format-src: append($format-src, $format-url, comma);
    }
  }
}

.class {
  background:
    #eee
    linear-gradient(
      100deg,
      $color-theme 40%,
      adjust-color($color-theme, $lightness: -4%) 70%,
      adjust-color($color-theme, $lightness: -9%)
    )
    center/cover
    no-repeat;
}

Activity

  1. added
    lang:css/scss/less
    status:needs discussion
    on Nov 17, 2019
  2. alexander-akait commented on Nov 18, 2019

    @alexander-akait
    Member

    Please provide provide full Expected behavior, i can't understand what is first value in your example

  3. added
    status:awaiting response
    on Nov 18, 2019
  4. GrimLink commented on Nov 18, 2019

    @GrimLink
    Author

    @evilebottnawi sorry, the expected output was also the input 😅
    I changed the input to a unformated version and added Expected behavior code sample.

  5. removed
    status:awaiting response
    on Nov 18, 2019
  6. alexander-akait commented on Nov 18, 2019

    @alexander-akait
    Member

    Unfortunately this is not heuristic and can lead to a very ugly code

  7. GrimLink commented on Nov 18, 2019

    @GrimLink
    Author

    @evilebottnawi please explain why?
    The only difference is the break at the property.

    Output

    .class {
      background: #eee
        linear-gradient()

    Expected

    .class {
      background:
        #eee
        linear-gradient()
  8. alexander-akait commented on Nov 18, 2019

    @alexander-akait
    Member
    .class {
      background: #eee
        linear-gradient(#e66465, #9198e5);
    }

    should be

    .class {
      background: #eee linear-gradient(#e66465, #9198e5);
    }

    because it is heuristic, it is fit in 80 characters

  9. GrimLink commented on Nov 18, 2019

    @GrimLink
    Author

    @evilebottnawi I get the feeling you are not understanding me.
    You comment is correct for 80 characters or less.
    But my issue lies when it is more.
    Then the values should nest under the property.
    Just as with stylelint and many css styleguides.

  10. alexander-akait commented on Nov 18, 2019

    @alexander-akait
    Member

    @GrimLink i.e. break only when it is more than 80 characters?

  11. alexander-akait commented on Nov 18, 2019

    @alexander-akait
    Member

    @GrimLink
    Note:

    a {
      color:
        pink;
    }

    is ugly and should be avoided, let's wait other answers

  12. GrimLink commented on Nov 18, 2019

    @GrimLink
    Author

    @evilebottnawi again it's for multiline properties
    So the second rule (always-multi-line) not the first rule!

    First of the first example is also not used by styleguides.

    a {
      box-shadow:
        0 0 0 1px #5b9dd9,
        0 0 2px 1px rgba(30, 140, 190, 0.8);
    }
  13. JounQin commented on Nov 19, 2019

    @JounQin
    Member

    @GrimLink You should always enable stylelint-config-prettier and stylelint-prettier if you want to use stylelint with prettier together IMO.

    prettier should take care of all formats or styles.

  14. GrimLink commented on Nov 19, 2019

    @GrimLink
    Author

    @JounQin that is not the issue.
    The way prettier formats multiline css properties is.
    Please read issue text -> #6986 (comment) before giving me an answer like this.

  15. JounQin commented on Nov 19, 2019

    @JounQin
    Member

    @GrimLink Sorry, my English is not so good, I still can't get the point, didn't you complain about prettier not formatting your scss expected same as other formatters? Please point out if I'm wrong.

  16. thorn0 commented on Nov 19, 2019

    @thorn0
    Member

    The issue is not about tools and style guides. What @GrimLink wants sounds reasonable to me:

    Prettier 1.19.1
    Playground link

    --parser css
    --print-width 60

    Input:

    .class {
      background:
        #eee
        linear-gradient(100deg, black 40%, yellow 70%, white)
        center/cover
        no-repeat;
    }

    Output:

    .class {
      background: #eee
        linear-gradient(100deg, black 40%, yellow 70%, white)
        center/cover no-repeat;
    }

    Requested:

    .class {
      background: 
        #eee
        linear-gradient(100deg, black 40%, yellow 70%, white)
        center/cover no-repeat;
    }
  17. GrimLink commented on Nov 19, 2019

    @GrimLink
    Author

    @JounQin no problem 😉
    Your not wrong.
    The formatting used by Prettier is different from styleguides and the default from Stylelint, for multiline properties.

    When Prettier formats css that is longer than the max line length the first value is placed before the property.
    Instead being wrapped below, with the rest of the values.

    Wrong:

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

    Expected:

    a {
      box-shadow:
        0 0 0 1px #5b9dd9,
        0 0 2px 1px rgba(30, 140, 190, 0.8);
    }
  18. thorn0 commented on Nov 19, 2019

    @thorn0
    Member

    @GrimLink Please stop mentioning those styleguides and tools. :)

  19. GrimLink commented on Nov 19, 2019

    @GrimLink
    Author

    @GrimLink Please stop mentioning those styleguides and tools. :)

    Yeah maybe you're right 😅

  20. JounQin commented on Nov 19, 2019

    @JounQin
    Member

    @GrimLink Maybe you can reorganize your issue description to make it shorter and clearer. It seems quite misleading?

  21. thorn0 commented on Nov 19, 2019

    @thorn0
    Member

    I'd say better to open a new issue instead of this.

  22. GrimLink commented on Nov 23, 2019

    @GrimLink
    Author

    @thorn0 and @JounQin I followed your advice and moved it to a new issue here -> #7039
    Hope it is better and simpler descripped there 😉

  23. added
    locked-due-to-inactivity
    on Feb 21, 2020
  24. locked as resolved and limited conversation to collaborators on Feb 21, 2020
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-inactivitystatus:needs discussion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions