| Crates.io | uncomment |
| lib.rs | uncomment |
| version | 2.7.0 |
| created_at | 2025-03-08 08:03:15.999862+00 |
| updated_at | 2025-09-11 06:53:54.26207+00 |
| description | A CLI tool to remove comments from code using tree-sitter for accurate parsing |
| homepage | |
| repository | https://github.com/Goldziher/uncomment |
| max_upload_size | |
| id | 1584182 |
| size | 15,920,210 |
A fast, accurate, and extensible comment removal tool that uses tree-sitter for parsing, ensuring 100% accuracy in comment identification. Originally created to clean up AI-generated code with excessive comments, it now supports any language with a tree-sitter grammar through its flexible configuration system.
If you find uncomment helpful, please consider sponsoring the development:
Your support helps maintain and improve this tool for the community! 🚀
Through the configuration system, you can add support for any language with a tree-sitter grammar, including:
brew tap goldziher/tap
brew install uncomment
cargo install uncomment
npm install -g uncomment-cli
pip install uncomment
git clone https://github.com/Goldziher/uncomment.git
cd uncomment
cargo install --path .
# Generate a configuration file for your project
uncomment init
# Remove comments from files
uncomment src/
# Preview changes without modifying files
uncomment --dry-run src/
# Generate a smart configuration based on your project
uncomment init
# Generate a comprehensive configuration with all supported languages
uncomment init --comprehensive
# Interactive configuration setup
uncomment init --interactive
# Use a custom configuration file
uncomment --config my-config.toml src/
The init command intelligently detects languages in your project:
# Smart detection - analyzes your project and includes only detected languages
$ uncomment init
Detected languages in your project:
- 150 rust files
- 89 typescript files
- 45 python files
- 12 vue files (requires custom grammar)
- 8 dockerfile files (requires custom grammar)
Generated .uncommentrc.toml with configurations for detected languages.
# Comprehensive mode - includes configurations for 25+ languages
$ uncomment init --comprehensive
Generated comprehensive configuration with all supported languages.
# Specify output location
$ uncomment init --output config/uncomment.toml
# Force overwrite existing configuration
$ uncomment init --force
# Remove comments from a single file
uncomment file.py
# Preview changes without modifying files
uncomment --dry-run file.py
# Process multiple files
uncomment src/*.py
# Remove documentation comments/docstrings
uncomment --remove-doc file.py
# Remove TODO and FIXME comments
uncomment --remove-todo --remove-fixme file.py
# Add custom patterns to preserve
uncomment --ignore-patterns "HACK" --ignore-patterns "WARNING" file.py
# Process entire directory recursively
uncomment src/
# Use parallel processing with 8 threads
uncomment --threads 8 src/
# Benchmark performance on a large codebase
uncomment benchmark --target /path/to/repo --iterations 3
# Profile performance with detailed analysis
uncomment profile /path/to/repo
~keep--remove-todo)--remove-fixme)--remove-doc)The tool preserves all linting and formatting directives to ensure your CI/CD pipelines and development workflows remain intact:
Go:
//nolint, //nolint:gosec, //golangci-lint, //staticcheck, //go:generatePython:
# noqa, # type: ignore, # mypy:, # pyright:, # ruff:, # pylint:, # flake8:# fmt: off/on, # black:, # isort:, # bandit:, # pyre-ignoreJavaScript/TypeScript:
eslint-disable, eslint-enable, eslint-disable-next-line@ts-ignore, @ts-expect-error, @ts-nocheck, @ts-check/// <reference, /// <amd-module, /// <amd-dependencyprettier-ignore, biome-ignore, deno-lint-ignorev8 ignore, c8 ignore, istanbul ignoreRust:
#[allow], #[deny], #[warn], #[forbid], #[cfg]clippy::, #[rustfmt::skip]Java:
@SuppressWarnings, @SuppressFBWarnings, //noinspection, // checkstyle:C/C++:
// NOLINT, // NOLINTNEXTLINE, #pragma, // clang-format off/onShell/Bash:
# shellcheck disable, # hadolint ignoreYAML:
# yamllint disable/enableHCL/Terraform:
# tfsec:ignore, # checkov:skip, # trivy:ignore, # tflint-ignoreRuby:
# rubocop:disable/enable, # reek:, # standard:disable/enableUncomment uses a flexible TOML-based configuration system that allows you to customize behavior for your project.
Uncomment searches for configuration files in the following order:
--config path/to/config.toml.uncommentrc.toml in the current directory.uncommentrc.toml in parent directories (up to git root or filesystem root)~/.config/uncomment/config.toml (global configuration)[global]
remove_todos = false
remove_fixme = false
remove_docs = false
preserve_patterns = ["IMPORTANT", "NOTE", "WARNING"]
use_default_ignores = true
respect_gitignore = true
[languages.python]
extensions = ["py", "pyw", "pyi"]
preserve_patterns = ["noqa", "type:", "pragma:", "pylint:"]
[patterns."tests/**/*.py"]
# Keep all comments in test files
remove_todos = false
remove_fixme = false
remove_docs = false
You can extend support to any language with a tree-sitter grammar:
# Add Swift support via Git
[languages.swift]
name = "Swift"
extensions = ["swift"]
comment_nodes = ["comment", "multiline_comment"]
preserve_patterns = ["MARK:", "TODO:", "FIXME:", "swiftlint:"]
[languages.swift.grammar]
source = { type = "git", url = "https://github.com/alex-pinkus/tree-sitter-swift", branch = "main" }
# Use a local grammar
[languages.custom]
name = "Custom Language"
extensions = ["custom"]
comment_nodes = ["comment"]
[languages.custom.grammar]
source = { type = "local", path = "/path/to/tree-sitter-custom" }
# Use a pre-compiled library
[languages.proprietary]
name = "Proprietary Language"
extensions = ["prop"]
comment_nodes = ["comment"]
[languages.proprietary.grammar]
source = { type = "library", path = "/usr/local/lib/libtree-sitter-proprietary.so" }
When multiple configuration files are found, they are merged with the following precedence (highest to lowest):
.uncommentrc.toml files (closer to the file being processed wins)~/.config/uncomment/config.toml)Pattern-specific configurations override language configurations for matching files.
Unlike regex-based tools, uncomment uses tree-sitter to build a proper Abstract Syntax Tree (AST) of your code. This means it understands the difference between:
The tool is built with a modular, extensible architecture:
With the new configuration system, you can add languages without modifying code:
Add to your .uncommentrc.toml:
[languages.mylang]
name = "My Language"
extensions = ["ml", "mli"]
comment_nodes = ["comment"]
preserve_patterns = ["TODO", "FIXME"]
[languages.mylang.grammar]
source = { type = "git", url = "https://github.com/tree-sitter/tree-sitter-mylang", branch = "main" }
For frequently used languages:
Cargo.tomlsrc/grammar/mod.rssrc/languages/registry.rsAdd to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/Goldziher/uncomment
rev: v2.5.0
hooks:
- id: uncomment
Add to your lefthook.yml:
pre-commit:
commands:
uncomment:
run: uncomment {staged_files}
stage_fixed: true
For both hooks, install uncomment via pip:
pip install uncomment
While slightly slower than regex-based approaches due to parsing overhead, the tool is very fast and scales well with parallel processing:
Performance scales excellently with multiple threads:
| Thread Count | Files/Second | Speedup |
|---|---|---|
| 1 thread | 1,500 | 1.0x |
| 4 threads | 3,900 | 2.6x |
| 8 threads | 5,100 | 3.4x |
Benchmarks run on a large enterprise codebase with 5,000 mixed language files
Use the built-in tools to measure performance on your specific codebase:
# Basic benchmark
uncomment benchmark --target /path/to/repo
# Detailed benchmark with multiple iterations
uncomment benchmark --target /path/to/repo --iterations 5 --threads 8
# Memory and performance profiling
uncomment profile /path/to/repo
The accuracy gained through AST parsing is worth the small performance cost, and parallel processing makes it suitable for even the largest codebases.
uncomment/
├── src/ # Source code
├── tests/ # Integration tests
├── fixtures/ # Test fixtures
│ ├── languages/ # Language-specific test files
│ └── repos/ # Repository test configurations
├── bench/ # CLI benchmarking tool
├── benchmarks/ # Rust micro-benchmarks
├── test-repos/ # Manual testing scripts
└── scripts/ # Build and release scripts
The project includes two types of benchmarking tools:
bench/: Custom CLI benchmarking tool for testing real-world performance on large codebases. Use via cargo run --release --bin benchmark.benchmarks/: Standard Rust micro-benchmarks for testing specific functions and components. Run with cargo bench.# Run all tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Run integration tests (including network-dependent)
cargo test -- --ignored
MIT