TidyJSThe ultimate TypeScript/JavaScript import organization VS Code extension TidyJS automatically transforms messy, disorganized imports into beautifully structured, aligned, and categorized import declarations. With advanced AST parsing, intelligent mixed import separation, and highly configurable grouping rules, TidyJS makes your codebase cleaner and more maintainable. ✨ Why TidyJS?The Problem: Modern TypeScript/React projects often have messy, inconsistent imports scattered throughout files, making code hard to read and maintain. The Solution: TidyJS intelligently organizes, groups, and formats all import declarations with pixel-perfect alignment and customizable rules - transforming chaos into clarity. 🚀 Key Features🧠 Smart Import SeparationAutomatically separates mixed imports like 🎯 Advanced AST ParsingUses TypeScript's AST parser for robust, error-tolerant import analysis that handles complex syntax and edge cases. ⚡ Intelligent Auto-Order SystemResolves group order conflicts automatically and assigns missing order numbers - no more configuration headaches. 🎨 Pixel-Perfect AlignmentAligns 'from' keywords across import groups for exceptional visual consistency. 📁 Hierarchical ConfigurationSupports 🚀 High PerformanceAdvanced caching system with RegExp serialization for lightning-fast processing of large codebases. 🛡️ Robust Error HandlingComprehensive validation with meaningful error messages and graceful degradation. 📸 Before & After ExamplesMixed Import SeparationBefore TidyJS:
After TidyJS:
Complex Mixed Import Transformations
📦 InstallationFrom VS Code Marketplace
Quick SetupAfter installation, TidyJS works immediately with sensible defaults. For custom configuration, see the Configuration Guide below. 🎮 UsageMethods to Format Imports
Create Configuration FileNew in v1.5.6: Easily create a
Supported File Types
⚙️ ConfigurationConfiguration HierarchyTidyJS uses a sophisticated configuration system with clear precedence:
Default Configuration
📂 Group ConfigurationBasic Group Setup
Advanced Group Patterns
Group Properties
🤖 Auto-Order Resolution SystemTidyJS features an intelligent auto-order system that eliminates configuration headaches: What it does:
Example:
🎨 Format OptionsImport Order ConfigurationControl the order of different import types within each group:
Formatting Options
Advanced Options
📁 Project Configuration Files
|
Type | Example | Internal Classification |
---|---|---|
Side-effect | import './styles.css'; |
sideEffect |
Default | import React from 'react'; |
default |
Named | import { useState } from 'react'; |
named |
Namespace | import * as Utils from './utils'; |
default |
TypeScript Type Imports
Type | Example | Internal Classification |
---|---|---|
Type Default | import type React from 'react'; |
typeDefault |
Type Named | import type { FC } from 'react'; |
typeNamed |
Type Namespace | import type * as Types from './types'; |
typeDefault |
Mixed Import Separation
TidyJS automatically separates ALL mixed import combinations:
// All these mixed imports are automatically separated:
// Default + Named
import React, { useState } from 'react';
// → import React from 'react';
// → import { useState } from 'react';
// Named + Type Named
import { useState, type FC } from 'react';
// → import { useState } from 'react';
// → import type { FC } from 'react';
// Default + Named + Type Named (3-way split)
import React, { useState, type FC } from 'react';
// → import React from 'react';
// → import { useState } from 'react';
// → import type { FC } from 'react';
// Default + Namespace
import React, * as ReactDOM from 'react-dom';
// → import React from 'react-dom';
// → import * as ReactDOM from 'react-dom';
// Type Default + Type Named
import type React, { FC } from 'react';
// → import type React from 'react';
// → import type { FC } from 'react';
Complex Syntax Support
// Aliased imports
import { useState as state, useEffect as effect } from 'react';
// Mixed aliases and types
import React, { Component as Comp, type FC } from 'react';
// Complex multiline imports (100+ specifiers supported)
import {
Button,
TextField,
Grid,
Paper,
Dialog,
// ... 100+ more imports
type Theme,
type Palette
} from '@mui/material';
// Unicode and special characters
import { café, naïve, 中文 } from 'unicode-module';
import worker from './worker?worker';
import styles from './component.module.css';
🛠️ Advanced Features
Dynamic Group Creation
TidyJS automatically creates groups for common patterns:
// Automatically creates "@app/auth" group
import { login } from '@app/auth/services';
import { AuthProvider } from '@app/auth/components';
// Automatically creates "@app/utils" group
import { formatDate } from '@app/utils/date';
import { validateEmail } from '@app/utils/validation';
Custom Sort Orders
Define precise ordering within groups:
{
"name": "React Ecosystem",
"match": "^react",
"sortOrder": [
"react",
"react-dom",
"react-*",
"@types/react*",
"*"
]
}
Path Resolution
Convert between relative and absolute paths:
{
"pathResolution": {
"enabled": true,
"mode": "absolute",
"preferredAliases": ["@components", "@utils", "@lib"]
}
}
Before:
import { Button } from '../../../components/ui/Button';
import { formatDate } from '../../utils/date';
After:
import { Button } from '@components/ui/Button';
import { formatDate } from '@utils/date';
🛡️ Error Handling & Validation
Robust Configuration Validation
TidyJS provides comprehensive validation with helpful error messages:
❌ Configuration Error Examples:
• "Multiple groups marked as default: React, Utils"
• "Invalid regex pattern in group 'External': Unterminated character class"
• "Duplicate group names found: Internal, Internal"
• "Invalid sortOrder in group 'React': array cannot be empty"
Graceful Error Recovery
- Malformed Imports: Continues processing valid imports even with syntax errors
- Invalid Regex: Falls back to string matching for invalid patterns
- Missing Modules: Optional removal of imports from non-existent packages
- Parse Errors: Detailed error reporting with line numbers and context
Debug Mode
Enable comprehensive logging for troubleshooting:
{
"tidyjs.debug": true
}
Debug Output Example:
[TidyJS] Configuration loaded: 4 groups, 0 excluded folders
[TidyJS] Parsing document: 23 imports found
[TidyJS] Mixed import separated: React, { useState, type FC }
[TidyJS] Groups created: React (3), External (8), Internal (12)
[TidyJS] Formatting completed in 12.3ms
📋 Commands & Keybindings
Available Commands
Command | Description |
---|---|
tidyjs.forceFormatDocument |
Format imports in active file |
tidyjs.createConfigFile |
Create a new .tidyjsrc configuration file |
Setting Up Keybindings
To add a keyboard shortcut for formatting imports:
- Open VS Code Keyboard Shortcuts (
Ctrl+K Ctrl+S
/Cmd+K Cmd+S
) - Search for "TidyJS: Format Imports"
- Click the + icon to add your preferred keybinding
Or add directly to your keybindings.json:
{
"key": "cmd+alt+i", // or your preferred shortcut
"command": "tidyjs.forceFormatDocument",
"when": "editorTextFocus"
}
🔧 Integration & Workflows
Format on Save
Enable automatic formatting when saving files:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "Asmir.tidyjs"
}
Team Configuration
Share configuration across your team using .tidyjsrc
:
{
"$schema": "./node_modules/tidyjs/tidyjs.schema.json",
"groups": [
{
"name": "React",
"match": "^react",
"order": 1
},
{
"name": "Team Libraries",
"match": "^@company/",
"order": 2
}
],
"format": {
"removeUnusedImports": true,
"singleQuote": true
}
}
---
## 🐛 Troubleshooting
### Common Issues & Solutions
| Issue | Solution |
|-------|----------|
| **Imports not formatting** | Ensure file type is supported (.ts, .tsx, .js, .jsx) |
| **Groups not matching** | Verify regex patterns are valid and properly escaped |
| **Configuration ignored** | Check configuration hierarchy and file locations |
| **Performance slow** | Enable debug mode to identify bottlenecks |
| **Mixed imports not separated** | Update to latest version (feature added in v1.5.0+) |
### Configuration Validation
Use the built-in validation to catch configuration errors:
```json
{
"tidyjs.debug": true
}
Check the VS Code Output panel (View → Output → TidyJS) for validation messages.
Getting Help
- Enable Debug Mode: Set
tidyjs.debug: true
- Check Output Panel: View → Output → Select "TidyJS"
- Review Configuration: Validate your
.tidyjsrc
or settings - GitHub Issues: Report bugs at github.com/asmirbe/tidyjs
🤝 Contributing
We welcome contributions! Here's how to get started:
Development Setup
# Clone the repository
git clone https://github.com/asmirbe/tidyjs.git
cd tidyjs
# Install dependencies
npm install
# Start development mode
npm run dev
# Run tests
npm run test
# Build extension
npm run build
Available Scripts
Script | Description |
---|---|
npm run dev |
Development mode with file watching |
npm run test |
Run Jest unit tests |
npm run test:e2e |
Run end-to-end VS Code tests |
npm run lint |
Lint codebase with ESLint |
npm run check |
Full validation (type check + lint + test) |
npm run build |
Build production extension |
Contributing Guidelines
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes with comprehensive tests
- Run validation:
npm run check
- Commit changes:
git commit -m 'Add amazing feature'
- Push to branch:
git push origin feature/amazing-feature
- Open a Pull Request
📄 License
MIT License - See LICENSE file for details.
🙏 Acknowledgments
- TypeScript Team - For the excellent AST parser
- VS Code Team - For the comprehensive extension API
- Community Contributors - For feedback, bug reports, and feature requests
📞 Support
- GitHub Issues: Report bugs or request features
- Documentation: Complete guides and examples
- VS Code Marketplace: Extension page and reviews
Made with ❤️ for the TypeScript/JavaScript community
⭐ Star us on GitHub if TidyJS helps organize your imports!