{"id":51026696,"url":"https://github.com/gitstq/stripcomment","last_synced_at":"2026-06-21T20:02:13.984Z","repository":{"id":361473380,"uuid":"1254595006","full_name":"gitstq/stripcomment","owner":"gitstq","description":"🧹 A powerful CLI tool to intelligently strip comments from source code while preserving strings and supporting 30+ programming languages","archived":false,"fork":false,"pushed_at":"2026-05-30T19:10:32.000Z","size":21,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-30T21:08:17.400Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gitstq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-30T19:09:41.000Z","updated_at":"2026-05-30T19:10:24.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gitstq/stripcomment","commit_stats":null,"previous_names":["gitstq/stripcomment"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gitstq/stripcomment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fstripcomment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fstripcomment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fstripcomment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fstripcomment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitstq","download_url":"https://codeload.github.com/gitstq/stripcomment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fstripcomment/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34623906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-21T02:00:05.568Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-06-21T20:02:13.247Z","updated_at":"2026-06-21T20:02:13.972Z","avatar_url":"https://github.com/gitstq.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/version-1.0.0-blue.svg\" alt=\"Version\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/python-3.10+-green.svg\" alt=\"Python\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/license-MIT-orange.svg\" alt=\"License\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/languages-30+-purple.svg\" alt=\"Languages\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"#english\"\u003eEnglish\u003c/a\u003e | \n  \u003ca href=\"#简体中文\"\u003e简体中文\u003c/a\u003e | \n  \u003ca href=\"#繁體中文\"\u003e繁體中文\u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n\u003ca name=\"english\"\u003e\u003c/a\u003e\n# 🧹 StripComment\n\n\u003e **Intelligently strip comments from source code while preserving strings and supporting 30+ programming languages.**\n\nStripComment is a powerful, lightweight CLI tool designed to remove comments from source code files with precision. It uses a state-machine parser to accurately identify and remove comments while preserving string literals, handling escape sequences, and offering flexible preservation options.\n\n## 🎉 Why StripComment?\n\n- **📦 Code Minification** - Prepare code for production by removing unnecessary comments\n- **🔍 Code Analysis** - Clean code before processing with analysis tools\n- **🔒 Privacy Protection** - Remove sensitive information hidden in comments\n- **📊 Documentation Generation** - Extract clean code for documentation purposes\n- **🚀 Build Optimization** - Reduce file size for faster loading\n\n## ✨ Core Features\n\n| Feature | Description |\n|---------|-------------|\n| 🗑️ **Smart Comment Removal** | Accurately removes single-line and multi-line comments |\n| 🔒 **String Preservation** | Intelligently preserves strings containing comment-like patterns |\n| 📚 **30+ Languages** | Supports Python, JavaScript, TypeScript, Java, C/C++, Go, Rust, and more |\n| 🎯 **Selective Preservation** | Keep docstrings, copyright notices, TODOs, and license headers |\n| 📊 **Statistics** | Detailed reports on comments removed, lines saved, bytes reduced |\n| 👀 **Dry Run Mode** | Preview changes without modifying files |\n| 🔄 **Batch Processing** | Process entire directories recursively |\n| ⚡ **Fast \u0026 Lightweight** | Pure Python, no external dependencies for core functionality |\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\n# Install from PyPI\npip install stripcomment\n\n# Or install with all optional dependencies\npip install \"stripcomment[all]\"\n```\n\n### Basic Usage\n\n```bash\n# Strip comments from a single file\nstripcomment strip script.py\n\n# Process a directory recursively\nstripcomment strip ./src --recursive\n\n# Preview changes without modifying files\nstripcomment strip script.py --dry-run\n\n# Preserve docstrings and TODOs\nstripcomment strip script.py --preserve-docstrings --preserve-todos\n```\n\n## 📖 Detailed Usage Guide\n\n### Command Reference\n\n#### `stripcomment strip`\n\nStrip comments from source code files.\n\n```bash\nstripcomment strip [OPTIONS] [PATH]\n```\n\n**Options:**\n\n| Option | Description |\n|--------|-------------|\n| `-o, --output PATH` | Output file or directory |\n| `-l, --language TEXT` | Force language (auto-detected by default) |\n| `--preserve-docstrings` | Preserve docstrings |\n| `--preserve-copyright` | Preserve copyright comments |\n| `--preserve-todos` | Preserve TODO/FIXME comments |\n| `--preserve-license` | Preserve license comments |\n| `-p, --preserve PATTERN` | Preserve comments matching regex pattern |\n| `--remove-blank-lines` | Remove blank lines after stripping |\n| `--minify` | Minify output (remove extra whitespace) |\n| `-d, --dry-run` | Preview changes without modifying files |\n| `-b, --backup` | Create .bak backup files |\n| `-r, --recursive` | Process directories recursively |\n| `-e, --extensions TEXT` | Comma-separated list of extensions to process |\n| `-V, --verbose` | Show detailed output |\n\n#### `stripcomment languages`\n\nList all supported programming languages.\n\n```bash\nstripcomment languages\n```\n\n#### `stripcomment stats`\n\nShow comment statistics for a file.\n\n```bash\nstripcomment stats script.py\n```\n\n### Python API\n\n```python\nfrom stripcomment import StripComment\nfrom stripcomment.languages import get_language_by_extension\n\n# Initialize with language config\nconfig = get_language_by_extension(\".py\")\nstripper = StripComment(config)\n\n# Strip comments from code string\ncode = '''\ndef hello():\n    \"\"\"Say hello.\"\"\"\n    # This is a comment\n    print(\"Hello, World!\")  # Inline comment\n'''\n\nresult = stripper.strip(code)\nprint(result.stripped_code)\nprint(f\"Comments removed: {result.comments_removed}\")\nprint(f\"Bytes saved: {result.bytes_saved}\")\n```\n\n### Examples\n\n#### Preserve Important Comments\n\n```bash\n# Keep copyright and license headers\nstripcomment strip ./src --preserve-copyright --preserve-license\n\n# Keep TODOs for future reference\nstripcomment strip ./src --preserve-todos\n\n# Custom preservation pattern\nstripcomment strip ./src --preserve \"@author\"\n```\n\n#### Batch Processing\n\n```bash\n# Process all Python files in a directory\nstripcomment strip ./project --recursive --extensions .py\n\n# Process multiple file types\nstripcomment strip ./project --recursive --extensions .py,.js,.ts\n\n# Create backups before processing\nstripcomment strip ./project --recursive --backup\n```\n\n#### Piped Input\n\n```bash\n# Pipe input\ncat script.py | stripcomment strip --language python\n\n# Combine with other tools\ncat script.py | stripcomment strip --language python \u003e clean.py\n```\n\n## 💡 Supported Languages\n\n| Category | Languages |\n|----------|-----------|\n| **Web** | JavaScript, TypeScript, HTML, CSS, PHP |\n| **Systems** | C, C++, Go, Rust, Assembly |\n| **Scripting** | Python, Ruby, Perl, Lua, R |\n| **JVM** | Java, Kotlin, Scala |\n| **Mobile** | Swift, Dart |\n| **Shell** | Bash, PowerShell |\n| **Data** | SQL, YAML, TOML, JSON5 |\n| **Other** | Haskell, Elixir, Erlang, Fortran, MATLAB, Julia, Vim Script |\n\n## 📦 Project Structure\n\n```\nstripcomment/\n├── src/stripcomment/\n│   ├── __init__.py      # Package initialization\n│   ├── core.py          # Core stripping logic\n│   ├── languages.py     # Language configurations\n│   └── cli.py           # Command-line interface\n├── tests/               # Test suite\n├── pyproject.toml       # Project configuration\n└── README.md            # Documentation\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'feat: add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n\u003ca name=\"简体中文\"\u003e\u003c/a\u003e\n# 🧹 StripComment\n\n\u003e **智能移除源代码中的注释，同时保护字符串内容，支持 30+ 编程语言。**\n\nStripComment 是一个强大、轻量级的命令行工具，专为精确移除源代码注释而设计。它使用状态机解析器准确识别并移除注释，同时保护字符串字面量、处理转义序列，并提供灵活的保留选项。\n\n## 🎉 为什么选择 StripComment？\n\n- **📦 代码压缩** - 移除不必要的注释，准备生产环境代码\n- **🔍 代码分析** - 在使用分析工具处理前清理代码\n- **🔒 隐私保护** - 移除隐藏在注释中的敏感信息\n- **📊 文档生成** - 提取干净的代码用于文档编写\n- **🚀 构建优化** - 减少文件大小，加快加载速度\n\n## ✨ 核心特性\n\n| 特性 | 描述 |\n|------|------|\n| 🗑️ **智能注释移除** | 精准移除单行和多行注释 |\n| 🔒 **字符串保护** | 智能保护包含注释模式的字符串 |\n| 📚 **30+ 语言** | 支持 Python、JavaScript、TypeScript、Java、C/C++、Go、Rust 等 |\n| 🎯 **选择性保留** | 保留文档字符串、版权声明、TODO 和许可证头 |\n| 📊 **统计报告** | 详细报告移除的注释数、节省的行数和字节数 |\n| 👀 **干运行模式** | 预览变更而不修改文件 |\n| 🔄 **批量处理** | 递归处理整个目录 |\n| ⚡ **快速轻量** | 纯 Python 实现，核心功能无外部依赖 |\n\n## 🚀 快速开始\n\n### 安装\n\n```bash\n# 从 PyPI 安装\npip install stripcomment\n\n# 或安装所有可选依赖\npip install \"stripcomment[all]\"\n```\n\n### 基本用法\n\n```bash\n# 从单个文件移除注释\nstripcomment strip script.py\n\n# 递归处理目录\nstripcomment strip ./src --recursive\n\n# 预览变更而不修改文件\nstripcomment strip script.py --dry-run\n\n# 保留文档字符串和 TODO\nstripcomment strip script.py --preserve-docstrings --preserve-todos\n```\n\n## 📖 详细使用指南\n\n### 命令参考\n\n#### `stripcomment strip`\n\n从源代码文件移除注释。\n\n```bash\nstripcomment strip [选项] [路径]\n```\n\n**选项：**\n\n| 选项 | 描述 |\n|------|------|\n| `-o, --output 路径` | 输出文件或目录 |\n| `-l, --language 语言` | 强制指定语言（默认自动检测） |\n| `--preserve-docstrings` | 保留文档字符串 |\n| `--preserve-copyright` | 保留版权注释 |\n| `--preserve-todos` | 保留 TODO/FIXME 注释 |\n| `--preserve-license` | 保留许可证注释 |\n| `-p, --preserve 模式` | 保留匹配正则表达式的注释 |\n| `--remove-blank-lines` | 移除注释后删除空行 |\n| `--minify` | 压缩输出（移除多余空白） |\n| `-d, --dry-run` | 预览变更而不修改文件 |\n| `-b, --backup` | 创建 .bak 备份文件 |\n| `-r, --recursive` | 递归处理目录 |\n| `-e, --extensions 扩展名` | 逗号分隔的扩展名列表 |\n| `-V, --verbose` | 显示详细输出 |\n\n#### `stripcomment languages`\n\n列出所有支持的编程语言。\n\n```bash\nstripcomment languages\n```\n\n#### `stripcomment stats`\n\n显示文件的注释统计信息。\n\n```bash\nstripcomment stats script.py\n```\n\n### Python API\n\n```python\nfrom stripcomment import StripComment\nfrom stripcomment.languages import get_language_by_extension\n\n# 使用语言配置初始化\nconfig = get_language_by_extension(\".py\")\nstripper = StripComment(config)\n\n# 从代码字符串移除注释\ncode = '''\ndef hello():\n    \"\"\"打招呼。\"\"\"\n    # 这是一个注释\n    print(\"你好，世界！\")  # 行内注释\n'''\n\nresult = stripper.strip(code)\nprint(result.stripped_code)\nprint(f\"移除的注释数: {result.comments_removed}\")\nprint(f\"节省的字节数: {result.bytes_saved}\")\n```\n\n### 示例\n\n#### 保留重要注释\n\n```bash\n# 保留版权和许可证头\nstripcomment strip ./src --preserve-copyright --preserve-license\n\n# 保留 TODO 以供后续参考\nstripcomment strip ./src --preserve-todos\n\n# 自定义保留模式\nstripcomment strip ./src --preserve \"@author\"\n```\n\n#### 批量处理\n\n```bash\n# 处理目录中的所有 Python 文件\nstripcomment strip ./project --recursive --extensions .py\n\n# 处理多种文件类型\nstripcomment strip ./project --recursive --extensions .py,.js,.ts\n\n# 处理前创建备份\nstripcomment strip ./project --recursive --backup\n```\n\n#### 管道输入\n\n```bash\n# 管道输入\ncat script.py | stripcomment strip --language python\n\n# 与其他工具组合\ncat script.py | stripcomment strip --language python \u003e clean.py\n```\n\n## 💡 支持的语言\n\n| 类别 | 语言 |\n|------|------|\n| **Web** | JavaScript, TypeScript, HTML, CSS, PHP |\n| **系统** | C, C++, Go, Rust, Assembly |\n| **脚本** | Python, Ruby, Perl, Lua, R |\n| **JVM** | Java, Kotlin, Scala |\n| **移动** | Swift, Dart |\n| **Shell** | Bash, PowerShell |\n| **数据** | SQL, YAML, TOML, JSON5 |\n| **其他** | Haskell, Elixir, Erlang, Fortran, MATLAB, Julia, Vim Script |\n\n## 🤝 贡献指南\n\n欢迎贡献代码！请随时提交 Pull Request。\n\n1. Fork 本仓库\n2. 创建特性分支 (`git checkout -b feature/amazing-feature`)\n3. 提交更改 (`git commit -m 'feat: add amazing feature'`)\n4. 推送到分支 (`git push origin feature/amazing-feature`)\n5. 打开 Pull Request\n\n## 📄 许可证\n\n本项目采用 MIT 许可证 - 详情请见 [LICENSE](LICENSE) 文件。\n\n---\n\n\u003ca name=\"繁體中文\"\u003e\u003c/a\u003e\n# 🧹 StripComment\n\n\u003e **智慧移除原始碼中的註解，同時保護字串內容，支援 30+ 程式語言。**\n\nStripComment 是一個強大、輕量級的命令列工具，專為精確移除原始碼註解而設計。它使用狀態機解析器準確識別並移除註解，同時保護字串字面量、處理轉義序列，並提供靈活的保留選項。\n\n## 🎉 為什麼選擇 StripComment？\n\n- **📦 程式碼壓縮** - 移除不必要的註解，準備生產環境程式碼\n- **🔍 程式碼分析** - 在使用分析工具處理前清理程式碼\n- **🔒 隱私保護** - 移除隱藏在註解中的敏感資訊\n- **📊 文件生成** - 提取乾淨的程式碼用於文件編寫\n- **🚀 建置最佳化** - 減少檔案大小，加快載入速度\n\n## ✨ 核心特性\n\n| 特性 | 描述 |\n|------|------|\n| 🗑️ **智慧註解移除** | 精準移除單行和多行註解 |\n| 🔒 **字串保護** | 智慧保護包含註解模式的字串 |\n| 📚 **30+ 語言** | 支援 Python、JavaScript、TypeScript、Java、C/C++、Go、Rust 等 |\n| 🎯 **選擇性保留** | 保留文件字串、版權宣告、TODO 和授權條款標頭 |\n| 📊 **統計報告** | 詳細報告移除的註解數、節省的行數和位元組數 |\n| 👀 **乾運行模式** | 預覽變更而不修改檔案 |\n| 🔄 **批次處理** | 遞迴處理整個目錄 |\n| ⚡ **快速輕量** | 純 Python 實作，核心功能無外部相依性 |\n\n## 🚀 快速開始\n\n### 安裝\n\n```bash\n# 從 PyPI 安裝\npip install stripcomment\n\n# 或安裝所有可選相依性\npip install \"stripcomment[all]\"\n```\n\n### 基本用法\n\n```bash\n# 從單一檔案移除註解\nstripcomment strip script.py\n\n# 遞迴處理目錄\nstripcomment strip ./src --recursive\n\n# 預覽變更而不修改檔案\nstripcomment strip script.py --dry-run\n\n# 保留文件字串和 TODO\nstripcomment strip script.py --preserve-docstrings --preserve-todos\n```\n\n## 📖 詳細使用指南\n\n### 命令參考\n\n#### `stripcomment strip`\n\n從原始碼檔案移除註解。\n\n```bash\nstripcomment strip [選項] [路徑]\n```\n\n**選項：**\n\n| 選項 | 描述 |\n|------|------|\n| `-o, --output 路徑` | 輸出檔案或目錄 |\n| `-l, --language 語言` | 強制指定語言（預設自動偵測） |\n| `--preserve-docstrings` | 保留文件字串 |\n| `--preserve-copyright` | 保留版權註解 |\n| `--preserve-todos` | 保留 TODO/FIXME 註解 |\n| `--preserve-license` | 保留授權條款註解 |\n| `-p, --preserve 模式` | 保留匹配正則表示式的註解 |\n| `--remove-blank-lines` | 移除註解後刪除空行 |\n| `--minify` | 壓縮輸出（移除多餘空白） |\n| `-d, --dry-run` | 預覽變更而不修改檔案 |\n| `-b, --backup` | 建立 .bak 備份檔案 |\n| `-r, --recursive` | 遞迴處理目錄 |\n| `-e, --extensions 副檔名` | 逗號分隔的副檔名列表 |\n| `-V, --verbose` | 顯示詳細輸出 |\n\n#### `stripcomment languages`\n\n列出所有支援的程式語言。\n\n```bash\nstripcomment languages\n```\n\n#### `stripcomment stats`\n\n顯示檔案的註解統計資訊。\n\n```bash\nstripcomment stats script.py\n```\n\n### Python API\n\n```python\nfrom stripcomment import StripComment\nfrom stripcomment.languages import get_language_by_extension\n\n# 使用語言設定初始化\nconfig = get_language_by_extension(\".py\")\nstripper = StripComment(config)\n\n# 從程式碼字串移除註解\ncode = '''\ndef hello():\n    \"\"\"打招呼。\"\"\"\n    # 這是一個註解\n    print(\"你好，世界！\")  # 行內註解\n'''\n\nresult = stripper.strip(code)\nprint(result.stripped_code)\nprint(f\"移除的註解數: {result.comments_removed}\")\nprint(f\"節省的位元組數: {result.bytes_saved}\")\n```\n\n## 💡 支援的語言\n\n| 類別 | 語言 |\n|------|------|\n| **Web** | JavaScript, TypeScript, HTML, CSS, PHP |\n| **系統** | C, C++, Go, Rust, Assembly |\n| **腳本** | Python, Ruby, Perl, Lua, R |\n| **JVM** | Java, Kotlin, Scala |\n| **行動** | Swift, Dart |\n| **Shell** | Bash, PowerShell |\n| **資料** | SQL, YAML, TOML, JSON5 |\n| **其他** | Haskell, Elixir, Erlang, Fortran, MATLAB, Julia, Vim Script |\n\n## 🤝 貢獻指南\n\n歡迎貢獻程式碼！請隨時提交 Pull Request。\n\n1. Fork 本儲存庫\n2. 建立特性分支 (`git checkout -b feature/amazing-feature`)\n3. 提交變更 (`git commit -m 'feat: add amazing feature'`)\n4. 推送到分支 (`git push origin feature/amazing-feature`)\n5. 開啟 Pull Request\n\n## 📄 授權條款\n\n本專案採用 MIT 授權條款 - 詳情請見 [LICENSE](LICENSE) 檔案。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Fstripcomment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitstq%2Fstripcomment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Fstripcomment/lists"}