Sort dependencies
Hi Andrew. Thanks for this plugin! I'm probably gonna add this to all of my projects' pipelines.
Feature Use Case
If a user manually enters a dependency into the package.json file, it will not be sorted alphabetically until a dependency is added using the yarn or npm CLI.
Feature Proposal
I propose [dev][peer]Dependencies are sorted alphabetically by this Prettier plugin.
👋 ahoy. really glad you enjoy it!
Most of the properties that are alphabetized were chosen because they're ones that frequently see manual editing and are most prone to getting out of sorts. dependencies and its cousins are an interesting case. I'd wager 99% of the time folks are using the CLI to add and remove deps, and those CLIs tend to be opinionated. (If you've got a specific use case for your environment where that isn't the case, I'd like to hear about it). So those aren't properties that I'd like to sort by default.
That said, I could see potential for an option which let users specify which additional properties to sort alphabetically. Perhaps something like:
{
sortAlpha: ['devDependencies', 'peerDependencies']
}
What are your thoughts?
Hmmm 🤔 Yes, I suppose you’d have to remain compatible with yarn/npm/etc. Having said that, this is the way I’m using your plugin, which includes using Husky to format before each commit, therefore it doesn’t matter what the package managers do with their sorting as this will overwrite it. So I would say this plugin can mimic Prettier’s philosophy and be as opinionated as possible; as long as it stays consistent.
It might also be possible to use https://github.com/tclindner/npm-package-json-lint API for some this, author format, sorting etc
This should have been implemented since https://github.com/shellscape/prettier-plugin-package/blob/master/lib/rules/dependencies.js.