Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support .prettierrc.jsonc #16287

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

rotu
Copy link
Contributor

@rotu rotu commented May 13, 2024

Description

Support .prettierrc.jsonc as a config file.

Checklist

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

Try the playground for this PR

@rotu rotu marked this pull request as draft May 13, 2024 19:16
@rotu rotu marked this pull request as ready for review May 13, 2024 19:49
@fisker
Copy link
Member

fisker commented May 28, 2024

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

@rotu
Copy link
Contributor Author

rotu commented May 28, 2024

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: #15956

@fisker
Copy link
Member

fisker commented May 28, 2024

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

@rotu
Copy link
Contributor Author

rotu commented May 28, 2024

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

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

@fisker
Copy link
Member

fisker commented May 28, 2024

We should NOT load invalid config file.

@rotu
Copy link
Contributor Author

rotu commented May 28, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants