Allow JSON with trailing commas
See original GitHub issueI’m looking for a way to support the following style:
- JSON-based
- Always quote keys
- Always include trailing commas
This would typically be not a problem – I should be able to set parser: json
and trailingComma: all
. However, #2308* disables this specific combination and I can’t get around it.
Here’s my use case: I want Prettier to format my VSCode settings files, which I keep in a git repo.
- VSCode requires keys to be quoted, so I can’t use the json5 parser.
- I would like trailing commas to make diffs more readable.
Note: I originally filed this bug in another repo https://github.com/prettier/prettier-vscode/issues/589
* I am aware that #2308 was created because trailing commas broke VSCode. However, times have changed and VSCode settings files now support trailing commas.
Thanks!
Prettier 1.15.3 Playground link
--parser json
--trailing-comma all
Input:
{
//
"a": 1,
"b": 2,
}
Output:
{
//
"a": 1,
"b": 2
}
Expected behavior: I’d like a set of input options that doesn’t make changes to the input; i.e., I want the output to also be
{
//
"a": 1,
"b": 2,
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:15
- Comments:24 (7 by maintainers)
.prettierrc
😃
Personally, I think
jsonc
(the language named JSON with Comments in VSCode, which is also used by TypeScripttsconfig.json
) is better than JSON5 since it only adds missing features that are necessary so it’s relatively simple.I was thinking of adding a
--parser jsonc
to address this issue, but then I found that its name (JSON with Comments) is very confusing since it looks likeJSON + comments
but it’s actuallyJSON + comments + trailing commas
while our--parser json
already handlesJSON + comments
, so thejsonc
description may look something like “JSON with Comments: same parser asjson
, but trailing commas are allowed”, which is super confusing.