🛡️ Code Quality Guardian (代码质量守护者)
Metadata
| Field | Value |
|---|
| Name | code-quality-guardian |
| Display Name |
代码质量守护者 |
|
Version | 1.0.0 |
|
Category | Development Tools |
|
Author | ClawHub |
|
License | MIT |
Description
A comprehensive code quality analysis tool supporting Python, JavaScript, and Go. It automatically detects code smells, complexity issues, security vulnerabilities, and style violations.
一款全面的代码质量分析工具,支持 Python、JavaScript 和 Go。自动检测代码异味、复杂度问题、安全漏洞和风格违规。
Features
English
- - Multi-language Support: Python, JavaScript/TypeScript, Go
- Code Smell Detection: Identifies anti-patterns and design issues
- Complexity Analysis: Cyclomatic and maintainability metrics via Radon
- Security Scanning: Detect vulnerabilities with Bandit
- Style Checking: PEP8, ESLint, and Go fmt compliance
- Comprehensive Reports: JSON, HTML, and console output formats
- CI/CD Integration: Easy integration with pipelines
- Configurable Rules: Customizable thresholds and rule sets
中文
- - 多语言支持: Python、JavaScript/TypeScript、Go
- 代码异味检测: 识别反模式和设计问题
- 复杂度分析: 通过 Radon 进行圈复杂度和可维护性指标分析
- 安全扫描: 使用 Bandit 检测安全漏洞
- 风格检查: 符合 PEP8、ESLint 和 Go fmt 规范
- 综合报告: JSON、HTML 和控制台输出格式
- CI/CD 集成: 易于集成到流水线
- 可配置规则: 可自定义阈值和规则集
Supported Languages
| Language | Tools Used | File Extensions |
|---|
| Python | flake8, pylint, bandit, radon, mypy | .py |
| JavaScript/TypeScript |
eslint, jshint | .js, .jsx, .ts, .tsx |
| Go | go vet, golint, staticcheck | .go |
Usage
Command Line Interface
CODEBLOCK0
Python API
CODEBLOCK1
Configuration File (.quality.yml)
CODEBLOCK2
Installation
CODEBLOCK3
Requirements
- - Python 3.8+
- flake8 >= 6.0.0
- pylint >= 2.17.0
- bandit >= 1.7.0
- radon >= 6.0.0
- mypy >= 1.0.0 (optional)
Report Types
Console Output (Default)
CODEBLOCK4
JSON Output
CODEBLOCK5
Exit Codes
| Code | Meaning |
|---|
| 0 | No issues found |
| 1 |
Issues found but within thresholds |
| 2 | Threshold exceeded |
| 3 | Configuration error |
| 4 | Tool execution error |
Integrations
GitHub Actions
CODEBLOCK6
Pre-commit Hook
CODEBLOCK7
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please read CONTRIBUTING.md for guidelines.
Changelog
v1.0.0
- - Initial release
- Support for Python, JavaScript, Go
- Multi-format reporting
- CI/CD integration support
🛡️ Code Quality Guardian (代码质量守护者)
元数据
| 字段 | 值 |
|---|
| 名称 | code-quality-guardian |
| 显示名称 |
代码质量守护者 |
|
版本 | 1.0.0 |
|
分类 | 开发工具 |
|
作者 | ClawHub |
|
许可证 | MIT |
描述
一款全面的代码质量分析工具,支持 Python、JavaScript 和 Go。自动检测代码异味、复杂度问题、安全漏洞和风格违规。
功能特性
英文
- - 多语言支持:Python、JavaScript/TypeScript、Go
- 代码异味检测:识别反模式和设计问题
- 复杂度分析:通过 Radon 进行圈复杂度和可维护性指标分析
- 安全扫描:使用 Bandit 检测安全漏洞
- 风格检查:符合 PEP8、ESLint 和 Go fmt 规范
- 综合报告:JSON、HTML 和控制台输出格式
- CI/CD 集成:易于集成到流水线
- 可配置规则:可自定义阈值和规则集
中文
- - 多语言支持:Python、JavaScript/TypeScript、Go
- 代码异味检测:识别反模式和设计问题
- 复杂度分析:通过 Radon 进行圈复杂度和可维护性指标分析
- 安全扫描:使用 Bandit 检测安全漏洞
- 风格检查:符合 PEP8、ESLint 和 Go fmt 规范
- 综合报告:JSON、HTML 和控制台输出格式
- CI/CD 集成:易于集成到流水线
- 可配置规则:可自定义阈值和规则集
支持的语言
| 语言 | 使用的工具 | 文件扩展名 |
|---|
| Python | flake8、pylint、bandit、radon、mypy | .py |
| JavaScript/TypeScript |
eslint、jshint | .js、.jsx、.ts、.tsx |
| Go | go vet、golint、staticcheck | .go |
使用方法
命令行界面
bash
分析 Python 项目
code-quality-guardian analyze --path ./my-project --language python
仅使用特定工具进行分析
code-quality-guardian analyze --path ./src --tools flake8,bandit
生成 HTML 报告
code-quality-guardian analyze --path . --format html --output report.html
检查特定复杂度阈值
code-quality-guardian analyze --path . --max-complexity 10
Python API
python
from codequalityguardian import QualityAnalyzer
初始化分析器
analyzer = QualityAnalyzer(
language=python,
tools=[flake8, pylint, bandit],
config_path=.quality.yml
)
运行分析
results = analyzer.analyze(./src)
生成报告
report = results.to_json()
print(f发现的问题数:{results.total_issues})
print(f复杂度评分:{results.complexity_score})
配置文件 (.quality.yml)
yaml
language: python
tools:
- flake8
- pylint
- bandit
- radon
thresholds:
max_complexity: 10
maxlinelength: 100
min_score: 8.0
ignore:
- /tests/
- /migrations/
- /venv/
flake8:
maxlinelength: 100
ignore: [E501, W503]
pylint:
disable: [C0103, R0903]
bandit:
severity: MEDIUM
confidence: MEDIUM
安装
bash
从 ClawHub 安装
clawhub install code-quality-guardian
或手动安装依赖
pip install -r requirements.txt
系统要求
- - Python 3.8+
- flake8 >= 6.0.0
- pylint >= 2.17.0
- bandit >= 1.7.0
- radon >= 6.0.0
- mypy >= 1.0.0(可选)
报告类型
控制台输出(默认)
═══════════════════════════════════════════
Code Quality Guardian v1.0.0
═══════════════════════════════════════════
📁 项目:my-project
🔤 语言:python
📊 分析文件数:42
┌─────────────────────────────────────────┐
│ 问题摘要 │
├─────────────────────────────────────────┤
│ 🔴 严重 0 │
│ 🟠 高 2 │
│ 🟡 中 8 │
│ 🔵 低 15 │
│ 💡 信息 23 │
├─────────────────────────────────────────┤
│ 总计:48 │
└─────────────────────────────────────────┘
复杂度:7.2/10(良好)
可维护性:A
安全评分:95%
JSON 输出
json
{
summary: {
files_analyzed: 42,
total_issues: 48,
critical: 0,
high: 2,
medium: 8,
low: 15,
info: 23
},
metrics: {
complexity: 7.2,
maintainability: A,
security_score: 95
},
issues: [...]
}
退出代码
发现问题但未超出阈值 |
| 2 | 超出阈值 |
| 3 | 配置错误 |
| 4 | 工具执行错误 |
集成
GitHub Actions
yaml
uses: clawhub/code-quality-guardian@v1
with:
language: python
path: ./src
fail-on: high
Pre-commit 钩子
yaml
repos:
- repo: https://github.com/clawhub/code-quality-guardian
rev: v1.0.0
hooks:
- id: quality-guardian
args: [--language, python]
许可证
MIT 许可证 - 详见 LICENSE 文件。
贡献指南
欢迎贡献!请阅读 CONTRIBUTING.md 了解指南。
更新日志
v1.0.0
- - 初始版本
- 支持 Python、JavaScript、Go
- 多格式报告
- CI/CD 集成支持