-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Environments
- Prettier Version: 3.2.4
- Running Prettier via: CLI
- Runtime: Node.js v20
- Operating System: macOS
- Prettier plugins (if any): none
Steps to reproduce:
echo '{\n"a": "b"\n}' > myfile.jsonc
npx [email protected] myfile.jsonc --write
cat myfile.jsoncOutput:
{
"a": "b",
}Expected output:
{
"a": "b"
}Why?
A jsonc parser was recently added to prettier (🎉), but the original issue that prompted the addition seems to suggest that jsonc is a defined standard with universal support for trailing commas. This does not appear to be the case, and Microsoft discourages the use of trailing commas in jsonc files.
In addition to discouraging via documentation, VSCode issues a warning for jsonc files with trailing commas unless the developer manually overrides the json schema for a given file.
Prettier's insertion of trailing commas goes against the recommendations of the entity that introduced / maintains the format. The VSCode warning in itself is a yellow flag, but the reasoning behind the warning suggests that tooling related to jsonc could break when trailing commas are utilized in the general case, even if certain specific instances support them (e.g. in the context of tsconfig)