comment-strip-cli
v1.0.0
Published
A powerful CLI tool to strip comments from source code files while preserving strings and important metadata
Downloads
9
Maintainers
Readme
Comment Strip CLI 🛠️
🚫 Tired of noisy, outdated, or AI-generated comments cluttering your code?
🔧 comment-strip-cli removes all the fluff in seconds — perfect for production-ready commits, open source cleanup, or polishing AI-assisted code.
🚀 Features
- Multi-language support: JavaScript/TypeScript, C/C++, Python, Solidity, Rust, Go, Java, and many more
- Smart parsing: Preserves comments inside strings and handles edge cases
- Flexible filtering: Strip specific comment types (e.g., only
//or only#) - Backup support: Create backups before modification
- Dry-run mode: Preview changes before applying
- Auto-formatting: Clean up code after comment removal
- Recursive processing: Handle entire directories
- Special file support: Dockerfile, Makefile, CMakeLists.txt
📦 Installation
Global Installation (Recommended)
npm install -g comment-strip-cliLocal Installation
npm install comment-strip-cli
npx comment-strip --help🔧 Usage
Basic Usage
comment-strip --help- Strip all comments from a file:
comment-strip <FILE_NAME>- Strip all comments from a directory:
comment-strip <DIRECTORY_NAME>- Preview changes without modifying files:
comment-strip <FILE_NAME> --dry-runAdvanced Usage
- Strip only single-line comments:
comment-strip <FILE_NAME> --type="//"- Strip only hash comments from Python files:
comment-strip script.py --type="#"- Create backup before processing:
comment-strip <FILE_NAME> --backup- Process only specific file types:
comment-strip <DIRECTORY_NAME>/ --extensions=js,ts,py- Combine options:
comment-strip src/ --type="//" --backup --extensions=js,ts📝 Command Options
Usage: comment-strip [options] <file|directory>
Options:
--type <type>, -t Comment type to strip: //, #, /* */, --, etc.
--dry-run, -d Preview changes without modifying files
--backup, -b Create backup files before modification
--extensions <ext>, -e File extensions to process (comma-separated)
--help, -h Show help message🌍 Supported Languages
Programming: JavaScript, TypeScript, C, C++, Java, Python, Solidity, Rust, Go, Kotlin, Swift, Dart, Scala
Web: CSS, SCSS, HTML, JSON
Config: Docker, CMake, TOML, YAML, INI, Makefile
Database: SQL
📋 Examples
JavaScript – Strip // and /* */ Comments
- Before
// This is a single-line comment
const url = "https://example.com"; // Inline comment
/*
This is a multi-line comment
*/
function greet(name) {
console.log("Hello, " + name); // Greet user
}comment-strip app.js- After
const url = "https://example.com";
function greet(name) {
console.log("Hello, " + name);
}🐍 Python – Strip # Comments
- Before
# Import the OS module
import os
def say_hello(name): # This function greets
message = f"Hello, {name}" # Format the message
print(message) # Displaycomment-strip script.py --type="#"- After
import os
def say_hello(name):
message = f"Hello, {name}"
print(message)Solidity – Strip // and /* */ but Preserve SPDX & NatSpec
- Before
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Greeter Contract
contract Greeter {
string public greeting; // Stores greeting
constructor(string memory _greeting) {
greeting = _greeting; // Set greeting
}
/* This function returns the greeting */
function greet() public view returns (string memory) {
return greeting;
}
}comment-strip Greeter.sol- After
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Greeter {
string public greeting;
constructor(string memory _greeting) {
greeting = _greeting;
}
function greet() public view returns (string memory) {
return greeting;
}
}🔒 Special Handling
Preserves SPDX licenses in Solidity files
Preserves shebangs (#!/usr/bin/env python3)
Preserves docstrings in Python
Handles comments inside strings correctly
Supports regex literals in JavaScript
🤝 Contributing
Fork the repository
Create your feature branch (git checkout -b feature/amazing-feature)
Commit your changes (git commit -m 'Add amazing feature')
Push to the branch (git push origin feature/amazing-feature)
Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⭐️ Star it. Strip it. Ship it.
🖤 Built with passion using Node.js, for minimalists and CLI lovers
