
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
clear-comments
Advanced tools
A fast and focused CLI tool to remove comments from your React/JavaScript projects.
You might NOT need this tool if:
This tool is designed for specific use cases where existing solutions don't fit your needs.
npm install -g clear-comments
npm install clear-comments --save-dev
Clear comments in current directory:
clear-comments
Clear comments in specific directory:
clear-comments ./src
With verbose output:
clear-comments --verbose
clear-comments ./src -v
Remove JSDoc comments too:
clear-comments --no-jsdoc
Remove all extra empty lines:
clear-comments ./src --no-jsdoc --remove-empty-lines true
Show help:
clear-comments --help
Using with npx (no installation required):
npx clear-comments
npx clear-comments ./src --verbose
In package.json scripts:
{
"scripts": {
"clean-code": "clear-comments ./src",
"prebuild": "clear-comments ./src --no-jsdoc",
"prepare-delivery": "clear-comments ./dist --verbose"
}
}
In CI/CD pipeline:
- name: Clean comments for production
run: npx clear-comments ./src --no-jsdoc
import { clearComments, removeComments } from 'clear-comments';
// Clear comments in entire project with options
const stats = await clearComments({
targetDir: './src',
verbose: true,
preserveJSDoc: true,
removeEmptyLines:false,
excludePatterns: ['**/generated/**']
});
console.log(`Processed ${stats.processedFiles} files`);
console.log(`Removed ${stats.totalLinesRemoved} lines of comments`);
// Remove comments from a string
const cleanCode = removeComments(sourceCode, '.tsx', true {
removeEmptyLines: true
});
// CommonJS usage
const { clearComments, removeComments } = require("clear-comments");
// Same API as above
// comment)/* comment */){/* comment */})<!-- comment -->)/** comment */) by default.js).ts).jsx).tsx)node_modules, dist, build directories.js - JavaScript files.jsx - React JSX files.ts - TypeScript files.tsx - TypeScript JSX files# Before delivering to client, clean up internal comments
clear-comments ./project-src --verbose
# ✅ Cleaned: 47 files, removed 312 lines of comments
# Prepare clean examples for tutorial
clear-comments ./tutorial-code --no-jsdoc
# Creates clean, distraction-free code examples
# Clean up old codebase before modernization
clear-comments ./legacy-app --verbose
# Removes outdated comments while preserving JSDoc
Before:
// This is a component for user authentication [comment way we go comot]
function MyComponent() {
/* State management for login form [comment way we go comot] */
const [count, setCount] = useState(0); // Counter state [comment way we go comot]
/**
* Handles user login
* @param credentials User login data
*/
const handleLogin = (credentials) => {
// TODO: Add validation [comment way go comot]
return authenticate(credentials);
};
return (
<div>
{/* JSX comment - login form [comment way go comot]*/}
<h1>Count: {count}</h1>
<!-- HTML comment (shouldn't be here) -->
</div>
);
}
After (with JSDoc preservation):
function MyComponent() {
const [count, setCount] = useState(0);
/**
* Handles user login [comment way no we no comot]
* @param credentials User login data
*/
const handleLogin = (credentials) => {
return authenticate(credentials);
};
return (
<div>
<h1>Count: {count}</h1>
</div>
);
}
git clone https://github.com/asapcone/clear-comments.git
cd clear-comments
npm install
npm run build
npm run dev
npm test
npm run clean
| Option | Description | Default |
|---|---|---|
directory | Target directory to process | Current directory |
--verbose, -v | Show detailed processing output | false |
--no-jsdoc | Remove JSDoc comments as well | Preserves JSDoc |
--help, -h | Show help information | - |
--remove-empty-lines [true false] | Preserve or remove blank lines | False |
clearComments(options)Main function to process files in a directory.
Options:
targetDir?: string - Directory to processpreserveJSDoc?: boolean - Keep JSDoc comments (default: true)verbose?: boolean - Detailed logging (default: false)excludePatterns?: string[] - Additional exclusion patternsReturns: Promise<ProcessingStats>
removeComments(content, extension, preserveJSDoc)Remove comments from a string of code.
Parameters:
content: string - Source code contentextension: '.js' | '.jsx' | '.ts' | '.tsx' - File extensionpreserveJSDoc: boolean - Whether to preserve JSDocReturns: string - Cleaned content
We welcome contributions! Please:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature).clearrc)MIT License - see the LICENSE file for details.
Aaron Sunday
🆕 Remove Empty Lines by Default
➕ Added --preserve-empty-lines CLI option
🛠 Improved merging of CLI options and config
💡 Need help? Open an issue on GitHub or check out the examples above.
🤝 Found this useful? Star the repo and share with your team!
FAQs
A fast CLI tool to clear comments from your React/JavaScript projects
We found that clear-comments demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.