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.
Description
We started using Biome for our formatter, and noticed that it formats our
package.jsonfiles slightly differently thanprettier-plugin-packagejson. Technically, Biome is more correct, but it is indeed different.Because
fix-mismatchesoutput agrees with Prettier (not Biome), it creates a large diff for all of ourpackage.jsonfiles 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.parsesomewhere in the path. I've seen this produce reformatting before in other tools.An AST-based approach with something like
jsonc-parsercould 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-parseris slower thanJSON.parsedue 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.