You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code保存JSON时自动拆分逗号分隔参数,求禁用该行为的设置

Fixing VS Code's Automatic Array Line Splitting in settings.json on Save

It sounds like the issue boils down to how your JSON formatter is configured to handle array formatting. Here’s how to track down the exact setting and fix it without disabling format-on-save:

Step 1: Identify the Active JSON Formatter

First, confirm which formatter is handling your JSON files on the problematic machine:

  • Open settings.json in VS Code.
  • Look at the bottom-right corner of the window—you’ll see "JSON" (or "JSON with Comments") displayed.
  • Click that label, then select Configure Default Formatter from the dropdown. Note whether it’s the built-in vscode.json-language-features or an extension like esbenp.prettier-vscode.

Step 2: Adjust Settings Based on the Formatter

If Using the Built-in JSON Formatter

The key setting controlling array line breaks is:

"json.format.arraysOnSingleLine": true

When set to true, this forces arrays to stay on a single line whenever possible, preventing unnecessary splitting on save.

You might also want to check two related settings:

  • editor.wordWrapColumn: If this value is set lower on your problematic machine, it could trigger line wrapping even for shorter arrays (the default is 80).
  • json.format.wrapLines: If set to false, it disables all line wrapping, but arraysOnSingleLine is more targeted for your specific issue.

If Using Prettier

Prettier splits arrays into multiple lines when they exceed the configured print width. To fix this:

  • Increase the printWidth setting to a higher value (e.g., 120) to give arrays more room to stay on one line:
    "prettier.printWidth": 120
    
  • If you want to force arrays to stay single-line regardless of length, you can use the prettier.bracketSameLine setting (though primarily for object literals, it helps with consistent array formatting):
    "prettier.bracketSameLine": true
    

Step 3: Verify the Fix

After adjusting the relevant setting, save settings.json and test by modifying an array (like your args array). It should now stay on a single line when format-on-save runs.

Since copying the working machine’s settings resolved the issue, the problematic machine likely had either json.format.arraysOnSingleLine set to false (for the built-in formatter) or a lower prettier.printWidth (for Prettier) compared to the working machine.

内容的提问来源于stack exchange,提问作者Paul Waldo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:43:53