verify-quality

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Code 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
    ,
    *.rs
    - Source code
  • Focus on main implementation files, not tests
Directories to check:
  • src/
    ,
    lib/
    ,
    app/
    , project root
  • 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
[HEURISTIC]
— they require judgment. Tag findings with
[H]
.

此技能中的所有检查均为
[HEURISTIC]
(启发式检查)——需要主观判断。所有检查结果标记为
[H]

2.1
[HEURISTIC]
Naming Conventions

2.1
[HEURISTIC]
命名规范

Check for:
IssueExamples
Single-letter variables (except loops)
x = get_data()
,
d = {}
Unclear abbreviations
proc_usr_req()
,
calc_val()
Inconsistent casingMixing
camelCase
and
snake_case
in same file
Names that don't describe purpose
data
,
temp
,
result
,
info
Boolean names without is/has/can
enabled = check()
vs
is_enabled = check()
Good naming:
python
undefined
检查内容:
问题示例
单字母变量(循环除外)
x = get_data()
,
d = {}
模糊缩写
proc_usr_req()
,
calc_val()
大小写不一致同一文件中混合使用
camelCase
snake_case
名称无法描述用途
data
,
temp
,
result
,
info
布尔型名称未使用is/has/can前缀
enabled = check()
对比
is_enabled = check()
良好命名示例:
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

2.2
[HEURISTIC]
代码结构

Check for:
IssueDescription
Large files> 500 lines for a single module
Large functions> 50 lines for a single function
Deep nesting> 4 levels of indentation
Mixed concernsBusiness logic mixed with I/O in same function
God objectsClasses 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

2.3
[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

2.4
[HEURISTIC]
文档

Check for:
MissingWhere expected
Module docstringTop of
.py
files
Class docstringAfter
class
definition
Function docstringAfter
def
for public functions
READMEProject root
Type hintsPublic function parameters/returns
Examples:
python
undefined
检查内容:
缺失项预期位置
模块文档字符串
.py
文件顶部
类文档字符串
class
定义之后
函数文档字符串公共函数的
def
定义之后
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

2.5
[HEURISTIC]
错误处理

Check for:
IssueDescription
Bare except
except:
without specific exception
Silent failures
except: pass
Generic exceptions raised
raise Exception("...")
No error handlingFunctions that can fail but don't handle errors
Examples:
python
undefined
检查内容:
问题描述
裸except
except:
未指定具体异常
静默失败
except: pass
抛出通用异常
raise Exception("...")
无错误处理可能失败但未处理错误的函数
示例:
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

2.6
[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

2.7
[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
undefined
markdown
undefined

Code 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
    [file:line]
    ([X] lines)
  • 代码结构良好
  • ⚠️
    [文件:行号]
    处存在大函数([X]行)

Documentation

文档

  • Key functions documented
  • ⚠️ Missing docstring at
    [file:line]
  • 关键函数已添加文档
  • ⚠️
    [文件:行号]
    处缺失文档字符串

Error Handling

错误处理

  • Errors properly handled
  • ⚠️ Bare except at
    [file:line]
  • 错误处理得当
  • ⚠️
    [文件:行号]
    处存在裸except

Findings

检查结果

[H]
= heuristic (all quality checks require judgment)
[H]
= 启发式检查(所有质量检查均需主观判断)

✅ Passing

✅ 通过项

  • [H]
    Consistent naming conventions throughout
  • [H]
    Functions are well-scoped and focused
  • [H]
    全程命名规范一致
  • [H]
    函数范围明确、关注点单一

⚠️ Warnings

⚠️ 警告项

  • [H]
    [Check]: [description]
    • Location: [file:line]
    • Impact: [why this matters]
    • Suggestion: [how to improve]
  • [H]
    [检查类型]: [描述]
    • 位置: [文件:行号]
    • 影响: [问题原因]
    • 建议: [改进方案]

Recommendations

建议

  1. [Priority recommendation]
  2. [Additional improvements]

---

*For full verification including security, patterns, and language-specific checks, say "verify agent".*
  1. [优先级建议]
  2. [其他改进建议]

---

*如需包含安全、模式和特定语言检查的完整验证,请说 "verify agent"。*