autoimport icon indicating copy to clipboard operation
autoimport copied to clipboard

Option to disable "move-to-top" feature

Open hydrargyrum opened this issue 2 years ago • 1 comments

Description

I work on a project which has many function-local imports because top imports would cause import cycles. But I can't use autoimport because it insists on moving them to the top (and also produces invalid syntax in this case, but that's another story).

Possible Solution

Make "move-import-to-top" feature optional, so it can be disabled, and still keep the "remove-unused-imports" feature.

hydrargyrum avatar Oct 03 '23 09:10 hydrargyrum

Hi @hydrargyrum thanks for taking the time to open an issue. Have you tried reordering your code so that you don't run into import cycles? It's often suggested that imports are left on top of the file both for cleanness and performance, so that's why we move them to the top. It's also because you can write imports as you develop code wherever you are so that when you run autoimport they are moved to the top.

However, I feel you that there are some cases where it would be nice to disable this feature. I'm personally no big fan of it as I think a refactor is a better solution, but if you want to make a PR that implements this and it doesn't add too much complexity I'm fine with merging it.

lyz-code avatar Oct 03 '23 14:10 lyz-code

I've added a PR to address this here. Note that the tests are currently failing due to an unrelated security vulnerability detected by the security tool. I have not had time to get autoimport's development environment up and running locally, so I could use help remediating that vulnerability. Probably a version bump is needed, but I'm out of time on this for now.

wbbradley avatar Jul 09 '24 23:07 wbbradley

Available since 1.6.0 thanks to @wbbradley

lyz-code avatar Jul 11 '24 17:07 lyz-code