warrah
is a command-line utility and a Rust library that sloppily removes code comments from a text file and outputs the result to stdout:
> warrah code.py
It's a sloppy program because it doesn't fully parse the code. It uses simple and fast logic to detect single- and multi-line comments. Consequently, it will remove comments inside strings and may result in invalid code.
The main use of this utility is to strip comments from code in order to feed it to an LLM, where occasionally incorrect code is fine. Thus the main focus here is on speed, low resource usage, language coverage and simplicity, not correctness.
Warrah supports single and multi-line comments in over 60 programming and markup languages, including popular ones like:
- Python
- JavaScript/TypeScript
- Rust
- Java
- C/C++
- Go
- Ruby
- HTML/CSS
- Shell scripts
- and many more...
For a complete list of supported languages and their comment syntax, please see docs/languages.md.
There are three ways to install Warrah.
First install Rust, then run:
cargo install warrah
Install with Homebrew:
brew tap evgenyneu/warrah
brew install warrah
Download a pre-built binary from the GitHub Releases page.
- Download the appropriate version for your platform.
- Move the binary to a location in your PATH.
warrah [PATH]
PATH: The path to the code file to strip comments from. The language is auto-detected from the file name or extension.
Output goes to stdout, use >
to save it:
warrah code.py > code_no_comments.py
See https://docs.rs/warrah/ if you want to use Warrah as a Rust library.
See docs/development.md for instructions on how to set up the development environment.
See contributing guidelines in CONTRIBUTING.md.
The warrah, or Falkland Islands wolf (Dusicyon australis), also known as the "Antarctic wolf," was the only native land mammal of the Falkland Islands. It was hunted by settlers for its fur and perceived threat to livestock, leading to its extinction in 1876.
Falkland Island fox or "Antarctic Wolf" by John Gerrard Keulemans, from St. George Mivart's Dogs, Jackals, Wolves, and Foxes: A Monograph of the Canidae, published by R. H. Porter, London, 1890. Lithography by Mintern Brothers. Source: Wikimedia Commons.
If you need help or notice a bug, feel free to create an issue ticket. We will be happy to help. :D
This work is in public domain.