code-quality
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Quality Check
代码质量检查
This skill runs code quality tools (ruff, mypy, pytest) and optionally simplifies code.
本技能可运行代码质量工具(ruff、mypy、pytest)并可选择简化代码。
Usage
使用方法
/code-quality [options]/code-quality [选项]Options
选项
- or
--all: Run on all synapse/ files (default: recently modified files only)-a - : Skip code-simplifier agent (by default, code-simplifier runs after checks pass)
--no-simplify - or
--fix: Auto-fix ruff issues with-fflag--fix - or
--test: Run pytest after linting passes-t - : Run all checks including tests (equivalent to
--full)--fix --test
- 或
--all: 在所有synapse/文件上运行(默认:仅最近修改的文件)-a - : 跳过代码简化Agent(默认情况下,检查通过后会运行代码简化工具)
--no-simplify - 或
--fix: 使用-f标志自动修复ruff问题--fix - 或
--test: 代码检查通过后运行pytest-t - : 运行包括测试在内的所有检查(等效于
--full)--fix --test
Workflow
工作流程
Step 1: Identify Target Files
步骤1:确定目标文件
If flag is provided:
--all- Target all files in directory
synapse/
Otherwise:
- Run to get recently modified files
git diff --name-only HEAD~1 - Filter to only files in
.pyorsynapse/tests/
如果提供了标志:
--all- 目标为目录下的所有文件
synapse/
否则:
- 运行获取最近修改的文件
git diff --name-only HEAD~1 - 筛选出或
synapse/目录下的tests/文件.py
Step 2: Run Ruff Linter
步骤2:运行Ruff代码检查器
bash
ruff check [files]If flag is provided:
--fixbash
ruff check --fix [files]Report any errors found. If errors remain after fix, stop and report.
bash
ruff check [files]如果提供了标志:
--fixbash
ruff check --fix [files]报告发现的所有错误。如果修复后仍有错误,停止操作并报告。
Step 3: Run Mypy Type Checker
步骤3:运行Mypy类型检查器
bash
uv run mypy [files]Report any type errors found. If errors exist, stop and report.
bash
uv run mypy [files]报告发现的所有类型错误。如果存在错误,停止操作并报告。
Step 4: Run Tests (if --test or --full)
步骤4:运行测试(若使用--test或--full)
If or flag is provided AND ruff/mypy passed:
--test--fullbash
pytestFor running specific tests related to modified files:
bash
pytest tests/ -vReport any test failures.
如果提供了或标志,且ruff/mypy检查通过:
--test--fullbash
pytest针对修改文件运行特定测试:
bash
pytest tests/ -v报告所有测试失败情况。
Step 5: Run Code Simplifier (Default)
步骤5:运行代码简化工具(默认)
By default, run code-simplifier after all checks pass. Skip with flag.
--no-simplifyUse the agent to simplify the recently modified code:
code-simplifier:code-simplifierTask tool with subagent_type: code-simplifier:code-simplifier
Prompt: Simplify and refine the recently modified code in [files].
Look for opportunities to reduce duplication, simplify conditionals,
and improve readability while maintaining all functionality.默认情况下,所有检查通过后会运行代码简化工具。可使用标志跳过此步骤。
--no-simplify使用 Agent简化最近修改的代码:
code-simplifier:code-simplifierTask tool with subagent_type: code-simplifier:code-simplifier
Prompt: 简化并优化[files]中最近修改的代码。
寻找减少代码重复、简化条件判断、
提升可读性同时保留所有功能的优化点。Step 6: Report Results
步骤6:报告结果
Summarize:
- Number of files checked
- Ruff status (pass/fail, errors fixed if --fix)
- Mypy status (pass/fail)
- Pytest status (pass/fail, skipped if not run)
- Code simplifier status (run by default, skipped if --no-simplify)
汇总内容:
- 已检查的文件数量
- Ruff状态(通过/失败,若使用--fix则包含已修复错误数)
- Mypy状态(通过/失败)
- Pytest状态(通过/失败,未运行则显示已跳过)
- 代码简化工具状态(默认运行,若使用--no-simplify则显示已跳过)
Error Handling
错误处理
When errors are found:
- Ruff errors: If is provided, attempt auto-fix first. Report remaining errors with file:line format.
--fix - Mypy errors: Report type errors with file:line format. Suggest fixes based on error messages.
- Test failures: Report failed test names and assertion errors. Do NOT proceed to simplification if tests fail.
发现错误时:
- Ruff错误:如果提供了,先尝试自动修复。以文件:行号的格式报告剩余错误。
--fix - Mypy错误:以文件:行号的格式报告类型错误。根据错误信息给出修复建议。
- 测试失败:报告失败的测试名称和断言错误。如果测试失败,不继续执行代码简化步骤。
Examples
示例
Basic check on recent changes
对最近修改内容进行基础检查
/code-quality/code-qualityCheck all files with auto-fix
对所有文件进行检查并自动修复
/code-quality --all --fix/code-quality --all --fixFull quality check with tests
包含测试的完整质量检查
/code-quality --full/code-quality --fullRun with tests only
仅运行测试
/code-quality --test/code-quality --testSkip code simplification
跳过代码简化
/code-quality --no-simplify/code-quality --no-simplifyShorthand
简写命令
/lint # Same as /code-quality (includes simplification)
/check # Same as /code-quality
/lint -a -f # All files with auto-fix
/lint -t # With tests
/lint --full # Full check (--fix --test)
/lint --no-simplify # Skip simplification/lint # 与/code-quality功能相同(包含代码简化)
/check # 与/code-quality功能相同
/lint -a -f # 对所有文件进行检查并自动修复
/lint -t # 附带测试
/lint --full # 完整检查(--fix --test)
/lint --no-simplify # 跳过代码简化Tool Configuration
工具配置
This project uses the following configurations (from pyproject.toml):
本项目使用以下配置(来自pyproject.toml):
Ruff
Ruff
- Target: Python 3.10
- Line length: 88
- Rules: E, F, I, UP, B, SIM
- Ignored: E501, B008
- Excluded: synapse/proto/a2a_pb2*.py
- 目标版本:Python 3.10
- 行长度:88
- 规则:E、F、I、UP、B、SIM
- 忽略规则:E501、B008
- 排除文件:synapse/proto/a2a_pb2*.py
Mypy
Mypy
- Strict mode with disallow_untyped_defs
- Tests have relaxed rules (ignore_errors)
- Proto files excluded
- 严格模式,禁用无类型定义
- 测试文件规则放宽(忽略错误)
- 排除Proto文件
Pytest
Pytest
- asyncio_mode: auto
- Run with: or
pytestpytest tests/ -v
- asyncio_mode: auto
- 运行命令:或
pytestpytest tests/ -v