简体   繁体   English

是否有更漂亮的配置来保持换行符?

[英]Is there a config in prettier to keep line breaks?

have a problem with prettier extension in VS Code, When I write this:在 VS Code 中使用更漂亮的扩展有问题,当我写这个时:

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'.如果您打开 VSC 并进入设置,然后进入扩展并单击“更漂亮”,那么在更漂亮的下方会勾选一个复选框:“需要配置”。 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.根据this Github issue并查看文档,似乎无法将其配置为保持换行符。

You could however set a very short printWidth or put // prettier-ignore comment above your code.但是,您可以设置一个非常短的printWidth或在代码上方放置// prettier-ignore printWidth // prettier-ignore注释。

Please try adding .prettierrc file to your code and adding a line in the object of the file.请尝试将 .prettierrc 文件添加到您的代码中,并在文件的对象中添加一行。

"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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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