keithamus / sort-package-json

Sort an Object or package.json based on the well-known package.json keys
MIT License
790 stars 83 forks source link

Option to allow don't sort sub-keys #317

Closed hyoban closed 5 months ago

hyoban commented 5 months ago

In eslint-plugin-package-json, we use sort-package-json to auto-fix order-properties rule. However, sort-package-json also sort sub-keys too. This resulted in an issue https://github.com/JoshuaKGoldberg/eslint-plugin-package-json/issues/80.

Would you like to have an option to allow don't sort sub-keys? I am willing to submit a pull request for this change.

keithamus commented 5 months ago

Please see the readme for an explanation (https://github.com/keithamus/sort-package-json?tab=readme-ov-file#i-would-like-this-tool-to-be-configurable-with-a-config-file-or-command-line-arguments):

I would like this tool to be configurable with a config file or command line arguments.

The lack of configuration here is a feature, not a bug. The intent of this tool is that a user can open a package json and always expect to see keys in a particular order. If we add a configuration for this tool, then that promise is broken, as users will first need to look at the configuration for each project to learn the ways in which this tool will change the package.json. The structure of the package.json should always be predictable & deterministic from project to project. I think the reason why this project is well used is because it is not another "tool" you have to set up with yet another JSON file and more cruft in your project to support it. You run a command and it does what it says on the tin.

A lot of people who ask for configuration cite the use case that they simply don't like the given order that exists and want to make sweeping changes. To me this seems far better suited to simply making a fork of this project as then you can go far further than specifying configuration.

hyoban commented 5 months ago

Thanks for your reply, and sorry for my noise issue. I will provide this option from my side.