The minimum supported version of Node.js is v18. Check your Node.js version with
node --version.
- Install sweepp:
```sh
npm install -g sweepp
# or
npm install --save-dev sweepp
```
Install via Homebrew tap:
brew tap piyushdhoka/sweep
brew install sweeppUpgrade:
brew update
brew upgrade sweepp- (Optional) Configure path aliases or monorepo settings in your
tsconfig.json/jsconfig.jsonfor best results.
Check the installed version with:
sweepp --version
If it's not the latest version, run:
npm update -g sweeppList unused imports and code:
sweepp list .Clean unused imports:
sweepp cleanDetect unused code:
sweepp unuseYou can use options with list/clean/unuse:
sweepp list . --ext ts,tsx,js --ignore dist,build--ext <list>: Comma-separated file extensions (default:ts,tsx,js,jsx)--ignore <list>: Comma-separated ignore patterns (default:node_modules)--check-local: Check if local imports exist in project (supports path aliases)
You can use these aliases:
swplistcleanunuseversion
Unused Imports Report
File Count Unused Imports
─────────────────────────────────────────────
src\math.ts 3 useState, useEffect, readFileSync
src\App.tsx 2 Component, useRef
─────────────────────────────────────────────
Summary: 2 file(s) with 5 unused import(s)
sweepp analyzes your codebase using Babel AST parsing to find unused imports and code. It supports monorepos and path aliases, and ignores system folders and .d.ts files for accurate results.
- Make sure you have supported file types in your project
- Check your ignore patterns
- Ensure your codebase is staged and accessible
- Use the
--ignoreoption to add more folders if needed
- sweepp is optimized for speed, but very large codebases may take longer
- Use the
--extoption to limit file types
- Piyush Dhoka: @piyushdhoka
This project is licensed under the Apache-2.0 License - see the LICENSE file for details.
- Zero config: run instantly
- List unused import specifiers (TS/JS/JSX/TSX)
- Safe clean mode removes them
- Detect unused code (functions, classes, variables, types, interfaces) with preview
- Fast AST parsing (Babel; SWC planned)
- Keeps side-effect imports (
import 'polyfill';) - Path alias support (
@/components,src/...) - Optionally check if local imports exist in project
- Monorepo support (pnpm workspaces, npm/yarn workspaces, Turborepo)
- Ignores system folders and
.d.tsfiles
npm install -g sweepp
# or
npm install --save-dev sweeppbrew tap piyushdhoka/sweep
brew install sweeppsweepp
swp
list
clean
unuse
versionYou can use options with list/clean/unuse:
sweepp list . --ext ts,tsx,js --ignore dist,build
swp list . --ext ts,tsx,js --ignore dist,build--ext <list>: Comma-separated file extensions (default:ts,tsx,js,jsx)--ignore <list>: Comma-separated ignore patterns (default:node_modules)--check-local: Check if local imports exist in project (supports path aliases from tsconfig.json/jsconfig.json)
Unused Imports Report
File Count Unused Imports
─────────────────────────────────────────────
src\math.ts 3 useState, useEffect, readFileSync
src\App.tsx 2 Component, useRef
─────────────────────────────────────────────
Summary: 2 file(s) with 5 unused import(s)
sweepp auto-detects path aliases from tsconfig.json/jsconfig.json and monorepo setups (pnpm, npm/yarn workspaces, Turborepo).
0: success1: error
import { analyzeAndClean } from 'sweepp/dist/analyzer';
const result = await analyzeAndClean('src/file.ts', true);
console.log(result.removed);
- Dynamic usage may evade detection
- Side-effect imports are preserved
- Heuristic unused code detection: Next.js pages/app route exports treated as used
- `.d.ts` files are ignored
✔ src/utils/math.ts removed: unusedAdd, unusedSub
✔ src/components/App.tsx removed: UnusedComponent
Clean Summary
Files changed: 2
Total specifiers removed: 3sweepp automatically reads tsconfig.json or jsconfig.json to resolve path aliases when using --check-local:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@components/*": ["src/components/*"]
}
}
}
## Monorepo Support
**Supported monorepo types:**
- **Turborepo** - Detected via `turbo.json` (uses underlying workspace config)
**Example pnpm-workspace.yaml:**
packages:
- 'packages/*'
- 'apps/*'Example package.json workspaces:
{
"workspaces": [
"packages/*",
"apps/*"
]
}When sweepp runs in a monorepo, it will:
- Automatically detect all workspace packages
- Resolve workspace imports like
@myorg/utilsto actual file paths - Support
workspace:*protocol in dependencies - Show monorepo info in output (e.g., "Detected pnpm monorepo with 5 package(s)")
Example output:
Detected pnpm monorepo with 3 package(s)
Unused Imports Report
...
0– success1– unexpected internal error
import { analyzeAndClean } from 'sweepp/dist/analyzer';
// Dry-run (true) lists removals without writing.
const result = await analyzeAndClean('src/file.ts', true);
console.log(result.removed);- Dynamic access patterns may evade detection
- Type-only imports counted if referenced
- Side-effect imports preserved
- Heuristic unused code detection: Next.js
pages/&app/route exports treated as used; namespace imports mark all exports used - Re-export chains & default export usage not fully analyzed yet; review before manual removal
- Babel parser first; SWC migration planned
- SWC for performance
- Improve unused code graph (default exports, re-exports, dynamic usage)
- Config file support
- VS Code extension
- Git diff only mode
- Parallel processing
- Cache / incremental mode
This project is licensed under the Apache-2.0 License - see the LICENSE file for details
