[json] option to format code with leading commas
See original GitHub issueCan we get an option in VS Code to have it format all lists by using leading commas instead of trailing commas?
This would so much simplify editing code and it would also greatly simplify the IDE’s automatic code completion (e.g. the VS Code Settings editor).
With the suggested option set to true
, comma separated lists would proposedly be formatted like this:
{ "workbench.iconTheme": "vs-seti"
, "editor.lineNumbers": "off"
, "editor.tabSize": 2
, "editor.insertSpaces": false
, "editor.autoClosingBrackets": false
}
Function calls using line wrapping for their arguments would look like this:
call( 1
, "test"
, new Console()
);
a nested sample would look like this:
{ "version": "0.2.0"
, "configurations":
[ { "type": "node"
, "request": "launch"
, "name": "Programm starten"
, "program": "${file}"
}
, { "type": "node"
, "request": "attach"
, "name": "An den Port anfügen"
, "address": "localhost"
, "port": 5858
}
]
}
This formatting style would result in much cleaner, tidier code.
Moreover, adding a new property to an object would be a snap:
Either copy/paste from an existing property (=> no more syntax errors due to redundant trailing commas, see screenshot below):
… or create a new property and you might immediately get IntelliSense right after typing the leading comma of the property to create.
The suggested formatting style is applicable to all languages
E.g. T-SQL:
CREATE TABLE
( id INT PRIMARY KEY IDENTITY
, name NVARCHAR(100) NOT NULL UNIQUE CHECK(LEN(name) > 0)
, created DATETIME NOT NULL DEFAULT(GETDATE())
, updated DATETIME NOT NULL DEFAULT(GETDATE())
)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:24
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Can you use a trailing comma in a JSON object?
With Relaxed JSON, you can have trailing commas, or just leave the commas out. They are optional.
Read more >Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >JsonSerializerOptions.AllowTrailingCommas Property
By default, AllowTrailingCommas is set to false , and a JsonException is thrown during deserialization if a trailing comma is encountered.
Read more >Leading with commas — ugly or efficient? An investigation ...
Here I analyze 320 GB of SQL code from 80,000 GitHub repositories to support this choice. Background. Many programming languages (C, Python, ...
Read more >Code Syntax Style: Trailing Commas - ReSharper - JetBrains
Configure preferences for trailing commas · Go to the Code Editing | C# | Syntax Style page of ReSharper options ( Alt+R, O...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
They always did. Same as they always supported leading commas. There is no rule on where to put punctuation characters.
Actually, once you started using leading commas you will immediately recognize the benefit of using it, and you will never want to revert to struggle with the clumsiness of trailing commas.
Why do people still use this leading-commas formatting? objects, arrays, functions allow trailing commas (even json5 does) now, it’s significantly more readable