【问题标题】:vscode json formatter: do not wrap json objectsvscode json格式化程序:不包装json对象
【发布时间】:2020-12-04 19:45:11
【问题描述】:

我现在正在使用 avro .avsc 模式,我喜欢在示例中进行格式化:

{
 "namespace": "example.avro",
 "type": "record",
 "name": "User",
 "fields": [
     {"name": "name", "type": "string"},
     {"name": "favorite_number",  "type": ["int", "null"]},
     {"name": "favorite_color", "type": ["string", "null"]}
 ]
}

我的意思是单行字段定义{"name": "name", "type": "string"}

我想在 vscode 中编辑和格式化我的架构,但它一直在包装字段,例如

 {
   "name": "name",
   "type": "string"
 }

我尝试配置默认 json 格式化程序并在 setting.json 中使用 beautify 扩展名,但没有成功

   "[json]": {
        "editor.tabSize": 2,
        "editor.wordWrap": "off",
        "editor.defaultFormatter": "vscode.json-language-features",
        // "editor.defaultFormatter": "HookyQR.beautify"
    },
    "html.format.wrapAttributes": "preserve",

    "beautify.config": {
        "indent_size": 2,
        "indent_char": " ",
        "preserve_newlines": true,
        "space_in_paren": true,
        "space_in_empty_paren": true,
        "wrap_attributes": "preserve", 
    },

【问题讨论】:

    标签: json visual-studio-code formatting avsc


    【解决方案1】:

    FracturedJson VSCode extension 可能对您有用。 (我是作者。它是在 MIT 许可下开源的。)

    基本思想是对象和数组写在单行上,只要它们不太长且嵌套不太深。

    如果您想在下载扩展程序之前试用这些功能,可以使用 browser version

    【讨论】:

    • 啊,开枪。我希望这个可能是“适合我的”,但看起来它不能处理 cmets。 : (
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-14
    • 2019-03-25
    • 1970-01-01
    • 2017-06-26
    • 2015-06-11
    相关资源
    最近更新 更多