IssueRaiser

Prettier should *not* format JSONC with trailing commas

*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:** ```sh echo '{\n"a": "b"\n}' > myfile.jsonc npx prettier@3.2.4 myfile.jsonc --write cat myfile.jsonc ``` **Output:** ```jsx { "a": "b", } ``` **Expected output:** ```jsx { "a": "b" } ``` **Why?** A `jsonc` parser was recently added to prettier (🎉), but the [original issue that prompted the addition](https://github.com/prettier/prettier/issues/15553) 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](https://code.visualstudio.com/docs/languages/json#_json-with-comments). In addition to discouraging via documentation, VSCode [issues a warning for jsonc files with trailing commas](https://github.com/microsoft/vscode/issues/102061) 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`)

Posted by slifty on Jan 18, 2024, 3:22 AM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.2,000 issues0 comments

support (Software)

Prettier should *not* format JSONC with trailing commas

sliftyJan 18, 2024, 3:22 AM

*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:** ```sh echo '{\n"a": "b"\n}' > myfile.jsonc npx prettier@3.2.4 myfile.jsonc --write cat myfile.jsonc ``` **Output:** ```jsx { "a": "b", } ``` **Expected output:** ```jsx { "a": "b" } ``` **Why?** A `jsonc` parser was recently added to prettier (🎉), but the [original issue that prompted the addition](https://github.com/prettier/prettier/issues/15553) 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](https://code.visualstudio.com/docs/languages/json#_json-with-comments). In addition to discouraging via documentation, VSCode [issues a warning for jsonc files with trailing commas](https://github.com/microsoft/vscode/issues/102061) 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`)

Comments (0)

No comments yet. Start the discussion.

Comment on this issue