Clean Unused Code – VS Code Extension
Tidy up your JavaScript / TypeScript projects with a single command.
The extension sweeps the entire workspace, deletes dead code, and keeps the rest of your files squeaky-clean—without touching any console.log
or debugger
statements.
✨ What it can do
- Remove unused imports (built-in Organize Imports refactor).
- Remove variables that are declared but never read.
- Remove functions that are never called (top-level or exported).
- Remove React component props that are passed-in but never used.
- Cancellable progress bar, auto-save only when edits were made.
- All rules are optional and can be toggled independently from the settings UI.
🛠️ Installation
From the Marketplace
- Open VS Code ➜ Extensions view.
- Search for "Clean Unused Code" and click Install.
Manual (.vsix)
# if you cloned the repo
npm install
npm run package # produces clean-unused-code-<version>.vsix
code --install-extension clean-unused-code-<version>.vsix
🚀 Quick Start
- Open the folder you want to clean.
- Press Ctrl / Cmd + Shift + P and run
"Clean Unused Imports (Whole Project)".
- Watch the progress notification; cancel any time.
- When the toast "Project clean-up complete ✅" appears, you're done!
⚙️ Configuration
File → Preferences → Settings → "Clean Unused Code" (searchable), or edit settings.json:
{
// package.json › configuration
"cleanUnusedImports.removeUnusedVariables": true, // delete unused let/const/var
"cleanUnusedImports.removeUnusedFunctions": true, // delete never-called functions
"cleanUnusedImports.removeUnusedProps": false, // delete unused React props
}
Toggle any of them, re-run the command, and only the enabled rules are applied.
📚 Usage Tips
• On-demand only by design—bind the command to a custom key if you prefer.
• Combine with VS Code's "Format Document" on save for an all-in-one hygiene workflow.
• Running in CI? Use code --install-extension
followed by code --command extension.cleanUnusedImports
inside a headless VS Code instance (via xvfb-run
on Linux).
🙋 FAQ
Q: Will it delete my debug prints?
A: No. The extension explicitly ignores console.*
calls and debugger
statements.
Q: Which languages are supported?
A: .js
, .jsx
, .ts
, and .tsx
. Support for more languages can be added via pull request.
Q: How does it detect unused React props?
A: It parses each component with the TypeScript AST and checks prop identifiers against the component body, skipping any component that uses the spread operator (...props
).
Happy coding & keep your project spotless!