Skip to content

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

@anthonyshew

Description

@anthonyshew

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions