Skip to main content

High-accuracy comment removal tool for 20+ programming languages with beautiful CLI

Project description

Comment Remover CLI

PyPI version Python Support License: MIT

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:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. 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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comment_remover_cli-1.2.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comment_remover_cli-1.2.1-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file comment_remover_cli-1.2.1.tar.gz.

File metadata

  • Download URL: comment_remover_cli-1.2.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.0

File hashes

Hashes for comment_remover_cli-1.2.1.tar.gz
Algorithm Hash digest
SHA256 0dba11d6998b728175c95e35fbba933b64b68e178536c3cbb64aea4d28e57565
MD5 8b3416005e47aaad5554bf6288c1b9c6
BLAKE2b-256 e86540a9b6e1c2c7a53968c4ac35067bc8692234f5287749a93f02c13bb9e6cb

See more details on using hashes here.

File details

Details for the file comment_remover_cli-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for comment_remover_cli-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0b13aa02f504fb4bdb452a9eedbd3f7052c783b445012ffedae249b69a36ff36
MD5 30134bb2758e7dcf6fd58a8d460bf9cf
BLAKE2b-256 524c95f2e53fa1d645674652adaa9b2388be58050e315454425a1ac424a9efde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page