AgentSkillsCN

validate-code

在完成Python代码的编写或修改后,可通过代码质量检查工具(如lint、format、type、docstring、doctest、test)对代码进行全方位验证,确保代码的健壮性与一致性。

SKILL.md
--- frontmatter
name: validate-code
version: 1.0.0
description: Run code validation checks (lint, format, type, docstring, doctest, test). Use when validating code quality after writing or modifying Python code.
user-invocable: true
argument-hint: "[--lint] [--format] [--type] [--docstring] [--doctest] [--test] [paths...]"

Validate

Run code validation checks via a single centralized script. All checks run independently — a failure in one does not prevent others from running.

Quick Reference

FlagCheckUnderlying Command
--lintLintinguv run ruff check
--formatFormattinguv run ruff format --check
--typeType checkinguv run ty check
--docstringDocstringsuv tool run pydoclint --style=google --allow-init-docstring=True
--doctestDoctest examplesuv run pytest --doctest-modules
--testTests + coverageuv run pytest --cov

Usage

bash
# Run all checks on project root
uv run python .claude/scripts/validate_code.py

# Run specific checks
uv run python .claude/scripts/validate_code.py --lint --type

# Run on specific path
uv run python .claude/scripts/validate_code.py --lint src/chain_reaction/

# Run on specific file
uv run python .claude/scripts/validate_code.py --docstring src/chain_reaction/utils/parser.py

# Run tests on specific directory
uv run python .claude/scripts/validate_code.py --test tests/unit/

Exit Codes

CodeMeaning
0All selected checks passed
1One or more checks failed

When to Use

  • After writing code — run all checks to verify quality
  • After modifying code — run checks scoped to changed files
  • Before committing — run full validation as a final gate
  • During review — verify code meets quality standards

Mutation Commands (Not Part of Validation)

The validate script is read-only — it checks but does not modify files. For auto-fixing, use these commands directly:

bash
uv run ruff check --fix <paths>   # auto-fix lint issues
uv run ruff format <paths>        # auto-format code