The import organizer extension will help you organize your file imports inside a JS/TS project. This extension does not use the built-in vs-code organizer as it relies on a configuration file allowing a more granular control over the result. You will be able to specify the order of your imports and the grouping of your imports. The extension will also allow you to specify a special identifier for absolute imports.
Furthermore the extension will allow you to organize all your imports in a file, in a directory and even within the entire project with a single command. You can right-click on a file or a directory and select the organize imports command you want to execute. It is also possible to launch the command from the command palette.
Requirements
The extension needs a configuration file to work properly. The .sorterconfig.json file will contain the configuration for the extension. It needs to be at the root of your project or in a .vscode folder. The configuration file isn't required for the extension to work since it will use the default configuration if no configuration file is found. However, it is recommended to use a configuration file to have a more granular control over the result.
Config file
Parameter
Type
Description
root
string
Required. Path for the source folder. Files that are not included here will be ignored
organizeOnSave
string
Organize import on document save. Defaults to false
showErrorMessages
boolean
Show error messages. Defaults to true
applySpecialIdentifier?
boolean
Replace absolute imports with specialIdentifier. Defaults to false
specialIdentifier?
string
String used for absolute imports. Defaults to @
replaceLongPathBySpecialIdentifier?
boolean
Replace long paths by specialIdentifier. Defaults to false
longPathLength?
number
Length of the path to replace by the special identifier. Defaults to 3
separatorCharacter?
string
Character used to separate imports. Defaults to ,
separatorLineLength?
number
Length of the separator line. Defaults to 100
addSeparatorLineAfterImports?
boolean
Add a separator line after imports. Defaults to false
breakLineAfterBlock?
boolean
Should add a new line after each block. Defaults to false
includedFolders?
string[]
Folders included when using the 'Organize imports of all files'
excludedFolders?
string[]
Folders excluded when using the 'Organize imports of all files'
allowedExtensions?
string[]
Allowed extensions
addLibrariesToOthers?
boolean
Should add unspecified libraries in the other block. Defaults to true
othersBlockName?
string
String used for naming the "others" block. Defaults to "others"
blocks
Block[]
Required Specifies the groups
Block
Parameter
Type
Description
name
string
Required. Name of the block. Will be inserted as a comment before any import block
displayName?
boolean
Wether the name should be displayed or not block. Defaults to
libraries?
string[]
Any imports related to one of the specified libraries will be added to the block
folders?
string[]
Folder or file path relative to the specified root inside the config. Any import from a subdir of this path will be added to the block
Known Issues
The extension is still in development and there are some known issues. If you find a bug, please add it to the bug list.