Report this

What is the reason for this report?

Prettier custom rules (formatter)?

Posted on May 29, 2021

Is there a way to set a full custom rule for prettier code formatter?

For example, if you don’t like this CSS coding style:

Body { color: red; }

But you like it that way:

Body { color:red; }

No space after : and a new line for { and }

Or in HTML prettier removes new lines after opening a DIV like:

<div> <p>My paragraph Text</p> <p>My paragraph Text</p> </div>

But I would not remove my custom new lines like:

<div>

<p>My paragraph Text</p>

<p>My paragraph Text</p>

</div>

Prettier makes the Code like this:

<div> <p>My paragraph Text</p>

<p>My paragraph Text</p> </div>

In between, prettier “allows” new lines. But inside something like a DIV, the first and last element “touch” the opening and ending DIV. So basically for HTML I would like to disable the deletion of new blank lines.

Is there a way to create a “coding style template” for each language so that prettier follow that “rules”?!

Or is there an other extension to do that?

Every company have their own “coding style”. 90% is the same, but some small things are different.

For example 4 new blank lines, after each Function to separate them better from each other. But if those lines get removed, you can’t use prettier…

So basically I (we) search for a full customization Coding style (formatter) Extension for VSCode.

Thanks for reading, and sry for the long text.

Best wishes, and stay healthy. Benjamin Schäfer



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

You can customize your prettier configurations by adding a .prettierrc file in your project root directory.

Read more here about config for languages - https://prettier.io/docs/en/configuration.html

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.