Allow trailing comma for "JSON with Comments" file type
See original GitHub issueBackground Certain config files, including VSCode’s config files, support a relaxed JSON syntax where:
- comments are allowed
- trailing commas are allowed
- keys must still be quoted, just like in real JSON
(VSCode calls this syntax “JSON with Comments”.)
Example of issue
I’m trying to have prettier-vscode
format my VSCode settings.json
and keybindings.json
files. Sometimes these files are automatically modified by VSCode (for example, when changing UI zoom).
Sometimes these files are modified directly by me.
When VSCode automatically modifies these files, it applies trailing commas, so I’d like have Prettier do the same. But this doesn’t seem possible: There is no way to force vscode-prettier
to respect my trailingComma
setting because #143 force-turns it off when the Prettier parser is json
. I can edit prettierrc
to change the parser to babylon
or flow
, but then Prettier will unquote keys, resulting in an invalid config.
Potential solutions
- Add an exception to the #143 when the syntax is “JSON with Comments”, essentially narrowing the cases under which #143 to a more accurate set.
- Escalate this issue to Prettier – propose that prettier supports two different JSON parsers, one which is strict and one which is the relaxed style. They can still use the same parser implementation – the only difference being that when using the strict JSON parser, trailing commas will always be removed. Then #143, which is sort of a hack, probably won’t be needed either.
I’m happy to PR a fix for this, please just let me either of the above solutions seems like a good idea. (Implementation tips would be appreciated too.)
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
This should be done in prettier/prettier. Closing
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.