Removes comments from source code. The interface follows go fmt: the result
goes to standard output, and flags rewrite, diff or list.
Comment-like text inside string literals is kept. A line holding nothing but a comment is removed with its line ending; a line that still holds code keeps its line ending, so lines are never joined.
make generate
go build -o bin/nocomment ./cmd/nocommentmake generate fetches pinned ANTLR grammars and writes lexers under
internal/lexer/generated/. They are build artifacts, not version controlled.
nocomment main.go # print without comments
nocomment -l src/ # list files that would change
nocomment -d src/main.go # unified diff
nocomment -w src/main.go # rewrite in place
nocomment -lang go < main.goA directory is walked recursively in lexicographic order; dot entries and
vendor, node_modules, bin, build, dist, target, scratch and
_build are skipped. Only known extensions are processed; a named file always
is.
|
write the result to the source file |
|
display a unified diff |
|
list files whose result differs |
|
report all errors, not only the first |
|
force the language |
|
process only names matching a comma-separated glob |
|
print version and build metadata |
|
show usage |
-w cannot combine with -d or -l; -d cannot combine with -l. Exit code
is 0 on success, 2 on a usage or processing error.
ANTLR lexers: Go, Java, C, C++, Kotlin, PostgreSQL, SQLite, SQL, TOML, HTML, XML. Delimiter scanner: Python, C#, PHP, Swift, Ruby, Shell, JSONC, YAML, Markdown, JavaScript, TypeScript, Rust, Scala.
Input must be valid UTF-8; a byte-order mark and a leading #! line are
preserved. -w writes a temporary file in the target directory and renames it,
keeping the file mode, and refuses a read-only file or a symbolic link.