IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
963 stars 21 forks source link

Feature: Prettier Plugin Collision Resolution #27

Open fbartho opened 2 years ago

fbartho commented 2 years ago

Is your feature request related to a problem? Prettier Plug-ins can collide with each-other: https://github.com/tailwindlabs/prettier-plugin-tailwindcss/issues/31

Describe the solution you'd like It’d be smart to have a documented procedure for working around this. It could even include code-changes if necessary.

Describe alternatives you've considered

I don’t think this is a breaking blocker-issue (shouldn’t be in the milestone for #22), but it’d be smart to have a plan

vincerubinetti commented 1 year ago

Related discussion:

https://github.com/hosseinmd/prettier-plugin-jsdoc/discussions/200

It seems like plugin-jsdoc is taking into account other plugins and trying to preserve their modifications, whereas plugin-sort-imports is not, because I have to put jsdoc after sort-imports or else sort-imports overwrites jsdoc's work. Maybe you can look at how they did the preserving?

I don't know anything about the prettier or prettier plugin architecture, so I don't know how hard this would be. Seems like maybe prettier could've designed their APIs a bit better to more gracefully identify and handle collisions...

IanVS commented 2 months ago

I made an attempt to solve this in https://github.com/IanVS/prettier-plugin-sort-imports/pull/175, but if we use the same approach as prettier-plugin-jsdoc, we end up in an infinite loop because each tries to run the other over and over. The tailwindcss plugin does things a bit differently, using an allowlist of compatible plugins, but I'm also not certain that wouldn't result in an infinite loop if we did the same.

So I'm not sure there's all that much we can do right now other than hope that Prettier creates a better api for plugins to operate in a pipeline.

But, if you're having problems with a specific prettier plugin, let us know which one it is here and maybe we can try something else later on like an allowlist.