-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
organizeImports without the reordering ("remove unused imports" being its own option) #43141
Comments
Another use is when you are using a code formatter such as prettier that sorts the imports (with an appropriate prettiert plugin) but doesn't have enough knowledge to find and remove unused imports. It would be great if the IDE would remove the unused imports, and prettier could format them. |
Hey @RyanCavanaugh do you still need more feedback for this? It seems like this would be an easy win, as you already implement both features, this is just asking you to separate them out. |
Another reason why these command should be separated is due to the fact that some projects like to use ESLint for organising imports but still want TypeScript to bring in imports which are being used. Sadly at the moment you can't do that without conflicting with ESLint. |
For anyone waiting for this, you can use this extension: https://marketplace.visualstudio.com/items?itemName=kuscamara.remove-unused-imports |
We have a code fix for removing all unused declarations that I think would be trivial to expose to |
Yes exposing that would be great @andrewbranch, it would be nice if VSCode offered this as an "on save" action via the extension, but just exposing it would be a win here |
I want the remove without organizing feature too... Ty for extension tip Milosz! |
Hey @andrewbranch did you ever get around to exposing this code fix? |
I think this slipped through the cracks, @jasonwilliams. Bringing it up with the VS Code team tomorrow. Looking back at my last comment, I’m not sure offering the remove-all-unused-stuff on save is a workable alternative after all, since that could delete entire local function and class declarations, which is probably not what anyone wants 😅 |
@jasonwilliams your original post showed an example code snippet with |
Yes I used to use that also but I can’t remember specifically what for. It may have been to remove imports I wasn’t using. |
Thanks so much for this @andrewbranch can't wait to try it |
Once microsoft/vscode#161654 lands you’ll be able to try it in nightly/Insiders. I’m working on exposing Sort Imports and Remove Unused Imports in the command palette as well. |
Wil remove unused imports map to VSCode’s “source.fixAll” option on save? And sort imports maps to “source.organizeImports” then I guess these will “just work” for people who have that set |
I haven’t made any changes to |
Suggestion
I was originally using the
organizeImports
in my"editor.codeActionsOnSave"
block on VSCode. The issue with this feature is it also does the sorting which we don't want.It's currently not possible to switch the sorting off without losing the "remove unused imports".
According to VSCode documentation "addMissingImports" is offered as an "on save" option, but not "removeUnusedImports".
⭐ Suggestion
As some projects already use tools which handle ordering it would be nice to just add/remove imports without changing the order.
Then have a separate command which handles ordering.
💻 Use Cases
My team are happy with the ordering of imports and don't want changes. However by keeping the ordering I lose the ability to remove unused imports.
Example
The text was updated successfully, but these errors were encountered: