Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you stop Prettier in VS code splitting attributes onto multiple lines?

I am using prettier to format my code in VS Code but I really dislike how it does it.

My main beef is it splitting attributes over multiple lines.

<input     type="checkbox"     name="asiaNews"     id="asiaNews"     value="asiaNews" /> 

I'd much prefer it to look like this

<input type="checkbox" name="asiaNews" id="asiaNews" value="asiaNews" /> 

I can't find anything in the docs or on SO

How to prevent VS Code from breaking up long HTML lines into multiple lines?

Is there a way to do it or a different tool that I can use so I can have my own custom formatting rules that suits my sensibilities?

like image 609
Tristanisginger Avatar asked May 24 '19 10:05

Tristanisginger


People also ask

How can you prevent VS Code from breaking up long HTML lines into multiple lines?

How can you prevent VS Code from breaking up long HTML lines into multiple lines? My solution: Select the SVG you want to convert to single line. Then press F1 and type Join Lines and hit enter.

How do I make my auto format Prettier?

Command+Shift+P to open it. It will show search bar with right arrow >, just start typing Format Document With, and you will come up with results as below. Select Format Document With and again you will be asked for few options. Select Prettier — Code Formatter and your file will be formatted.


1 Answers

A quick fix is to go to Prettier Extension Settings (ctrl + shift + X) and in Prettier Extension Settings search for "Print Width" set it to 250 or anything that works for you.

1: Go to Extention Settings:

Prettier Extension Settings

2: Change the value of Print Width to your liking.

Changing the value of Print Width

To disable format code on save. Turn off the "Format On Save" and use Alt+Shift+F to format the code when ever you want.

Disable or enable Format On Save

You can visually check the setting here

like image 145
Bilal Ahmad Avatar answered Oct 07 '22 19:10

Bilal Ahmad