verify-quality
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Quality Verification
代码质量验证
Purpose
目的
Verify code for quality anti-patterns including poor naming, missing documentation, magic values, and organizational issues. All analysis happens locally.
验证代码中的质量反模式,包括命名不佳、缺失文档、魔法值以及代码结构问题。所有分析均在本地进行。
When to Use
使用场景
Trigger this skill when the user asks to:
- "verify agent quality"
- "verify quality"
- "check code quality"
- "review code organization"
- "check naming conventions"
Note: For full verification including security, patterns, and language-specific checks, tell the user to say "verify agent".
当用户提出以下请求时触发此技能:
- "verify agent quality"
- "verify quality"
- "check code quality"
- "review code organization"
- "check naming conventions"
注意: 如需包含安全、模式和特定语言检查的完整验证,请告知用户说 "verify agent"。
Process
流程
Step 1: Discover Files
步骤1:发现文件
Locate files to analyze:
Source files:
- ,
*.py,*.ts,*.js,*.go- Source code*.rs - Focus on main implementation files, not tests
Directories to check:
- ,
src/,lib/, project rootapp/ - ,
agent/,tools/utils/
Exclude:
- ,
node_modules/,.venv/,venv/__pycache__/ - Test files (,
*.test.*,*.spec.*)*_test.go - Generated files, migrations
定位需要分析的文件:
源文件:
- ,
*.py,*.ts,*.js,*.go- 源代码*.rs - 重点关注主实现文件,而非测试文件
需检查的目录:
- ,
src/,lib/, 项目根目录app/ - ,
agent/,tools/utils/
排除项:
- ,
node_modules/,.venv/,venv/__pycache__/ - 测试文件(,
*.test.*,*.spec.*)*_test.go - 生成文件、迁移文件
Step 2: Run Quality Checks
步骤2:执行质量检查
All checks in this skill are — they require judgment. Tag findings with .
[HEURISTIC][H]此技能中的所有检查均为 (启发式检查)——需要主观判断。所有检查结果标记为 。
[HEURISTIC][H]2.1 [HEURISTIC]
Naming Conventions
[HEURISTIC]2.1 [HEURISTIC]
命名规范
[HEURISTIC]Check for:
| Issue | Examples |
|---|---|
| Single-letter variables (except loops) | |
| Unclear abbreviations | |
| Inconsistent casing | Mixing |
| Names that don't describe purpose | |
| Boolean names without is/has/can | |
Good naming:
python
undefined检查内容:
| 问题 | 示例 |
|---|---|
| 单字母变量(循环除外) | |
| 模糊缩写 | |
| 大小写不一致 | 同一文件中混合使用 |
| 名称无法描述用途 | |
| 布尔型名称未使用is/has/can前缀 | |
良好命名示例:
python
undefined✅ Clear, descriptive
✅ 清晰、具有描述性
user_profile = get_user_profile(user_id)
is_authenticated = check_authentication(token)
max_retry_attempts = 3
user_profile = get_user_profile(user_id)
is_authenticated = check_authentication(token)
max_retry_attempts = 3
⚠️ Unclear
⚠️ 模糊不清
x = get_up(uid)
auth = check(t)
n = 3
Severity: ⚠️ Warning
---x = get_up(uid)
auth = check(t)
n = 3
严重程度:⚠️ 警告
---2.2 [HEURISTIC]
Code Organization
[HEURISTIC]2.2 [HEURISTIC]
代码结构
[HEURISTIC]Check for:
| Issue | Description |
|---|---|
| Large files | > 500 lines for a single module |
| Large functions | > 50 lines for a single function |
| Deep nesting | > 4 levels of indentation |
| Mixed concerns | Business logic mixed with I/O in same function |
| God objects | Classes with > 10 public methods or > 20 attributes |
Example issues:
python
undefined检查内容:
| 问题 | 描述 |
|---|---|
| 大文件 | 单个模块超过500行 |
| 大函数 | 单个函数超过50行 |
| 深层嵌套 | 缩进层级超过4层 |
| 关注点混合 | 同一函数中混合业务逻辑与I/O操作 |
| 上帝对象 | 包含超过10个公共方法或20个属性的类 |
问题示例:
python
undefined⚠️ Warning - Deep nesting
⚠️ 警告 - 深层嵌套
def process(data):
if condition1:
if condition2:
for item in items:
if condition3:
if condition4: # Too deep
...
def process(data):
if condition1:
if condition2:
for item in items:
if condition3:
if condition4: # 层级过深
...
⚠️ Warning - Mixed concerns
⚠️ 警告 - 关注点混合
def save_user(user):
# Validation
if not user.email:
raise ValueError("...")
# Business logic
user.created_at = datetime.now()
# Database I/O
db.session.add(user)
db.session.commit()
# Email sending
send_welcome_email(user) # Multiple concerns
Severity: ⚠️ Warning
---def save_user(user):
# 验证逻辑
if not user.email:
raise ValueError("...")
# 业务逻辑
user.created_at = datetime.now()
# 数据库I/O
db.session.add(user)
db.session.commit()
# 邮件发送
send_welcome_email(user) # 多个关注点混合
严重程度:⚠️ 警告
---2.3 [HEURISTIC]
Magic Numbers and Strings
[HEURISTIC]2.3 [HEURISTIC]
魔法数字与字符串
[HEURISTIC]Check for:
- Numeric literals in code without constants
- String literals repeated multiple times
- Configuration values hardcoded in logic
Examples:
python
undefined检查内容:
- 代码中未使用常量的数值字面量
- 重复出现的字符串字面量
- 硬编码在逻辑中的配置值
示例:
python
undefined⚠️ Warning - Magic numbers
⚠️ 警告 - 魔法数字
if retry_count > 3: # What does 3 mean?
...
time.sleep(60) # Why 60?
if retry_count > 3: # 3代表什么?
...
time.sleep(60) # 为什么是60?
⚠️ Warning - Repeated strings
⚠️ 警告 - 重复字符串
if status == "pending":
...
elif status == "pending": # Typo risk
...
if status == "pending":
...
elif status == "pending": # 存在拼写错误风险
...
✅ Good - Named constants
✅ 良好 - 使用命名常量
MAX_RETRIES = 3
RETRY_DELAY_SECONDS = 60
STATUS_PENDING = "pending"
if retry_count > MAX_RETRIES:
...
time.sleep(RETRY_DELAY_SECONDS)
Severity: ⚠️ Warning
---MAX_RETRIES = 3
RETRY_DELAY_SECONDS = 60
STATUS_PENDING = "pending"
if retry_count > MAX_RETRIES:
...
time.sleep(RETRY_DELAY_SECONDS)
严重程度:⚠️ 警告
---2.4 [HEURISTIC]
Documentation
[HEURISTIC]2.4 [HEURISTIC]
文档
[HEURISTIC]Check for:
| Missing | Where expected |
|---|---|
| Module docstring | Top of |
| Class docstring | After |
| Function docstring | After |
| README | Project root |
| Type hints | Public function parameters/returns |
Examples:
python
undefined检查内容:
| 缺失项 | 预期位置 |
|---|---|
| 模块文档字符串 | |
| 类文档字符串 | |
| 函数文档字符串 | 公共函数的 |
| README | 项目根目录 |
| 类型提示 | 公共函数的参数/返回值 |
示例:
python
undefined⚠️ Warning - Missing docstrings
⚠️ 警告 - 缺失文档字符串
def calculate_score(user, items, weights):
total = 0
for item, weight in zip(items, weights):
total += item.value * weight
return total
def calculate_score(user, items, weights):
total = 0
for item, weight in zip(items, weights):
total += item.value * weight
return total
✅ Good - Documented
✅ 良好 - 已添加文档
def calculate_score(user: User, items: list[Item], weights: list[float]) -> float:
"""
Calculate weighted score for a user's items.
Args:
user: The user to calculate score for
items: List of items to score
weights: Weight multipliers for each item
Returns:
Total weighted score
"""
...
Severity: ⚠️ Warning
---def calculate_score(user: User, items: list[Item], weights: list[float]) -> float:
"""
计算用户物品的加权分数。
参数:
user: 要计算分数的用户
items: 待评分的物品列表
weights: 每个物品的权重乘数
返回:
总加权分数
"""
...
严重程度:⚠️ 警告
---2.5 [HEURISTIC]
Error Handling
[HEURISTIC]2.5 [HEURISTIC]
错误处理
[HEURISTIC]Check for:
| Issue | Description |
|---|---|
| Bare except | |
| Silent failures | |
| Generic exceptions raised | |
| No error handling | Functions that can fail but don't handle errors |
Examples:
python
undefined检查内容:
| 问题 | 描述 |
|---|---|
| 裸except | |
| 静默失败 | |
| 抛出通用异常 | |
| 无错误处理 | 可能失败但未处理错误的函数 |
示例:
python
undefined⚠️ Warning - Bare except
⚠️ 警告 - 裸except
try:
process_data()
except:
pass
try:
process_data()
except:
pass
⚠️ Warning - Generic exception
⚠️ 警告 - 通用异常
raise Exception("Something went wrong")
raise Exception("Something went wrong")
✅ Good - Specific handling
✅ 良好 - 特定异常处理
try:
process_data()
except ValueError as e:
logger.warning(f"Invalid data: {e}")
return default_value
except ConnectionError as e:
logger.error(f"Connection failed: {e}")
raise ServiceUnavailableError from e
Severity: ⚠️ Warning
---try:
process_data()
except ValueError as e:
logger.warning(f"Invalid data: {e}")
return default_value
except ConnectionError as e:
logger.error(f"Connection failed: {e}")
raise ServiceUnavailableError from e
严重程度:⚠️ 警告
---2.6 [HEURISTIC]
Code Duplication
[HEURISTIC]2.6 [HEURISTIC]
代码重复
[HEURISTIC]Check for:
- Identical or near-identical code blocks (> 5 lines)
- Copy-pasted functions with minor variations
- Repeated patterns that could be abstracted
Example:
python
undefined检查内容:
- 完全或近乎完全相同的代码块(超过5行)
- 复制粘贴后仅做微小修改的函数
- 可抽象的重复模式
示例:
python
undefined⚠️ Warning - Duplication
⚠️ 警告 - 代码重复
def get_user_by_id(user_id):
response = requests.get(f"{BASE_URL}/users/{user_id}")
if response.status_code == 200:
return response.json()
return None
def get_order_by_id(order_id):
response = requests.get(f"{BASE_URL}/orders/{order_id}")
if response.status_code == 200:
return response.json()
return None
def get_user_by_id(user_id):
response = requests.get(f"{BASE_URL}/users/{user_id}")
if response.status_code == 200:
return response.json()
return None
def get_order_by_id(order_id):
response = requests.get(f"{BASE_URL}/orders/{order_id}")
if response.status_code == 200:
return response.json()
return None
✅ Good - Abstracted
✅ 良好 - 已抽象
def get_resource(resource_type: str, resource_id: str):
response = requests.get(f"{BASE_URL}/{resource_type}/{resource_id}")
if response.status_code == 200:
return response.json()
return None
Severity: ⚠️ Warning
---def get_resource(resource_type: str, resource_id: str):
response = requests.get(f"{BASE_URL}/{resource_type}/{resource_id}")
if response.status_code == 200:
return response.json()
return None
严重程度:⚠️ 警告
---2.7 [HEURISTIC]
Commented-Out Code
[HEURISTIC]2.7 [HEURISTIC]
注释掉的代码
[HEURISTIC]Check for:
- Large blocks of commented-out code (> 5 lines)
- TODO comments that are stale (months old if dates present)
- FIXME comments indicating known issues
Examples:
python
undefined检查内容:
- 大块注释掉的代码(超过5行)
- 过时的TODO注释(若有日期则超过数月)
- 指示已知问题的FIXME注释
示例:
python
undefined⚠️ Warning - Commented code should be removed
⚠️ 警告 - 应移除注释代码
def old_implementation():
def old_implementation():
for item in items:
for item in items:
process_item(item)
process_item(item)
return results
return results
⚠️ Warning - Stale TODO
⚠️ 警告 - 过时的TODO
TODO: Fix this before launch (added 2024-01-15)
TODO: Fix this before launch (added 2024-01-15)
✅ Acceptable - Brief explanatory comment
✅ 可接受 - 简短解释性注释
Note: Using legacy API format for backwards compatibility
Note: Using legacy API format for backwards compatibility
Severity: ⚠️ Warning
---
严重程度:⚠️ 警告
---Step 3: Generate Report
步骤3:生成报告
markdown
undefinedmarkdown
undefinedCode Quality Verification Report
代码质量验证报告
Project: [name or path]
Date: [current date]
Files analyzed: [count]
项目: [名称或路径]
日期: [当前日期]
分析文件数: [数量]
Summary
摘要
✅ X checks passed | ⚠️ Y warnings | ❌ Z issues
✅ X项检查通过 | ⚠️ Y项警告 | ❌ Z项问题
Naming
命名
- Naming conventions consistent
- ⚠️ Unclear names at
[file:line]
- 命名规范一致
- ⚠️ 处存在模糊名称
[文件:行号]
Organization
代码结构
- Code well-organized
- ⚠️ Large function at ([X] lines)
[file:line]
- 代码结构良好
- ⚠️ 处存在大函数([X]行)
[文件:行号]
Documentation
文档
- Key functions documented
- ⚠️ Missing docstring at
[file:line]
- 关键函数已添加文档
- ⚠️ 处缺失文档字符串
[文件:行号]
Error Handling
错误处理
- Errors properly handled
- ⚠️ Bare except at
[file:line]
- 错误处理得当
- ⚠️ 处存在裸except
[文件:行号]
Findings
检查结果
= heuristic (all quality checks require judgment)[H]
= 启发式检查(所有质量检查均需主观判断)[H]
✅ Passing
✅ 通过项
- Consistent naming conventions throughout
[H] - Functions are well-scoped and focused
[H]
- 全程命名规范一致
[H] - 函数范围明确、关注点单一
[H]
⚠️ Warnings
⚠️ 警告项
- [Check]: [description]
[H]- Location: [file:line]
- Impact: [why this matters]
- Suggestion: [how to improve]
- [检查类型]: [描述]
[H]- 位置: [文件:行号]
- 影响: [问题原因]
- 建议: [改进方案]
Recommendations
建议
- [Priority recommendation]
- [Additional improvements]
---
*For full verification including security, patterns, and language-specific checks, say "verify agent".*- [优先级建议]
- [其他改进建议]
---
*如需包含安全、模式和特定语言检查的完整验证,请说 "verify agent"。*