简体   繁体   中英

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!

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在此处输入图片说明

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.

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

"printWidth": 100

Reference screenshot: 在此处输入图片说明

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;

您可以在此问题上表示支持-https: //github.com/prettier/prettier/issues/2550

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM