Sujoy Karmaker
Sujoy Karmaker

Reputation: 69

How to stop vscode beautify or prettier from preserving newlines when formatting javascript code?

I want to remove all the newlines/extra lines when I save the code. I found this settings in Atom but not in VSCode. How can I do that?

Upvotes: 4

Views: 6107

Answers (2)

Wedt52
Wedt52

Reputation: 1

You can also set Trim Final New lines to on and set Max Preserve New lines to your need.

Vs code settings image

Upvotes: -2

Guillermo Gutiérrez
Guillermo Gutiérrez

Reputation: 17789

You can set the VSCode setting html.format.preserveNewLines to false. It will be recognized by Beautify, but works only for HTML files.

The alternative to apply the setting for all files recognized by Beautify is to add a file named .jsbeautifyrc at the root of the workspace, with the following content:

{
   "preserve_newlines": false
}

Also, the VSCode setting editor.formatOnSave should be set to true. To do it you can create the file .vscode/settings.json with the next content:

{
    "editor.formatOnSave": true
}

The settings.json file, located at the .vscode folder in the root of the workspace, allows to configure the VSCode settings to be applied for the current workspace.

Upvotes: 4

Related Questions