prettier-plugin-package icon indicating copy to clipboard operation
prettier-plugin-package copied to clipboard

Sort dependencies

Open will-stone opened this issue 6 years ago • 4 comments

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.

will-stone avatar Sep 18 '19 08:09 will-stone

👋 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?

shellscape avatar Sep 18 '19 22:09 shellscape

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.

will-stone avatar Sep 19 '19 07:09 will-stone

It might also be possible to use https://github.com/tclindner/npm-package-json-lint API for some this, author format, sorting etc

ntwb avatar Dec 16 '19 22:12 ntwb

This should have been implemented since https://github.com/shellscape/prettier-plugin-package/blob/master/lib/rules/dependencies.js.

JounQin avatar Apr 16 '21 01:04 JounQin