https://github.com/tktech/comscrub
Strips all comments from C/C++/Obj-C/Obj-C++ sources and headers.
https://github.com/tktech/comscrub
Last synced: 8 months ago
JSON representation
Strips all comments from C/C++/Obj-C/Obj-C++ sources and headers.
- Host: GitHub
- URL: https://github.com/tktech/comscrub
- Owner: TkTech
- Created: 2025-09-19T04:42:07.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-19T06:02:06.000Z (9 months ago)
- Last Synced: 2025-10-02T01:43:52.524Z (9 months ago)
- Language: Python
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
comscrub
=========
Strip comments from C-family source files using libclang’s tokenizer. Unlike
regex-based approaches, this relies on clang’s understanding of the language,
so strings and tricky edge cases are handled correctly.
Usage
-----
- CLI: `comscrub file.c` (or `python -m comscrub file.c`).
- Prints to stdout by default; use `--inplace` to rewrite files.
- Remove only line comments with `--line-comments-only` (keeps `/* ... */`).
Examples:
- `comscrub data/sample.c`
- `comscrub --inplace data/sample.c`
- Remove only line comments: `comscrub --line-comments-only data/sample.cpp`
- Force language (otherwise inferred from extension): `comscrub -x c++ foo.hpp`
- Pass extra clang args (repeatable): `comscrub --clang-arg -std=c11 file.c`
One-liners:
- In‑place across repo (batch files safely):
- find . -type f \( -name '*.cpp' -o -name '*.hpp' \) -exec uv run comscrub --inplace {} +
- Dry‑run to stdout (one file at a time to keep outputs separate):
- find . -type f \( -name '*.cpp' -o -name '*.hpp' \) -exec uv run comscrub {} \;
- Only remove line comments:
- find . -type f \( -name '*.cpp' -o -name '*.hpp' \) -exec uv run comscrub --line-comments-only --inplace {} +
- Handle paths with spaces using null‑sep + xargs:
- find . -type f \( -name '*.cpp' -o -name '*.hpp' \) -print0 | xargs -0 uv run comscrub --inplace
- Exclude common build/VC dirs:
- find . -type d \( -name .git -o -name build -o -name dist \) -prune -o -type f \( -name '*.cpp' -o -name '*.hpp' \) -exec uv run comscrub --inplace {} +