matzkoh / prettier-plugin-packagejson

Prettier plugin for package.json
MIT License
316 stars 10 forks source link

Bug: Sorting priority of hyphens and underscores is wrong #183

Closed Zamiell closed 1 month ago

Zamiell commented 1 month ago

Hello, and thanks for the excellent plugin!

Today, I discovered that this plugin uses a different sorting priority of hyphens and underscores than what npm uses, which was unexpected for me.

Steps to reproduce:

mkdir test
cd test
npm init --yes
npm install --save-dev prettier prettier-plugin-packagejson @types/eslint-config-prettier @types/eslint__js
cat package.json
# Notice that "@types/eslint__js" comes before "@types/eslint-config-prettier".
npx prettier package.json --plugin prettier-plugin-packagejson --write
cat package.json
# Notice that "@types/eslint-config-prettier" comes before "@types/eslint__js".

This mismatch is particularly painful because whenever I install a new dependency with npm (e.g. npm install --save-dev foo), it automatically breaks CI, because now Prettier fails to pass the package.json file, which then requires someone to explicitly go and format the package.json file again.

Can we fix this so that this plugin and npm have parity?

Zamiell commented 1 month ago

Nevermind, this seems to be a duplicate of https://github.com/keithamus/sort-package-json/issues/234. Sorry for the noise.