simonhaenisch/prettier-plugin-organize-imports

Oneline imports

btxtiger opened this issue · 3 comments

I don't know how deep plugins can modify the default prettier behavior. But would it be possible to add an option that makes the imports taking one line?
There are some workarounds like using the fork prettierx, but this is not optimal for many reasons. There is also this huge discussion about the topic, and currently it seems that won't be fixed by prettier itself.

To be clear what I am talking about: These multiline imports are just wasting space at the top of huge classes, and could be collapsed to one single line. Using code folding is also not a solution for this.

image

I guess I get your point and I'd love to add a feature for it, however sadly this plugin can't solve this because it's hooking into a preprocess hook of the plugin API (more accurately: wrapping the preprocess hook of a bunch of Prettier's built-in parsers), i.e. it runs before the code runs through the rest of Prettier (which applies the print width).

I was thinking maybe there's some VS Code (or other IDE) plugin to always collapse the import section, so I did a quick search and actually there's a VS Code setting for it: editor.foldingImportsByDefault (link). I will try this out now, thanks for the idea 😬

BTW there's potentially a way to monkey-patch the built-in parsers to ignore printWidth when inside an import statement, but imo it doesn't really fit into this plugin's scope (also I have no ambition to find out how to do it 😅). On the other hand, doing that as another plugin would probably be incompatible with this one.

Ok, thanks for checking