Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a config in prettier to keep line breaks?

have a problem with prettier extension in VS Code, When I write this:

const result = await pool
      .request()
      .query('select NumberPlate, ID, TimeStamp from RESULTS order by ID');

and save the file, it turns into a single line like this:

const result = await pool.request().query('select NumberPlate, ID, TimeStamp from RESULTS order by ID');

with the following config in prettier:

{
    "git.confirmSync": false,
    "editor.minimap.enabled": false,
    "window.zoomLevel": 0,
    "liveServer.settings.donotShowInfoMsg": true,
    "workbench.startupEditor": "newUntitledFile",
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "editor.formatOnSave": true,
    "prettier.printWidth": 200,
    "prettier.singleQuote": true,
    "prettier.arrowParens": "always",
    "editor.tabSize": 2,
    "editor.tabCompletion": "on"
}

Is there a way to avoid this from happening?

Thanks!

like image 808
juan ocho Avatar asked Jul 10 '19 17:07

juan ocho


3 Answers

According to this Github issue and looking at the doc, it doesn't seem to be possible to configure it to keep line breaks.

You could however set a very short printWidth or put // prettier-ignore comment above your code.

like image 63
Antoine Gagnon Avatar answered Oct 16 '22 14:10

Antoine Gagnon


Please try adding .prettierrc file to your code and adding a line in the object of the file.

"printWidth": 100

Reference screenshot: enter image description here

like image 24
Rahul Mahadik Avatar answered Oct 16 '22 15:10

Rahul Mahadik


Did not find a configuration. As a hack you might want to include a comment on the first line to break:

return ternaryExpression //
          ? trueResult
          : falseResult;
like image 12
Stefan Avatar answered Oct 16 '22 15:10

Stefan