【问题标题】:How do you stop prettier or beautify breaking JS objects onto multiple lines?你如何停止更漂亮或美化将 JS 对象分成多行?
【发布时间】:2022-01-17 15:08:50
【问题描述】:

我需要这个:

    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 代码 settings.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
}

我在这里尝试了解决方案:Prevent Prettier from converting single line object declarations into multi line in Visual Studio Code?。什么都没有

这与解决方案无关,因为 HTML 工作正常:How do you stop Prettier in VS code splitting attributes onto multiple lines?

我玩过 printWidth,将其设置为 1000。没有。 我检查过没有安装和运行其他格式化程序。还是什么都没有。

不知道为什么它不会将较小的对象压缩到一条线上。

【问题讨论】:

    标签: javascript json formatting vscode-settings prettier


    【解决方案1】:

    这可能是因为您的printWidth 值非常大("printWidth": 300)

    printWidth 指定打印机将换行的行长。尝试将值减小为 "printWidth": 160 之类的值(默认值实际上是 80)

    您可以在更漂亮的文档选项page 中阅读更多相关信息

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 2021-05-10
      • 2019-06-18
      • 2021-05-13
      • 1970-01-01
      • 2021-02-01
      • 2020-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多