Lightweight Frontend Component Code Quality Intelligent Diagnosis Engine
ComponentGuard 是一款轻量级前端组件代码质量智能诊断引擎,零外部依赖,纯 Python 标准库实现。支持 React (JSX/TSX)、Vue (SFC) 和 Svelte 三大主流框架的组件代码质量检测。
随着 AI 辅助编程工具的普及,AI 生成的组件代码往往存在各种反模式和潜在问题。ComponentGuard 旨在帮助开发者快速发现并修复这些问题,提升代码质量。
.map() 渲染中缺失的 key 属性0 && <JSX> 等常见 bugdocument.getElementById 等反模式# 克隆仓库
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
# 直接使用(无需安装)
python3 -m componentguard ./src
# 或安装为全局命令
pip install .
componentguard ./src
# 扫描当前目录
python3 -m componentguard
# 扫描指定目录
python3 -m componentguard ./src/components
# 扫描单个文件
python3 -m componentguard ./src/App.jsx
# 详细输出(含修复建议)
python3 -m componentguard ./src --verbose
# 仅扫描 React 文件
python3 -m componentguard ./src --framework react
# 禁用彩色输出
python3 -m componentguard ./src --no-color
# 导出 JSON 报告
python3 -m componentguard ./src --json report.json
# 导出 Markdown 报告
python3 -m componentguard ./src --md report.md
# 同时导出两种格式
python3 -m componentguard ./src --json report.json --md report.md
| 参数 | 说明 | 示例 |
|---|---|---|
path |
扫描路径(文件或目录) | ./src |
-v, --verbose |
显示详细修复建议 | --verbose |
--json FILE |
导出 JSON 报告 | --json report.json |
--md FILE |
导出 Markdown 报告 | --md report.md |
--no-color |
禁用彩色输出 | --no-color |
--framework |
仅扫描指定框架 | --framework react |
--version |
显示版本号 | --version |
| 级别 | 图标 | 说明 |
|---|---|---|
| ERROR | ✖ | 必须修复的严重问题 |
| WARNING | ⚠ | 建议修复的警告 |
| INFO | ℹ | 信息提示 |
| SUGGESTION | 💡 | 优化建议 |
1. CI/CD 集成
# GitHub Actions
- name: Run ComponentGuard
run: |
python3 -m componentguard ./src --json report.json --no-color
# 检查是否有 error 级别问题
python3 -c "import json; d=json.load(open('report.json')); exit(1 if d['summary']['total_errors'] > 0 else 0)"
2. Git Hook 集成
# .git/hooks/pre-commit
#!/bin/bash
python3 -m componentguard ./src --no-color
if [ $? -ne 0 ]; then
echo "❌ ComponentGuard found errors. Please fix before committing."
exit 1
fi
3. npm scripts 集成
{
"scripts": {
"lint:components": "python3 -m componentguard ./src --verbose"
}
}
| 选择 | 原因 |
|---|---|
| Python | 跨平台、开发者友好、标准库丰富 |
| 正则表达式 | 轻量级、零依赖、覆盖主流反模式 |
| CLI 工具 | 易于集成到各种工作流 |
--fix 自动修复功能.componentguardrc)--watch 监听模式# 从源码安装
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
pip install .
# 验证安装
componentguard --version
# 无需安装,直接运行
python3 componentguard/cli.py ./src
| 环境 | 版本 |
|---|---|
| Python | 3.9+ |
| 操作系统 | Windows / macOS / Linux |
| 前端框架 | React 16+ / Vue 2/3 / Svelte 3/4/5 |
欢迎社区贡献!请遵循以下规范:
git checkout -b feat/new-rulepython3 -m pytest tests/ -v本项目基于 MIT License 开源。
ComponentGuard 是一款輕量級前端元件程式碼品質智慧診斷引擎,零外部依賴,純 Python 標準函式庫實作。支援 React (JSX/TSX)、Vue (SFC) 和 Svelte 三大主流框架的元件程式碼品質檢測。
隨著 AI 輔助程式設計工具的普及,AI 生成的元件程式碼往往存在各種反模式和潛在問題。ComponentGuard 旨在幫助開發者快速發現並修復這些問題,提升程式碼品質。
.map() 渲染中缺失的 key 屬性0 && <JSX> 等常見 bugdocument.getElementById 等反模式# 克隆倉庫
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
# 直接使用(無需安裝)
python3 -m componentguard ./src
# 或安裝為全域命令
pip install .
componentguard ./src
# 掃描當前目錄
python3 -m componentguard
# 掃描指定目錄
python3 -m componentguard ./src/components
# 掃描單個檔案
python3 -m componentguard ./src/App.jsx
# 詳細輸出(含修復建議)
python3 -m componentguard ./src --verbose
# 僅掃描 React 檔案
python3 -m componentguard ./src --framework react
# 停用彩色輸出
python3 -m componentguard ./src --no-color
# 匯出 JSON 報告
python3 -m componentguard ./src --json report.json
# 匯出 Markdown 報告
python3 -m componentguard ./src --md report.md
# 同時匯出兩種格式
python3 -m componentguard ./src --json report.json --md report.md
| 參數 | 說明 | 範例 |
|---|---|---|
path |
掃描路徑(檔案或目錄) | ./src |
-v, --verbose |
顯示詳細修復建議 | --verbose |
--json FILE |
匯出 JSON 報告 | --json report.json |
--md FILE |
匯出 Markdown 報告 | --md report.md |
--no-color |
停用彩色輸出 | --no-color |
--framework |
僅掃描指定框架 | --framework react |
--version |
顯示版本號 | --version |
| 級別 | 圖示 | 說明 |
|---|---|---|
| ERROR | ✖ | 必須修復的嚴重問題 |
| WARNING | ⚠ | 建議修復的警告 |
| INFO | ℹ | 資訊提示 |
| SUGGESTION | 💡 | 優化建議 |
--fix 自動修復功能.componentguardrc)--watch 監聽模式# 從原始碼安裝
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
pip install .
# 驗證安裝
componentguard --version
| 環境 | 版本 |
|---|---|
| Python | 3.9+ |
| 作業系統 | Windows / macOS / Linux |
| 前端框架 | React 16+ / Vue 2/3 / Svelte 3/4/5 |
歡迎社群貢獻!請遵循以下規範:
git checkout -b feat/new-rulepython3 -m pytest tests/ -v本專案基於 MIT License 開源。
ComponentGuard is a lightweight frontend component code quality intelligent diagnosis engine with zero external dependencies, built entirely with Python's standard library. It supports React (JSX/TSX), Vue (SFC), and Svelte — the three most popular frontend frameworks.
With the rise of AI-assisted coding tools, AI-generated component code often contains anti-patterns and potential issues. ComponentGuard helps developers quickly identify and fix these problems to improve code quality.
.map() renders without key props0 && <JSX> and similar bugsdocument.getElementById and similar anti-patterns# Clone the repository
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
# Run directly (no installation needed)
python3 -m componentguard ./src
# Or install as a global command
pip install .
componentguard ./src
# Scan current directory
python3 -m componentguard
# Scan a specific directory
python3 -m componentguard ./src/components
# Scan a single file
python3 -m componentguard ./src/App.jsx
# Verbose output (with fix suggestions)
python3 -m componentguard ./src --verbose
# Only scan React files
python3 -m componentguard ./src --framework react
# Disable colored output
python3 -m componentguard ./src --no-color
# Export JSON report
python3 -m componentguard ./src --json report.json
# Export Markdown report
python3 -m componentguard ./src --md report.md
# Export both formats
python3 -m componentguard ./src --json report.json --md report.md
| Argument | Description | Example |
|---|---|---|
path |
Scan path (file or directory) | ./src |
-v, --verbose |
Show detailed fix suggestions | --verbose |
--json FILE |
Export JSON report | --json report.json |
--md FILE |
Export Markdown report | --md report.md |
--no-color |
Disable colored output | --no-color |
--framework |
Only scan specific framework | --framework react |
--version |
Show version | --version |
| Level | Icon | Description |
|---|---|---|
| ERROR | ✖ | Critical issues that must be fixed |
| WARNING | ⚠ | Issues recommended to fix |
| INFO | ℹ | Informational notices |
| SUGGESTION | 💡 | Optimization suggestions |
1. CI/CD Integration
# GitHub Actions
- name: Run ComponentGuard
run: |
python3 -m componentguard ./src --json report.json --no-color
python3 -c "import json; d=json.load(open('report.json')); exit(1 if d['summary']['total_errors'] > 0 else 0)"
2. Git Hook Integration
# .git/hooks/pre-commit
#!/bin/bash
python3 -m componentguard ./src --no-color
if [ $? -ne 0 ]; then
echo "❌ ComponentGuard found errors. Please fix before committing."
exit 1
fi
--fix auto-fix functionality.componentguardrc)--watch watch mode# Install from source
git clone https://github.com/gitstq/ComponentGuard.git
cd ComponentGuard
pip install .
# Verify installation
componentguard --version
| Environment | Version |
|---|---|
| Python | 3.9+ |
| OS | Windows / macOS / Linux |
| Frameworks | React 16+ / Vue 2/3 / Svelte 3/4/5 |
Contributions are welcome! Please follow these guidelines:
git checkout -b feat/new-rulepython3 -m pytest tests/ -vThis project is licensed under the MIT License.
Built with ❤️ by gitstq