62

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!

David Browne - Microsoft
  • 80,331
  • 6
  • 39
  • 67
juan ocho
  • 823
  • 1
  • 7
  • 13

4 Answers4

36

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.

Antoine Gagnon
  • 874
  • 7
  • 13
  • 3
    why have to set a very short printWidth? It's not working. We must use a larger number. I have to put the `// prettier-ignore` comment – Nam Lee Oct 06 '22 at 18:09
33

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

Rahul Mahadik
  • 794
  • 11
  • 19
  • it's not working, 100 is short, how can it keep line breaks? We must use a larger number?? – Nam Lee Oct 06 '22 at 18:10
  • @NamLêQuý, this worked for me, but you can surely add more. You can also refer to the below URL for more info about the property. URL: https://prettier.io/docs/en/options.html#print-width – Rahul Mahadik Oct 08 '22 at 16:14
15

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;
Stefan
  • 10,010
  • 7
  • 61
  • 117
5

If you open VSC and go into settings then Extentions and click on "prettier" there's a check box ticked under Prettier: 'Require Config'. If that's unchecked it will break your lines automatically enter image description here

Jarred
  • 181
  • 1
  • 6