Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prettier formats in multiline for arrays and long line in VSCode

When I use a long array and console, prettier formats it into multiple lines which is annoying in some cases. I want them break after a certain length. Can I set a breaking point for the prettier where it will make the new line? Please check the image. Prettier format demo

like image 581
Sabbir Ahmed Saif Avatar asked Jan 07 '20 02:01

Sabbir Ahmed Saif


People also ask

How can I prevent Prettier from taking multi line array to a single line?

Set the option in settings. Appending this line to the end of your settings. json file means Prettier will only wrap the line when it exceeds 1000 characters (essentially never). You can change this number to preference, for reference the default is 80 . Just make sure to save changes to the file and you are done!

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

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. 2: Change the value of Print Width to your liking. To disable format code on save.


2 Answers

Sadly can't be done, here you can find the discussion about the issue. The only apparently solution it's to add a comment // after the first array element:

Example:

imports: [
        BrowserModule, //
        FoodModule,
        SharedModule,
        AppRoutingModule
    ],
like image 196
Luis Alfredo Serrano Díaz Avatar answered Nov 03 '22 05:11

Luis Alfredo Serrano Díaz


There's a fork of Prettier called Prettier Now that allows this.

After downloading, go into your settings.json and add ⤵︎

"prettier.arrayExpand": true
like image 45
tyirvine Avatar answered Nov 03 '22 04:11

tyirvine