#comments #pre-commit #cli #glob-pattern #command-line-tool #file-path

app uncomment

A cli tool to remove comments from code. Supports multiple languages.

3 stable releases

new 1.0.2 Mar 8, 2025

#124 in Command line utilities

Download history 281/week @ 2025-03-03

281 downloads per month

MIT license

130KB
3.5K SLoC

Rust 2.5K SLoC // 0.1% comments Shell 543 SLoC // 0.1% comments

Uncomment

uncomment is a fast, efficient CLI tool to remove comments from your source code files. It was created to solve the common problem of AI assistants adding excessive comments to generated code.

Features

  • Removes comments while preserving important metadata and directives
  • Supports multiple programming languages with language-specific awareness
  • Preserves code structure and whitespace
  • Handles complex cases like comments in strings and embedded comments
  • Language-specific smart defaults for preserving important comment patterns
  • Fast operation with glob pattern support for batch processing

Supported Languages

  • Rust (.rs)
  • C (.c, .h)
  • C++ (.cpp, .cc, .cxx, .hpp, .hxx)
  • Java (.java)
  • JavaScript (.js)
  • TypeScript (.ts)
  • Python (.py)
  • Ruby (.rb)
  • Go (.go)
  • Swift (.swift)

Installation

cargo install uncomment

From GitHub Releases

You can also download pre-built binaries directly from the GitHub Releases page.

Using as a Pre-commit Hook

To use uncomment as a pre-commit hook:

Add this to your .pre-commit-config.yaml:

- repo: https://github.com/Goldziher/uncomment
  rev: v1.0.2 # Use the latest version
  hooks:
    - id: uncomment
      # Optional: Add any arguments you want
      # args: [--remove-todo, --remove-fixme]

Note - the pre-commit hook relies on the rust toolchain being available on the system.

Usage

Basic usage:

uncomment path/to/file.rs             # Process a single file
uncomment src                         # Process all files in a directory (recursively)
uncomment src/*.rs                    # Process multiple files with a glob pattern
uncomment src/**/*.{js,ts}            # Process JavaScript and TypeScript files recursively

When given a directory path without glob patterns (like uncomment src), the tool automatically expands it to a recursive pattern (src/**/*) to process all files within that directory tree.

Command Line Options

Usage: uncomment [OPTIONS] <PATHS>...

Arguments:
  <PATHS>...  The file(s) to uncomment - can be file paths or glob patterns

Options:
  -r, --remove-todo          Whether to remove TODO comments [default: false]
  -f, --remove-fixme         Whether to remove FIXME comments [default: false]
  -d, --remove-doc           Whether to remove doc strings [default: false]
  -i, --ignore-patterns <IGNORE_PATTERNS>
                             Comment patterns to keep, e.g. "noqa:", "eslint-disable*", etc.
      --no-default-ignores   Disable language-specific default ignore patterns [default: false]
  -n, --dry-run              Dry run (don't modify files, just show what would be changed) [default: false]
  -h, --help                 Print help
  -V, --version              Print version

Smart Comment Preservation

By default, uncomment preserves:

  1. Comments containing ~keep~ explicitly marked for preservation
  2. TODO comments (unless --remove-todo is specified)
  3. FIXME comments (unless --remove-fixme is specified)
  4. Documentation comments/docstrings (unless --remove-doc is specified)
  5. Language-specific patterns (unless --no-default-ignores is specified), including:
    • Rust: #[, allow(, cfg_attr, etc.
    • Python: # noqa, # type:, # pylint:, etc.
    • JavaScript/TypeScript: @flow, @ts-ignore, eslint-disable, etc.
    • And many more for each supported language

Additional patterns can be preserved with the -i/--ignore-patterns option.

Examples

Remove all comments except TODOs, FIXMEs, and docstrings:

uncomment src/*.rs

Remove everything including doc strings, TODOs and FIXMEs:

uncomment src/*.py --remove-todo --remove-fixme --remove-doc

Keep comments containing certain patterns:

uncomment src/*.py -i "some-pattern"

Dry run (see what would change without modifying files):

uncomment src/*.js --dry-run

Disable language-specific default ignore patterns:

uncomment src/*.rs --no-default-ignores

License

MIT License

Dependencies

~3–12MB
~160K SLoC