High-accuracy comment removal tool for 20+ programming languages with beautiful CLI
Project description
Comment Remover CLI
A high-accuracy Python tool for removing comments from programming files while preserving important code patterns such as color codes, URLs, and preprocessor directives.
Features
- Universal Language Support: 20+ programming languages including Python, JavaScript, TypeScript, C/C++, Java, C#, Go, Rust, HTML, CSS, SQL, PHP, Ruby, and Shell scripts
- Safe Operation: Automatic backup creation before processing
- Undo Capability: Restore original files from backup
- Configurable Settings: JSON-based configuration system
- Demo Mode: Generate test files for validation
- High Performance: Efficient processing of entire directory trees
- Recursive Scanning: Processes all subdirectories automatically
- Robust Error Handling: Graceful handling of permission errors and encoding issues
Installation
From PyPI (Recommended)
pip install comment-remover-cli
From Source
git clone https://github.com/guider23/Comms.git
cd Comms
pip install .
Quick Start
# Remove comments from current directory
python -m comms.cli
# Remove comments from specific directory
python -m comms.cli /path/to/your/project
# Create demo files for testing
python -m comms.cli --demo
# Restore files from backup
python -m comms.cli --undo
# Display help information
python -m comms.cli --help
Command Line Options
python -m comms.cli [directory] [options]
Options:
-h, --help Show help message and exit
--demo Create demo files with comments for testing
--undo Restore files from most recent backup
--config FILE Use custom configuration file (default: config.json)
Supported Languages
| Language | Extensions | Line Comments | Block Comments |
|---|---|---|---|
| Python | .py | # | """ """ or ''' ''' |
| JavaScript/TypeScript | .js, .jsx, .ts, .tsx | // | /* */ |
| Java | .java | // | /* */ |
| C/C++ | .c, .cpp, .h, .hpp | // | /* */ |
| C# | .cs | // | /* */ |
| Go | .go | // | /* */ |
| Rust | .rs | // | /* */ |
| PHP | .php | // | /* */ |
| Ruby | .rb | # | =begin =end |
| Shell/Bash | .sh, .bash | # | - |
| SQL | .sql | -- | /* */ |
| HTML | .html, .htm | - | |
| CSS | .css | - | /* */ |
| SCSS/Sass | .scss, .sass | // | /* */ |
| Lua | .lua | -- | --[[ ]] |
| Swift | .swift | // | /* */ |
| Kotlin | .kt, .kts | // | /* */ |
Pattern Preservation
The tool intelligently preserves:
- Color codes:
#FF5733,#123ABC - URLs:
https://example.com,http://site.com - Shebangs:
#!/usr/bin/env python - C Preprocessor:
#include,#define,#if,#endif, etc. - Content in strings: Comments inside quoted strings remain untouched
Example Usage
Before Processing
Python file:
#!/usr/bin/env python3
# This is a comment to remove
import requests # Another comment
def get_data():
"""This docstring stays"""
url = "https://api.example.com" # URL preserved
color = "#FF5733" # Color code preserved
# This comment will be removed
return requests.get(url)
After Processing
Python file:
#!/usr/bin/env python3
import requests
def get_data():
"""This docstring stays"""
url = "https://api.example.com"
color = "#FF5733"
return requests.get(url)
Configuration
Create a config.json file to customize behavior:
{
"languages": {
"python": {
"extensions": [".py"],
"line_comment": "#",
"block_comment_start": "\"\"\"",
"block_comment_end": "\"\"\""
},
"javascript": {
"extensions": [".js", ".jsx"],
"line_comment": "//",
"block_comment_start": "/*",
"block_comment_end": "*/"
}
},
"backup_enabled": true,
"backup_directory": ".backup",
"skip_patterns": [
"node_modules/",
".git/",
"__pycache__/"
]
}
Safety Features
Automatic Backups
- All original files are backed up to
.backup/directory - Backup directory structure mirrors your project structure
- Previous backups are overwritten on each run
Undo Operation
# Restore from most recent backup
python -m comms.cli --undo
Pre-execution Warning
The tool displays:
- Number of files to be processed
- File types detected
- Clear warning about the operation
- Requires explicit confirmation
Error Handling
- Permission errors: Gracefully skipped with warnings
- Encoding issues: Uses UTF-8 with error tolerance
- Backup failures: File processing is skipped if backup fails
- Malformed files: Processing continues with error reporting
Advanced Usage
Custom Configuration
python -m comms.cli --config custom-config.json /my/project
Processing Specific File Types
Edit config.json to limit processing to specific languages or add new ones.
Integration with Build Systems
# In your build script
python -m comms.cli src/ --config production-config.json
Technical Details
String Handling
- Properly handles escaped quotes in strings
- Supports single, double, and triple-quoted strings (Python)
- Preserves multiline strings and docstrings
Comment Detection
- State-machine based parsing for accuracy
- Context-aware comment detection
- Handles nested comment structures
Performance
- Processes files sequentially for reliability
- Memory-efficient line-by-line processing for large files
- Minimal I/O operations
Requirements
- Python 3.6 or higher
- No external dependencies
- Cross-platform (Windows, macOS, Linux)
Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a 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
Development Setup
git clone https://github.com/guider23/Comms.git
cd Comms
pip install -e .
Running Tests
python -m pytest tests/
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: Report bugs on GitHub Issues
- PyPI Package: comment-remover-cli
- Documentation: Full docs at GitHub Repository
Changelog
v1.1.0
- Professional documentation
- Improved error handling
- Enhanced pattern preservation
- Updated PyPI package
v1.0.0
- Initial release
- Support for 20+ programming languages
- Automatic backup and undo functionality
- Configurable settings
Made for developers who value clean, production-ready code.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file comment_remover_cli-1.2.0.tar.gz.
File metadata
- Download URL: comment_remover_cli-1.2.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
237ec098c3b41252f4e254d72353d40a10b32e9a41deebab35e97f5902bfd551
|
|
| MD5 |
334d58ce3b09d2e42aa9bd8847d1a19c
|
|
| BLAKE2b-256 |
610aac917b299bfff6aeff4c1dc8b39ee09c5625b9f234879df3ecca63f80360
|
File details
Details for the file comment_remover_cli-1.2.0-py3-none-any.whl.
File metadata
- Download URL: comment_remover_cli-1.2.0-py3-none-any.whl
- Upload date:
- Size: 20.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84d347a4aa8d0b64d8a62f1d28565e867e850c472c4e993f030e5f1259aaaeb9
|
|
| MD5 |
debb7c7b5ea0ec125d4f025e37c147a0
|
|
| BLAKE2b-256 |
e97783aa623ada14e297007e4b718143b85c838954261867839b7ffee4e5fc3b
|