簡體   English   中英

是否有更漂亮的配置來保持換行符?

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

在 VS Code 中使用更漂亮的擴展有問題,當我寫這個時:

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

有沒有辦法避免這種情況發生?

謝謝!

如果您打開 VSC 並進入設置,然后進入擴展並單擊“更漂亮”,那么在更漂亮的下方會勾選一個復選框:“需要配置”。 如果未選中它會自動斷行在此處輸入圖片說明

根據this Github issue並查看文檔,似乎無法將其配置為保持換行符。

但是,您可以設置一個非常短的printWidth或在代碼上方放置// prettier-ignore printWidth // prettier-ignore注釋。

請嘗試將 .prettierrc 文件添加到您的代碼中,並在文件的對象中添加一行。

"printWidth": 100

參考截圖: 在此處輸入圖片說明

沒有找到配置。 作為黑客,您可能希望在要中斷的第一行中包含注釋:

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