2

I have the Prettier extension added to my VS Code editor.

When using Less or Sass, the default settings format code like this:

// Default

.parent_selector {
  .child_selector {
    color: red;
  }
}
// Desired Format

.parent_selector {

  .child_selector {
    color: red;
  }
}

How could I tweak the Prettier CSS settings to achieve this? I know it seems trivial, but in bigger code bases it helps readability.

6
  • so you said Prettier doesn't work with less and sass, right? Commented Mar 20, 2019 at 19:27
  • The rule you want is that a blank line should be added after the start of a new nesting block? Or a blank line should be added before every rule within a scope? Commented Mar 20, 2019 at 19:27
  • @demo Prettier does work with Less and Sass: Less example Commented Mar 20, 2019 at 19:28
  • @RoryO'Kane Ideally I just want a space before every rule in a scope Commented Mar 20, 2019 at 19:29
  • 3
    Prettier is opinionated, so the Prettier tool tries not to provide too many options. I tried changing all of the options in the Prettier playground, but none of them achieved that effect. Therefore, you will have to accomplish this formatting change with some other CSS formatting tool. The solution might also use one of those tools that helps you set up a single command to run Prettier followed by another program that touches up Prettier’s formatting. Commented Mar 20, 2019 at 19:36

1 Answer 1

2

As an alternative method; It can be achieved by using stylelint plugin and stylelint-config-standard rules.

npm install --save-dev stylelint stylelint-config-standard

After installing them, proceed with ctrl+shift+p on VS Code and run command: stylelint: fix all auto-fixable problems.

stylelint: fix all auto-fixable problems

PS: Consider assigning a keyboard shortcut for stylelint: fix all auto-fixable problems command for easy access.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.