Automatically organize imports

tonyhicks20

Tony Hicks

Posted on October 12, 2021

Automatically organize imports

While refactoring your javascript/typescript code it's easy to remove things but forget to get rid of the unused imports.

Alt Text

In VSCode, you can easily remove these with the shortcut : Shift + Alt + O.
This is sometimes easy to forget to do though, and wouldn't it be better if there was some way to do this automatically every time you save?

In VSCode, go to File -> Preferences -> Settings and click on the icon in the top right hand corner to open up the settings in JSON.

Alt Text

Add the following json:

"editor.codeActionsOnSave": {
    "source.organizeImports": true
},
Enter fullscreen mode Exit fullscreen mode

So that it looks something like the following:
Alt Text

Et voilà!
Your imports will now be organized every time you save a file.
Enjoy :-)

💖 💪 🙅 🚩
tonyhicks20
Tony Hicks

Posted on October 12, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Automatically organize imports
vscode Automatically organize imports

October 12, 2021