VS Code extension for keeping your TypeScript code organized by grouping and ordering class members.
TypeScript Code Organizer is a VS Code extension for organizing TypeScript source code in a project workspace. It allows software developers to organize import statements, modules, classes, interfaces and type members and helps them keep their source code more consistent and easier to navigate. It is highly configurable and allows sharing of the configuration across the development team. Everything from import statements, regions, grouping to sorting can be configured! It also comes as a command line tool, see TypeScript Code Organizer Command Line Interface.
Organize currently opened TypeScript file or all TypeScript files in your project.
From the command palette you can:
- create default configuration file by invoking command
TypeScript Code Organizer: Create Configuration File
, - organize current TypeScript file by invoking command
TypeScript Code Organizer: Organize Current File
, - organize all TypeScript files in the project by invoking command
TypeScript Code Organizer: Organize All Files
You can invoke command TypeScript Code Organizer: Organize Current File
by using the shortcut Ctr + Shift + O
. You can change the shortcut by assigning a different shortcut to command "tsco.organize". The shortcut Ctr + Shift + O
only works if the opened file is a TypeScript file.
You can invoke command TypeScript Code Organizer: Organize Current File
by using the context menu item.
Extensions supports the following configuration options:
tsco.organizeOnSave
: Organizes TypeScripot code on save (set to false by default).tsco.configurationFilePath
: Specifies the file path to the TSCO configuraiton file. Can be absolute or relative to the workspace root.
Code organization is configured by a tsco.json
configuration file. To create a default TypeScript Code Organizer configuration file, invoke the following command:
This will create a tsco.json
file at the workspace root directory. For configuration reference, see TypeScript Code Organizer Configuration Reference. The configuration file should be commited to the repository and shared with team members to ensure consistent code organization configuration. If you would like to specify an alternative location for the configuration file, you con do it using tsco.configurationFilePath
setting. If no configuration file is found, TSCO will look in the parent directory until tsco.json
or the root of file system is found. If tsco.json
is not found, the default configuration will be used.
In order to prevent a TypeScript file being organized you can add the file to the exclude list in the configuration file files section or add one of the following comments to the top of the TypeScript file:
// tsco:ignore
or
// <auto-generated />
If you have issues with TSCO, like not using the correct configuration file, you can use tye output window to investigate issues:
See TypeScript Code Organizer Command Line Interface on NPM.
See TypeScript Code Organizer Command Line Interface on NPM.
- Initial release.
- added add public modifier if missing option
- added add region Indentation option
- added end region caption option
- added organizing type aliases, interfaces, classes and functions
- fixed issue with Indentation tabs / spaces
- fixed issue when comments were preceding class members
- fixed issue when decorators were preceding class members
- fixed issue with removing redundant empty lines
- updated referenced packages
- added group properties with decorators option
- fixed issue with duplicated regions
- addded grouping by decorator for all elements, not just properties when grouping by decorators
- added a new line between group with decorators and group without decorators when grouping by decorators
- removed limitation where extension can be activated only when not in debug mode
- fixed bug where redundant empty lines were not removed correctly
- fix bug where public access modifier was not added to methods
- added option of adding number of members within a region (courtesy of pillont)
- added option to output accessors before constructor (courtesy of pillont)
- add option to customize grouping and ordering of members
- fix bug where accessors (getters and setters) got removed when organizing a class
- added option to treat arrow function properties as methods (courtesy of testpossessed)
- fix bug where assync methods were not assigned a public access modifier correctly
- added option organize file on save
- fixed issue where static members without an access modifier were not correctly decorated with the public access modifier
- fixed issue where a redundant empty line was added when organising arrow type method properties
- fixed issue where default access modifier is not correctly set
- fixed issue where invalid member names are used
- trigger organizing members only if manually saving the file and not if autosave is on in VS Code (courtesy of Donny Verduijn)
- add support for private identifiers for properties and methods
- fix issue where intefaces lost getters/setters when organizing
- add support for a special member list to be put at the top or bottom of a member group
- update README
- add support for organizing accessors
- add support for organizing static block declarations
- add support for organizing functions outside of classes
- add support for ignoring files
- fix TS reference error
- fix accessor issue when decorator contains a parameter with the name of the field
- add organizing document on saving in any mode (not just manual saving) (courtesy of Christopher Robinson)
-
configuration is no longer compatible with 1.x.x as version 2.x.x uses a configuration file
-
merged functionality with TypeScript Class Organizer CLI
- added support for configuration files
- added support for organizing import statements
- added ability to include/exclude files
- added support for organizing modules, interfaces and type aliases
- added more fine-grained support for treating arrow function variables and constants
- added more fine-grained configuration for module organization
- added more fine-grained configuration for interface organization
- added more fine-grained configuration for type alias organization
-
added ability to create a default configuration file
-
added support for regular expressions and globs when putting members above or below the member type group
-
added support for sorting member type groups asc, desc or no sorting
- added debugging output
- added saving changes on organizing
- added configuration file path setting
- fix issue with missing typescript dependency
- fix module formatting issue
- fix issue with import statements with comments
- fix issue with sorting members with dependencies
- fix organizing imports with type aliases