VS Code保存JSON时自动拆分逗号分隔参数,求禁用该行为的设置
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.jsonin 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-featuresor an extension likeesbenp.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 tofalse, it disables all line wrapping, butarraysOnSingleLineis 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
printWidthsetting 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.bracketSameLinesetting (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

