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

fix-mismatches results in formatting changes in package.json #241

Closed
anthonyshew opened this issue Aug 25, 2024 · 2 comments
Closed

fix-mismatches results in formatting changes in package.json #241

anthonyshew opened this issue Aug 25, 2024 · 2 comments

Comments

@anthonyshew
Copy link

Description

We started using Biome for our formatter, and noticed that it formats our package.json files slightly differently than prettier-plugin-packagejson. Technically, Biome is more correct, but it is indeed different.

Because fix-mismatches output agrees with Prettier (not Biome), it creates a large diff for all of our package.json files in our monorepo, even when there are no mismatches to fix. While this isn't a showstopper, it's slightly inconvenient, making diffs hard to read when there really is a mismatch to fix.

Suggested Solution

I'm not sure of the current implementation that's causing this but I'd figure it has to do with JSON.parse somewhere in the path. I've seen this produce reformatting before in other tools.

An AST-based approach with something like jsonc-parser could help here, allowing edits to specific nodes of the AST so that formatting for other parts of the file can be preserved. If my memory serves me correctly, jsonc-parser is slower than JSON.parse due to its higher specificity, but I would hope those performance impacts are negligible given what we can reasonably expect for the sizes of users' package.jsons.

Help Needed

I'm aware there's a Rust rewrite going on but I'm not sure of the status of it, nor if a fix on the current implementation would be welcome with the rewrite ongoing.

@JamieMason
Copy link
Owner

Much better, thanks! Released in 13.0.0

@anthonyshew
Copy link
Author

Wow! Thanks a ton!

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

No branches or pull requests

2 participants