有没有漂亮的配置来保持换行符?

时间:2019-07-10 17:31:46

标签: javascript express prettier

VS代码中的漂亮扩展有问题, 当我写这篇文章时:

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

并保存文件,它将变成一行,如下所示:

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

具有以下更漂亮的配置:

{
    "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"
}

有办法避免这种情况发生吗?

谢谢!

4 个答案:

答案 0 :(得分:3)

未找到配置。作为黑客,您可能希望在第一行中断处添加评论:

return ternaryExpression //
          ? trueResult
          : falseResult;

答案 1 :(得分:0)

根据this Github issue并查看该文档,似乎无法对其进行配置以保留换行符。

不过,您可以设置非常短的printWidth或在代码上方放置// prettier-ignore注释。

答案 2 :(得分:0)

如果您打开VSC并进入设置,然后单击扩展,然后单击“更漂亮”,则在“更漂亮”下勾选了一个复选框:“ Require Config”。如果未选中,它将自动中断您的行 enter image description here

答案 3 :(得分:0)

请尝试将 .prettierrc 文件添加到您的代码中,并在文件的对象中添加一行。

"printWidth": 100

参考截图: enter image description here

相关问题