Sort Code Plugin
A VS Code extension that sorts TypeScript and JavaScript code elements alphabetically with intelligent grouping and class member ordering.
Features
- Comprehensive Code Sorting: Sorts functions, variables, classes, interfaces, enums, and exports
- Class Member Ordering: Follows priority-based sorting within classes:
- Constructor first
- Public static methods
- Public methods
- Private static methods
- Private methods
- All sorted alphabetically within each priority group
- Smart Export Handling:
export default statements are always placed last
- Multi-line Statement Support: Properly handles multi-line const declarations and complex statements
- Comment Preservation: Maintains all comments and formatting
- Function Type Detection: Supports all function types:
- Regular function declarations:
function name() {}
- Arrow functions:
const name = () => {}
- Function expressions:
const name = function() {}
- Async functions:
async function name() {}
- Class methods with visibility modifiers
- File Type Support: Works with
.ts , .js , .tsx , .jsx , .mjs , .cjs , .mts , .cts files
Usage
Commands
- Sort Functions in Current File: Sort all code elements in the current file
Keyboard Shortcuts
Ctrl+M Ctrl+Z (Windows/Linux) or Cmd+M Cmd+Z (Mac): Sort code in current file
How to Use
- Open a TypeScript or JavaScript file
- Use the command palette (
Ctrl+Shift+P ) and search for "Sort Functions"
- Or right-click in the editor and select "Sort Functions in Current File"
- Or use the keyboard shortcut
Ctrl+M Ctrl+Z (chord: press Ctrl+M, then Ctrl+Z)
Sorting Logic
Top-Level Elements
Elements are grouped and sorted in this order:
- Import statements
- Variables and constants
- Interfaces
- Enums
- Classes
- Export statements
- Export default statements (always last)
Class Members
Within classes, members are sorted using priorities:
- Constructor - Always first
- Public static methods - Sorted alphabetically
- Public methods - Sorted alphabetically
- Private static methods - Sorted alphabetically
- Private methods - Sorted alphabetically
Requirements
Extension Settings
This extension does not contribute any settings currently.
Release Notes
1.0.0
Initial release featuring:
- Comprehensive code sorting for TypeScript and JavaScript
- class member ordering
- Support for all function types and file extensions
- Smart export default handling
- Multi-line statement support
Development
To develop this extension:
- Clone the repository
- Run
npm install to install dependencies
- Press
F5 to open a new Extension Development Host window
- Test the extension in the new window
License
MIT
| |