Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort dependencies #2

Open
will-stone opened this issue Sep 18, 2019 · 4 comments
Open

Sort dependencies #2

will-stone opened this issue Sep 18, 2019 · 4 comments

Comments

@will-stone
Copy link
Contributor

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.

@shellscape
Copy link
Owner

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

@will-stone
Copy link
Contributor Author

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 will-stone mentioned this issue Oct 3, 2019
8 tasks
@ntwb
Copy link

ntwb commented Dec 16, 2019

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

@JounQin
Copy link

JounQin commented Apr 16, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants