comment-remover-0.1.1 is not a library.
Comment Remover
Strip comments from your code
Install
Install all languages
Install specific languages only
for small binary sizes, install only the languages you need:
# example: Install with Python and Rust support only
# example: install with JavaScript, TypeScript, and C support
Usage
rmcm [OPTIONS] [FILES]...
Arguments:
[FILES]... Input files to process (if empty, reads from stdin)
Options:
-l, --language <LANG> Specify language (required for stdin, optional for files)
-i, --in-place Modify files in-place instead of outputting to stdout
-c, --collapse-whitespace <N> Collapse consecutive blank lines to at most N blank lines
-f, --force Continue processing even if some files fail
-h, --help Print help
Examples
# remove comments from a python file and print to stdout
# remove comments and modify file in-place
# process multiple files in-place
# read from stdin (language must be specified)
|
# collapse multiple blank lines to at most 1
# override language detection
# continue processing even if some files fail
Supported Languages
The tool uses tree-sitter parsers for accurate comment removal. Each language is an optional feature:
| Language | Feature Flag | Extensions | Comment Styles |
|---|---|---|---|
| Bash | bash |
.sh, .bash |
# |
| C | c |
.c, .h |
//, /* */ |
| C# | c-sharp |
.cs |
//, /* */, /// |
| C++ | cpp |
.cpp, .cc, .cxx, .hpp, .hxx, .c++ |
//, /* */ |
| CSS | css |
.css |
/* */ |
| Go | go |
.go |
//, /* */ |
| Haskell | haskell |
.hs |
--, {- -} |
| HTML | html |
.html, .htm |
<!-- --> |
| Java | java |
.java |
//, /* */, /** */ |
| JavaScript | javascript |
.js, .jsx, .mjs, .cjs |
//, /* */ |
| Lua | lua |
.lua |
--, --[[ ]] |
| PHP | php |
.php |
//, #, /* */ |
| Python | python |
.py, .pyw |
# |
| Ruby | ruby |
.rb |
#, =begin/=end |
| Rust | rust-lang |
.rs |
//, /* */ |
| Scala | scala |
.scala |
//, /* */ |
| Swift | swift |
.swift |
//, /* */ |
| TypeScript | typescript |
.ts, .tsx, .mts, .cts |
//, /* */ |
Build from Source
# clone the repo
# build with all languages
# Build with specific languages
Available Features
All language features:
bash, c, c-sharp, cpp, css, go, haskell, html, java, javascript,
json, lua, php, python, ruby, rust-lang, scala, swift, typescript, yaml
TODO
Want to help? Here's what we're planning:
- SQL - Add support for SQL dialects with
--and/* */ - Perl - Support
#comments and POD documentation - R - Handle
#comments - Kotlin - Support
//and/* */comments - Dart - Add comment support
- Elixir - Handle
#comments - Configuration files -
.ini,.conf,.env,.toml - Documentation generation - Option to extract comments instead of removing
- Preserve specific comments - Keep comments matching patterns (e.g., license headers)
- Recursive directory processing - Process entire directory trees
- Parallel processing - Speed up batch operations
Contributing
Found a bug? PRs are welcome. The repo is open to anything. Pick something from the TODO or bring your own ideas.
License
Apache 2.0