Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve empty line between CSS blocks #2621

Closed
nelsieborja opened this issue Aug 13, 2017 · 11 comments
Closed

Preserve empty line between CSS blocks #2621

nelsieborja opened this issue Aug 13, 2017 · 11 comments
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@nelsieborja
Copy link

For readability purpose, I want to enforce space between CSS blocks like so:

.style1 {
   ...
}

.style2 {
   ...
}

Does this already exist? I can't seem to find its availability in your rules..

@lydell
Copy link
Member

lydell commented Aug 13, 2017

Somewhat related: #2068

@nelsieborja
Copy link
Author

Nope not working for SCSS but works for JS...

Wildcard just to see if it'll work but not at all

"padding-line-between-statements": [
      "error",
      { "blankLine": "always", "prev": "*", "next": "*" }
    ]

@gvincentlh
Copy link

Bump. We'd like to use Prettier on our SCSS but can't until this issue is resolved :-(

@lydell
Copy link
Member

lydell commented Aug 16, 2017

@nelsieborja and @gvincentlh Can you clarify if you want empty lines in the input code to be preserved (like in JS → will likely be fixed, or already works, not sure atm), or if you want to enforce blank lines at specific places (unlikely to happen)?

@gvincentlh
Copy link

@lydell we would need the ability to enforce (via config switch?) blank lines between selectors.

@lydell
Copy link
Member

lydell commented Aug 17, 2017

Here is a clarification of the current state:

Currently, handling of blank lines works the same for CSS as in JS.

In JS, Prettier never prints blank lines on its own. It only preserves blank lines from the input JS (with some extra rules). This is because finding where to place blank lines in JS is hard, and allowing the user to choose where they should be is a trade-off that had to be made to make Prettier usable in practice.

So, currently, the same applies to CSS.

  • It is consistent if we handle blank lines the same as in JS.
  • But CSS is a much simpler language, so it could be possible to make Prettier decide where blank lines go.
  • That's why Option for ignoring original formatting 100% #2068 is related, because it discusses a mode where all original formatting is completely ignored, including blank lines – so Prettier would have to decide where to put blank lines instead.

@lydell lydell added the lang:css/scss/less Issues affecting CSS, Less or SCSS label Sep 5, 2017
@cmseaton42
Copy link

Has this been resolved? Is there currently a work around?

@lydell
Copy link
Member

lydell commented Dec 15, 2017

@cmseaton42 No, this is not resolved. Workaround: Use stylelint.

@nelsieborja
Copy link
Author

Thanks @lydell works perfectly with styelint

@alexander-akait
Copy link
Member

Closing. Should be done with stylelint. Thanks!

@jeddy3
Copy link

jeddy3 commented Feb 26, 2018

New options were recently added to the *-empty-line-before rules of stylelint. These options were added to help stylelint and Prettier work better together. Previously, both stylelint and Prettier would attempt to pretty-print/lint/format the first-nested node of each block. Now stylelint can be configured to ignore these first-nested nodes, leaving prettier to remove any empty lines before them without conflict. stylelint can then be used to just lint/format the empty lines between at-rules, rules, declarations and custom properties.

The following configuration makes use of these new options, and I believe it will configure stylelint to avoid stepping on Prettier's toes:

{
  "rules": {
    "at-rule-empty-line-before": [
      "always",
      {
        "except": ["blockless-after-same-name-blockless"],
        "ignore": ["after-comment", "first-nested"],
        "severity": "warning"
      }
    ],
    "custom-property-empty-line-before": [
      "always",
      {
        "except": ["after-custom-property"],
        "ignore": ["after-comment", "first-nested", "inside-single-line-block"],
        "severity": "warning"
      }
    ],
    "declaration-empty-line-before": [
      "always",
      {
        "except": ["after-declaration"],
        "ignore": ["after-comment", "first-nested", "inside-single-line-block"],
        "severity": "warning"
      }
    ],
    "rule-empty-line-before": [
      "always",
      {
        "ignore": ["after-comment", "first-nested"],
        "severity": "warning"
      }
    ]
  }
}

You'll need at least stylelint@9.1.1 for this config to work.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 5, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 5, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lang:css/scss/less Issues affecting CSS, Less or SCSS locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

6 participants