Runs safety validation before marking anything as fixable
Presents results as diagnostics (squiggly lines), quick fixes, and a tree view
Safety Validation
Before marking any symbol for removal, the extension checks for:
Dynamic imports: require(variable), import(expr)
eval() usage: If eval is present, all symbols are preserved
Decorators: Decorated classes/methods are preserved (NestJS, Angular, etc.)
Reflect API: If Reflect metadata is used, decorated symbols are kept
Side-effect imports: import "polyfill", CSS imports, etc. are preserved
Framework conventions: Next.js pages/routes, NestJS modules/services, Angular components, test files, config files, index files
Global assignments: window.X, globalThis.Y
If uncertain → the symbol is kept. Conservative by design.
Settings
Setting
Default
Description
importOptimizer.analyzeOnSave
false
Automatically analyze on file save
importOptimizer.autoFixOnSave
false
Auto-fix unused imports on save
importOptimizer.ignorePaths
["**/node_modules/**", ...]
Glob patterns to ignore
importOptimizer.preserveSideEffectImports
true
Keep side-effect imports
importOptimizer.convertToTypeImports
true
Convert type-only imports to import type
importOptimizer.optimizeNamespaceImports
true
Narrow import * to named imports
importOptimizer.detectUnusedExports
true
Find exports not imported elsewhere
importOptimizer.detectUnusedDependencies
true
Find unused npm dependencies
importOptimizer.detectUnreferencedFiles
true
Find files not imported anywhere
importOptimizer.safetyLevel
"strict"
strict / moderate / aggressive
UI
Diagnostics: Issues show as squiggly underlines with Unnecessary tag (faded text)
Quick Fixes: Lightbulb actions appear on hover — click to fix
Tree View: "Import Optimizer" panel in the Explorer sidebar shows all findings grouped by category
Status Bar: Click the "⟡ Import Optimizer" item in the status bar to trigger analysis
Getting Started
# Clone and install
git clone <repo>
cd import-optimizer
npm install
# Compile
npm run compile
# Press F5 in VS Code to launch the Extension Development Host