Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Clean Imports on SaveNew to Visual Studio Code? Get it now.
Clean Imports on Save

Clean Imports on Save

Marios Papamarkou

|
2,734 installs
| (1) | Free
Clean unused imports when file (.ts, .tsx, .js, .jsx) is saved without changing the order
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Clean Imports

Description

VS Code extension to clean the imports of JavaScript and TypeScript files (.js, .jsx, .ts and .tsx). The main difference with the "Organize Imports" of VS Code is that it doesn't re-sort the imports or adds spaces before and after the curly braces. Also, all file formatting (whitespace, indentation etc) remains untouched.
The extension is triggered by default on saving (configurable in the extension settings) or by the Command Palette (a keybinding can be assigned there with the cog icon).
The extension will also format all open editors with pending changes when "Save All" is triggered from VS Code (look in Limitations for more details on this).

Clean Imports

How to Use

The extension will be triggered when saving a file with one of the file extension mentioned in the description. This can be toggled in the settings:

Settings Screenshot

or in the settings.json:

Settings Screenshot

The command can also be separately triggered from the Command Palette. The command ignores the setting to trigger the extension on save:

Settings Screenshot

Limitations

  • When activating "Save All" with VS Code only editors in a dirty state are saved, not the currently open editor (if not dirty). This means if an editor with unused imports is open with no pending changes then the extension will not be triggered
  • Saving an editor directly on the other hand always triggers the save event on the open editor so the extension will be triggered (if enabled)
  • The extension keeps tracked of the "visited" editors (since there's no way currently to get them from the api). This means that if some files are open with pending changed, VS Code is closed and re-opened and "Save All" is triggered then these files will not be formatted

License

This project is licensed under the MIT License.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft