簡體   English   中英

你如何停止更漂亮或美化將 JS 對象分成多行?

[英]How do you stop prettier or beautify breaking JS objects onto multiple lines?

我需要這個:

    var short_sleeve = {
        type: "Short Sleeve",
        id: this.item.epos_code,
    };

看起來像這樣:

var short_sleeve = { type: "Short Sleeve", id: this.item.epos_code, };

這是我的 prettierrc.json:

{
    "bracketSpacing": false,
    "endOfLine": "auto",
    "printWidth": 300,
    "proseWrap": "never",
    "tabWidth": 4,
    "trailingComma": "all",
    "useTabs": true
}

這是我的 vs 代碼設置。json

{
    "prettier.singleQuote": true,
    "prettier.tabWidth": 4,
    "editor.defaultFormatter": "esbenp.prettier-vscode",
    "prettier.printWidth": 300,
    "editor.formatOnSave": true,
    "files.trimTrailingWhitespace": true,
    "diffEditor.ignoreTrimWhitespace": false,
    "prettier.proseWrap": "never",
    "materialTheme.accent": "Acid Lime",
    "twig-language.wrap": 100
}

我在這里嘗試過解決方案: Prettier from convert single line object declarations into multi line in Visual Studio Code? . 沒有什么

這與解決方案無關,因為 HTML 工作正常: 如何在 VS 代碼拆分屬性中停止 Prettier 到多行?

我玩過 printWidth,將其設置為 1000。沒什么。 我檢查過沒有安裝和運行其他格式化程序。 依然沒有。

不知道為什么它不會將較小的對象壓縮到一條線上。

這可能是因為您的printWidth值非常大( "printWidth": 300

printWidth指定打印機將換行的行長。 嘗試將值減小到類似"printWidth": 160的值(默認值實際上是 80)

您可以在更漂亮的文檔選項頁面上閱讀更多相關信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM