Skip to content

isaka-james/remove-comments

Repository files navigation

remove-comments

Every comment, gone. Nothing else touched.

A fast, zero dependency command line tool that removes comments from source code in 132 languages. Written in Rust. Safe by default.

CI License: MIT Rust 1.74+

Why

Comments are for people. Sometimes you need code without them: before publishing, before measuring, before feeding code to another tool. Removing them by hand is slow. Removing them with regular expressions breaks strings, URLs, and templates.

remove-comments understands each language. It knows that # port in a YAML value is data, that :// is a URL, that a Ruby heredoc is a string, and that eslint-disable keeps your build green.

Install

With Rust installed:

cargo install --path .

Or download a prebuilt binary from the releases page.

Usage

Preview first. Nothing is ever written without --write.

remove-comments src/
remove-comments preview

  found   src/app.js     12 comments   306 B
  found   src/main.rs     8 comments   174 B

  2 of 41 files have comments, 20 comments, 480 B
  nothing changed, run with --write to apply

Apply:

remove-comments --write src/

See exactly what changes:

remove-comments --diff src/

Guard a pipeline:

remove-comments --check src/ && echo "no comments"

Use it in a pipe:

cat build.log.py | remove-comments --stdin --lang python

What it keeps

Some comments are load bearing. These stay unless you say otherwise.

Kept by default Example Remove with
Shebang lines #!/usr/bin/env bash never removed
License headers /* Copyright ... */ --strip-license
Tool directives eslint-disable, noqa, go:build, shellcheck --strip-directives
Compiler pragmas {-# LANGUAGE #-}, {$MODE} --strip-directives

Documentation comments such as /// and /** */ are removed by default. Keep them with --keep-doc. Keep anything else with --keep <text>.

Safety

  • Preview is the default mode. Writing requires --write.
  • node_modules, target, dist, vendor and 60 other build and dependency directories are never entered. Open one deliberately with --allow <name>.
  • .git is never touched, even with --allow.
  • Binary, minified, generated, and lockfile content is detected and skipped.
  • Hidden files and symlinks are skipped unless you opt in.
  • Writes are atomic and preserve file permissions. --backup keeps a .orig copy.
  • When the parser is not sure, it keeps the comment. Corruption is the only failure that matters, so every uncertain case fails toward keeping your code intact.

Options

remove-comments [options] [path ...]
Option Meaning
-w, --write Apply changes
--check Exit 1 if comments are found
--diff Show removed and rewritten lines
--json Machine readable report
-b, --backup Keep a .orig copy of changed files
--keep <text> Keep comments containing text
--keep-doc Keep documentation comments
--allow / --deny <name> Manage protected directories
-l, --lang <name> Force a language
--list-languages Show all 132 languages

Run remove-comments --help for the full list.

Exit codes

Code Meaning
0 Success
1 Comments found, only with --check
2 Usage error
3 Some files could not be processed

Languages

All 132, from C to Zig, including template engines, shells, build files, and hardware description languages. The full table lives in docs/LANGUAGES.md.

Contributing

See CONTRIBUTING.md. The short version: the codebase contains zero comments on purpose, names carry the meaning, and every language rule ships with tests.

License

MIT

About

Say goodbye to comments with a click. Making code cleaner than your browser history.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

4 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages