Interactive CLI to find and selectively remove console statements from your codebase
npm install console-cleanInteractive CLI tool to find and selectively remove console statements from your codebase.
Think git add -p but for cleaning up debug logs.
``bashRun directly with npx
npx console-clean
Usage
$3
Scan your codebase and interactively select which console statements to remove:
`bash
console-clean
or
console-clean ./src
`This will:
1. Scan all JS/TS files
2. Show each console statement with context
3. Let you choose: Remove, Keep, Remove all of type, etc.
4. Preview changes before applying
$3
List all console statements without removing them:
`bash
Table output
console-clean scanJSON output (for CI/tooling)
console-clean scan --jsonScan specific directory
console-clean scan --path ./src
`$3
Remove all console statements without interaction:
`bash
Remove all (with confirmation)
console-clean cleanSkip confirmation
console-clean clean --forceDry run (show what would be removed)
console-clean clean --dry-run
`Configuration
Create a config file in your project root:
$3
`json
{
"include": ["src//", "lib//"],
"exclude": ["/.test.", "/.spec."],
"types": ["log", "debug", "info"],
"keep": ["error", "warn"],
"respectGitignore": true,
"ignoreComments": ["console-clean-ignore", "keep-console"]
}
`$3
`javascript
export default {
include: ['src/*/'],
exclude: ['*/.test.*'],
types: ['log', 'debug'],
keep: ['error', 'warn'],
};
`$3
`json
{
"consoleclean": {
"types": ["log", "debug"],
"keep": ["error", "warn"]
}
}
`Ignore Comments
Mark console statements to preserve:
`javascript
// console-clean-ignore
console.log('This will be skipped');console.log('This too'); // console-clean-ignore
/ console-clean-ignore /
console.warn('Block comment works too');
`Options
$3
-
--path, -p - Directory to scan (default: .)
- --config, -c - Path to config file$3
-
--no-preview - Skip diff preview before applying$3
-
--json - Output as JSON$3
-
--force, -f - Skip confirmation prompt
- --dry-run - Show changes without applyingExamples
`bash
Interactive mode in src directory
console-clean ./srcScan and output JSON
console-clean scan --json > console-report.jsonRemove all console.log and console.debug (keep errors/warnings)
console-clean cleanDry run to preview changes
console-clean clean --dry-runForce remove without confirmation
console-clean clean --force
`How It Works
1. Scanner: Uses
fast-glob to find JS/TS files, respects .gitignore
2. Parser: Uses Babel to parse files and detect console statements
3. Modifier: Uses magic-string for surgical removal without breaking code
4. Interactive: Uses inquirer for smooth terminal UIFeatures
- ✓ Detects all console.* methods (log, warn, error, info, debug, etc.)
- ✓ Interactive selection with context preview
- ✓ Safe removal preserving code structure
- ✓ Respects .gitignore patterns
- ✓ Supports ignore comments
- ✓ TypeScript and JSX support
- ✓ Dry run mode
- ✓ JSON output for CI/tooling
Supported Console Methods
All standard console methods:
-
log, warn, error, info, debug, trace
- table, dir, group, groupEnd, groupCollapsed
- time, timeEnd, timeLog
- assert, count, countReset
- clear, profile, profileEnd`MIT
Nabil Benhamou
Issues and PRs welcome at https://github.com/thebiltheory/console-clean