@chengyixu/cmtx
v1.0.0
Published
Comment eXtractor — extract comments from source code files with line numbers. Supports JS, TS, Python, Go, Rust, C/C++, Java, Ruby, Shell, and more.
Maintainers
Readme
cmtx — Comment eXtractor
Extract comments from source code files with line numbers. Zero dependencies.
Install
npm install -g @chengyixu/cmtxUsage
# Extract all comments from a file
cmtx src/app.ts
# Find TODO/FIXME/HACK/NOTE/BUG comments
cmtx --todo src/
# Extract only Python comments
cmtx --lang py script.py
# Pipe code from stdin
cat file.c | cmtx -l c
# JSON output for scripting
cmtx --json lib/ | jq '.[] | select(.type == "multi")'Supported Languages
| Language | Extensions | |----------|-----------| | JavaScript/TypeScript | .js, .ts, .jsx, .tsx, .mjs, .cjs | | Python | .py, .py3 | | Go | .go | | Rust | .rs | | C | .c, .h | | C++ | .cpp, .hpp, .cc, .hh, .cxx, .hxx | | Java | .java | | Ruby | .rb | | Shell | .sh, .bash, .zsh | | Swift | .swift | | Kotlin | .kt, .kts | | SQL | .sql | | Lua | .lua | | Haskell | .hs | | Elm | .elm | | Elixir | .ex, .exs |
Flags
| Flag | Description |
|------|-------------|
| --help, -h | Show help |
| --version, -V | Show version |
| --todo, -t | Only comments with TODO/FIXME/HACK/XXX/NOTE/BUG |
| --single, -s | Only single-line comments |
| --multi, -m | Only multi-line/block comments |
| --no-color | Disable colored output |
| --json, -j | Output as JSON array |
| --lang, -l | Force language (e.g., js, py, go) |
Examples
# Find all TODO comments in a TypeScript project
$ cmtx --todo src/
src/utils/helpers.ts:42 [single] // TODO: optimize this loop
src/api/client.ts:128 [single] // FIXME: handle timeout edge case
# Extract docstrings from Python
$ cmtx --multi lib.py
lib.py:5-10 [multi] Parse the configuration file and return settings dict
# JSON output for CI/CD integration
$ cmtx --json --todo src/ > todos.json