feat: support `.prettierrc.jsonc`
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.mdfile followingchangelog_unreleased/TEMPLATE.md. - [x] I’ve read the contributing guidelines.
I think we already support enough formats. Anyway if we want support it, we need a different loader.
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
Because our jsonc parser won't able to format it.
Because our
jsoncparser won't able to format it.
Yes. I anticipated that. And it's why I'm using the .json5 loader.
We should NOT load invalid config file.
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(fortunatelydeno.jsoncis 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?