comment-strip-cli
Version:
A powerful CLI tool to strip comments from source code files while preserving strings and important metadata
272 lines (174 loc) ⢠4.81 kB
Markdown
# 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-cli
~~~
Local 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-run
~~~
### Advanced 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) # Display
~~~
~~~
comment-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.
#
<div align="center">
āļø Star it. Strip it. Ship it.
š¤ Built with passion using Node.js, for minimalists and CLI lovers
</div>
#