AI 生成代码智能诊断引擎
72 条内置规则 · 支持 React / Vue / Svelte / HTML 多框架 · 零外部依赖
CodeLens-AI 是一款轻量级的 AI 生成代码智能诊断引擎,专为前端开发者打造。它能够自动检测 React、Vue、Svelte 和 HTML 组件代码中的质量问题,包括性能反模式、安全漏洞、可访问性问题和 AI 生成代码的典型特征。
灵感来源于 GitHub 热门项目 react-doctor,但做了全面的差异化升级:从仅支持 React 扩展到多框架支持,从 npm 包改为零依赖 Python CLI 工具,新增 AI 代码特征识别、自定义规则引擎和 TUI 交互界面。
# 克隆仓库
git clone https://github.com/gitstq/CodeLens-AI.git
cd CodeLens-AI
# 安装(可选)
pip install -e .
# 检查单个文件
python -m codelens_ai check src/App.jsx
# 扫描整个目录
python -m codelens_ai scan ./src --framework react
# 启动 TUI 交互界面
python -m codelens_ai tui
# 查看所有规则
python -m codelens_ai rules
# 输出 JSON 报告
python -m codelens_ai check src/App.jsx --output json > report.json
# 输出 HTML 报告
python -m codelens_ai scan ./src --output html --report-path ./report.html
# 指定最低严重级别
python -m codelens_ai scan ./src --severity warning
# 忽略特定规则
python -m codelens_ai scan ./src --ignore ai-006,ai-008
| 参数 | 说明 | 示例 |
|---|---|---|
scan <path> |
扫描文件或目录 | codelens scan ./src |
check <file> |
检查单个文件 | codelens check App.jsx |
tui |
启动 TUI 界面 | codelens tui |
rules |
列出所有规则 | codelens rules |
--framework |
指定框架 | --framework vue |
--severity |
最低报告级别 | --severity error |
--output |
输出格式 | --output json |
--config |
配置文件路径 | --config .codelens.yaml |
--ignore |
忽略规则 ID | --ignore react-001 |
--no-color |
禁用彩色输出 | --no-color |
# 框架配置
framework: auto # auto/react/vue/svelte/html
# 严重级别过滤
severity: warning # error/warning/info/hint
# 忽略规则
ignore:
- ai-006
- ai-008
# 规则配置覆盖
rules:
react-001:
severity: error
enabled: true
ai-009:
severity: hint
# 输出配置
output:
format: terminal # terminal/json/html
color: true
name: CodeLens AI Check
on: [push, pull_request]
jobs:
codelens:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -e .
- run: python -m codelens_ai scan ./src --output json --severity error > codelens-report.json
- run: |
if [ $? -ne 0 ]; then
echo "::error::CodeLens-AI detected code quality issues"
exit 1
fi
| 退出码 | 含义 |
|---|---|
| 0 | 未检测到问题 |
| 1 | 检测到警告级别问题 |
| 2 | 检测到错误级别问题 |
argparse 处理 CLI,re 处理正则分析,json 处理数据交换--fix 自动修复功能本项目为 Python CLI 工具,无需打包即可直接使用:
# 直接运行
python -m codelens_ai scan ./src
# 或安装后使用
pip install -e .
codelens scan ./src
兼容环境
欢迎贡献代码!请遵循以下步骤:
git checkout -b feature/amazing-rule)git commit -m 'feat: 添加新的诊断规则')git push origin feature/amazing-rule)提交规范:遵循 Angular 提交规范
feat: 新增功能fix: 修复问题docs: 文档更新refactor: 代码重构test: 测试相关chore: 构建/工具相关本项目基于 MIT License 开源。
CodeLens-AI 是一款輕量級的 AI 生成程式碼智慧診斷引擎,專為前端開發者打造。它能夠自動偵測 React、Vue、Svelte 和 HTML 元件程式碼中的品質問題,包括效能反模式、安全漏洞、無障礙性問題和 AI 生成程式碼的典型特徵。
靈感來源於 GitHub 熱門專案 react-doctor,但做了全面的差異化升級:從僅支援 React 擴展到多框架支援,從 npm 套件改為零依賴 Python CLI 工具,新增 AI 程式碼特徵識別、自訂規則引擎和 TUI 互動介面。
# 克隆倉庫
git clone https://github.com/gitstq/CodeLens-AI.git
cd CodeLens-AI
# 安裝(可選)
pip install -e .
# 檢查單個檔案
python -m codelens_ai check src/App.jsx
# 掃描整個目錄
python -m codelens_ai scan ./src --framework react
# 啟動 TUI 互動介面
python -m codelens_ai tui
# 查看所有規則
python -m codelens_ai rules
# 輸出 JSON 報告
python -m codelens_ai check src/App.jsx --output json > report.json
# 輸出 HTML 報告
python -m codelens_ai scan ./src --output html --report-path ./report.html
# 指定最低嚴重級別
python -m codelens_ai scan ./src --severity warning
# 忽略特定規則
python -m codelens_ai scan ./src --ignore ai-006,ai-008
| 參數 | 說明 | 範例 |
|---|---|---|
scan <path> |
掃描檔案或目錄 | codelens scan ./src |
check <file> |
檢查單個檔案 | codelens check App.jsx |
tui |
啟動 TUI 介面 | codelens tui |
rules |
列出所有規則 | codelens rules |
--framework |
指定框架 | --framework vue |
--severity |
最低報告級別 | --severity error |
--output |
輸出格式 | --output json |
--config |
設定檔路徑 | --config .codelens.yaml |
--ignore |
忽略規則 ID | --ignore react-001 |
--no-color |
停用彩色輸出 | --no-color |
# 框架設定
framework: auto # auto/react/vue/svelte/html
# 嚴重級別過濾
severity: warning # error/warning/info/hint
# 忽略規則
ignore:
- ai-006
- ai-008
# 規則設定覆蓋
rules:
react-001:
severity: error
enabled: true
ai-009:
severity: hint
# 輸出設定
output:
format: terminal # terminal/json/html
color: true
name: CodeLens AI Check
on: [push, pull_request]
jobs:
codelens:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -e .
- run: python -m codelens_ai scan ./src --output json --severity error > codelens-report.json
- run: |
if [ $? -ne 0 ]; then
echo "::error::CodeLens-AI detected code quality issues"
exit 1
fi
| 退出碼 | 含義 |
|---|---|
| 0 | 未偵測到問題 |
| 1 | 偵測到警告級別問題 |
| 2 | 偵測到錯誤級別問題 |
argparse 處理 CLI,re 處理正則分析,json 處理資料交換--fix 自動修復功能本專案為 Python CLI 工具,無需打包即可直接使用:
# 直接執行
python -m codelens_ai scan ./src
# 或安裝後使用
pip install -e .
codelens scan ./src
相容環境
歡迎貢獻程式碼!請遵循以下步驟:
git checkout -b feature/amazing-rule)git commit -m 'feat: 新增新的診斷規則')git push origin feature/amazing-rule)提交規範:遵循 Angular 提交規範
feat: 新增功能fix: 修復問題docs: 文件更新refactor: 程式碼重構test: 測試相關chore: 建構/工具相關本專案基於 MIT License 開源。
CodeLens-AI is a lightweight intelligent diagnostic engine for AI-generated code, built for frontend developers. It automatically detects quality issues in React, Vue, Svelte, and HTML component code — including performance anti-patterns, security vulnerabilities, accessibility problems, and telltale signs of AI-generated code.
Inspired by the popular GitHub project react-doctor, CodeLens-AI takes a fundamentally different approach: expanding from React-only to multi-framework support, replacing an npm package with a zero-dependency Python CLI tool, and introducing AI code pattern detection, a custom rule engine, and an interactive TUI.
# Clone the repository
git clone https://github.com/gitstq/CodeLens-AI.git
cd CodeLens-AI
# Install (optional)
pip install -e .
# Check a single file
python -m codelens_ai check src/App.jsx
# Scan an entire directory
python -m codelens_ai scan ./src --framework react
# Launch the TUI interface
python -m codelens_ai tui
# List all rules
python -m codelens_ai rules
# Output a JSON report
python -m codelens_ai check src/App.jsx --output json > report.json
# Output an HTML report
python -m codelens_ai scan ./src --output html --report-path ./report.html
# Set minimum severity level
python -m codelens_ai scan ./src --severity warning
# Ignore specific rules
python -m codelens_ai scan ./src --ignore ai-006,ai-008
| Argument | Description | Example |
|---|---|---|
scan <path> |
Scan files or directories | codelens scan ./src |
check <file> |
Check a single file | codelens check App.jsx |
tui |
Launch the TUI interface | codelens tui |
rules |
List all rules | codelens rules |
--framework |
Specify framework | --framework vue |
--severity |
Minimum report level | --severity error |
--output |
Output format | --output json |
--config |
Path to config file | --config .codelens.yaml |
--ignore |
Ignore rule IDs | --ignore react-001 |
--no-color |
Disable colorized output | --no-color |
# Framework configuration
framework: auto # auto/react/vue/svelte/html
# Severity level filter
severity: warning # error/warning/info/hint
# Ignored rules
ignore:
- ai-006
- ai-008
# Rule configuration overrides
rules:
react-001:
severity: error
enabled: true
ai-009:
severity: hint
# Output configuration
output:
format: terminal # terminal/json/html
color: true
name: CodeLens AI Check
on: [push, pull_request]
jobs:
codelens:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install -e .
- run: python -m codelens_ai scan ./src --output json --severity error > codelens-report.json
- run: |
if [ $? -ne 0 ]; then
echo "::error::CodeLens-AI detected code quality issues"
exit 1
fi
| Exit Code | Meaning |
|---|---|
| 0 | No issues detected |
| 1 | Warning-level issues detected |
| 2 | Error-level issues detected |
argparse for CLI, re for regex-based analysis, json for data exchange--fix auto-fix capabilityCodeLens-AI is a Python CLI tool that works out of the box — no packaging required:
# Run directly
python -m codelens_ai scan ./src
# Or install and use
pip install -e .
codelens scan ./src
Compatible Environments
Contributions are welcome! Please follow these steps:
git checkout -b feature/amazing-rule)git commit -m 'feat: add a new diagnostic rule')git push origin feature/amazing-rule)Commit Convention: Follow the Angular commit convention
feat: New featurefix: Bug fixdocs: Documentation updaterefactor: Code refactoringtest: Test-related changeschore: Build/tooling changesThis project is licensed under the MIT License.