Skip to content

Prettier should *not* format JSONC with trailing commas #15956

@slifty

Description

@slifty

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.jsonc

Output:

{
  "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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions