prettier icon indicating copy to clipboard operation
prettier copied to clipboard

feat: support `.prettierrc.jsonc`

Open rotu opened this issue 1 year ago • 8 comments

Description

Fixes https://github.com/prettier/prettier/issues/16966

Support .prettierrc.jsonc as a config file.

Checklist

  • [x] I’ve added tests to confirm my change works.
  • [x] (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • [x] (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • [x] I’ve read the contributing guidelines.

Try the playground for this PR

rotu avatar May 13 '24 19:05 rotu

I think we already support enough formats. Anyway if we want support it, we need a different loader.

fisker avatar May 28 '24 15:05 fisker

Why would this require a different loader? json5 is a strict superset of jsonc. In fact, it might be nice to remove the json parser altogether, as prettier will fail to parse its own config file if it is mangled by adding trailing commas: https://github.com/prettier/prettier/issues/15956

rotu avatar May 28 '24 17:05 rotu

Because our jsonc parser won't able to format it.

fisker avatar May 28 '24 17:05 fisker

Because our jsonc parser won't able to format it.

Yes. I anticipated that. And it's why I'm using the .json5 loader.

rotu avatar May 28 '24 17:05 rotu

We should NOT load invalid config file.

fisker avatar May 28 '24 17:05 fisker

I think we already support enough formats.

Okay. Well, let's get back to this question because it supercedes the loader concern

Here's my original justification:

It's pretty common but unfortunate practice to name files .json when they are actually .jsonc. This is encouraged by:

  • VSCode with jsconfig.json, tsconfig.json, settings.json, etc.
  • eslint in .eslintrc.json
  • Deno with deno.json (fortunately deno.jsonc is also tolerated!)

It would be nice to allow "json with comments" as a format in common with these tools. Does that align with Prettier's goals? (If not, I'll close this PR outright)

If so, would it be sensible to tolerate comments in the prettierrc.json config file? To tolerate trailing commas?

rotu avatar May 28 '24 19:05 rotu