A lightweight JavaScript/TypeScript code cleaning tool
npm install @fe-fast/code-sweeper> Lightweight JavaScript/TypeScript code cleanup tool



Code Sweeper is a tool focused on automatically cleaning redundant code in projects, filling the code cleanup gaps that ESLint and Prettier cannot cover.
- ๐ Smart Analysis: AST-based static analysis for precise identification of unused code
- ๐งน One-click Cleanup: Remove unused imports, variables, and functions
- ๐ Debug Cleanup: Automatically remove console.log and debugger statements
- โ๏ธ Flexible Configuration: Support custom cleanup rules and file filtering
- ๐ Multi-framework Support: Compatible with Vue, React, and TypeScript projects
- ๐ Detailed Reports: Provide before-and-after cleanup analysis
- ๐ Build Tool Integration: Support for Webpack, Vite, and Rollup plugins
``bashGlobal installation
npm install -g code-sweeper
$3
`bash
Analyze code issues
code-sweeper analyzeClean code (preview mode)
code-sweeper clean --dry-runExecute cleanup
code-sweeper cleanInitialize configuration file
code-sweeper config --init
`๐ Build Tool Integration
For seamless integration into your build process, Code Sweeper provides official plugins for major build tools.
$3
`bash
npm install @fe-fast/code-sweeper --save-dev
or
pnpm add -D @fe-fast/code-sweeper
or
yarn add -D @fe-fast/code-sweeper
`$3
`javascript
// webpack.config.js
const { CodeSweeperWebpackPlugin } = require('@fe-fast/code-sweeper/webpack');module.exports = {
// ... other configs
plugins: [
new CodeSweeperWebpackPlugin({
// options
rules: {
removeConsoleLog: process.env.NODE_ENV === 'production',
},
}),
],
};
`$3
`typescript
// vite.config.ts
import { defineConfig } from 'vite';
import codeSweeperPlugin from '@fe-fast/code-sweeper/vite';export default defineConfig({
plugins: [
codeSweeperPlugin({
rules: {
removeConsoleLog: process.env.NODE_ENV === 'production',
},
}),
],
});
`$3
`javascript
// rollup.config.js
import codeSweeperPlugin from '@fe-fast/code-sweeper/rollup';export default {
// ... other configs
plugins: [
codeSweeperPlugin({
rules: {
removeConsoleLog: process.env.NODE_ENV === 'production',
},
}),
],
};
`$3
All plugins support the following options:
`typescript
interface PluginOptions {
include?: string[];
exclude?: string[];
dryRun?: boolean;
skipConfirmation?: boolean;
rules?: {
removeUnusedImports?: boolean;
removeUnusedVariables?: boolean;
removeConsoleLog?: boolean;
removeDebugger?: boolean;
formatCode?: boolean;
renameToCamelCase?: boolean;
};
}
`For more examples, check out the examples directory.
๐ Command Reference
$3
Analyze code issues in the project without making any modifications.
`bash
code-sweeper analyze [options]Options:
-p, --path Target directory path (default: current directory)
-c, --config Configuration file path
--json Output results in JSON format
`$3
Execute code cleanup operations.
`bash
code-sweeper clean [options]Options:
-p, --path Target directory path (default: current directory)
-c, --config Configuration file path
--dry-run Preview mode, don't actually modify files
--imports Only clean unused imports
--variables Only clean unused variables
--console Only remove console statements
--debugger Only remove debugger statements
-y, --yes Skip confirmation prompts
`$3
Manage cleanup rule configurations.
`bash
code-sweeper config [options]Options:
--init Initialize configuration file
--show Show current configuration
`โ๏ธ Configuration File
Create a
.code-sweeper.json file in your project root:`json
{
"rules": {
"removeUnusedImports": true,
"removeUnusedVariables": true,
"removeConsoleLog": true,
"removeDebugger": true,
"formatCode": false,
"renameToCamelCase": false
},
"include": [
"src/*/.{js,ts,jsx,tsx}",
"components/*/.{js,ts,jsx,tsx}"
],
"exclude": [
"node_modules/**",
"dist/**",
"build/**",
"*.min.js"
],
"parser": {
"typescript": true,
"jsx": true,
"decorators": true,
"classProperties": true
}
}
`๐ Usage Examples
$3
`bash
$ code-sweeper analyze๐ Code Sweeper - Analyzing your code...
๐ Target path: /Users/project/src
๐ Code Analysis Report
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Summary:
โข Total files scanned: 45
โข Files with issues: 12
โข Total issues found: 28
๐ Issue Breakdown:
โข Unused imports: 15
โข Unused variables: 8
โข Console statements: 3
โข Debugger statements: 2
๐ก Recommendations:
โข Run code-sweeper clean to fix these issues
โข Use --dry-run flag to preview changes first
`$3
`bash
$ code-sweeper clean๐งน Code Sweeper - Cleaning your code...
โ
Cleaning completed!
๐ Summary:
โข Files modified: 8
โข Issues fixed: 23
โข Lines removed: 45
โข Estimated size reduction: ~2.1KB
`๐ ๏ธ Development
`bash
Clone the project
git clone https://github.com/william-xue/code-sweeper.git
cd code-sweeperInstall dependencies
npm installBuild project
npm run buildRun tests
npm testLocal development
npm run dev
`๐ค Contributing
Welcome to submit Issues and Pull Requests!
1. Fork this project
2. Create a feature branch (
git checkout -b feature/AmazingFeature)
3. Commit your changes (git commit -m 'Add some AmazingFeature')
4. Push to the branch (git push origin feature/AmazingFeature`)This project is licensed under the MIT License - see the LICENSE file for details.
- Babel - AST parsing and transformation
- TypeScript - Type support
- Commander.js - CLI framework
---
Make code cleaner, make development more efficient! ๐