2.2 KiB
2.2 KiB
name, description
| name | description |
|---|---|
| pre-commit-check | Run pre-commit code quality checks (ruff lint/format, mypy type check, deptry dependency audit) and fix any issues before committing. Use when the user wants to commit code, asks to check code quality, or mentions pre-commit validation. Also use when preparing code for submission or when the user says "check before commit" or "run checks". |
Pre-Commit Code Quality Check
Workflow
Run all checks in parallel first, then fix any issues iteratively:
Step 1: Run checks (parallel)
- uv run ruff check .
- uv run ruff format --check .
- uv run mypy src/
- uv run deptry .
Step 2: If any check fails, fix issues
- ruff check --fix . (auto-fix lint issues)
- ruff format . (auto-format)
- Fix type annotation errors manually
Step 3: Re-run all checks to confirm
Step 4: Report results with table
Common Fixes
| Error | Fix |
|---|---|
UP038 |
Replace isinstance(e, (X, Y)) with isinstance(e, X | Y) |
no-untyped-def |
Add return type annotation (-> None for void functions) |
I001 |
Run uv run ruff check --fix . |
no-any-return |
Use cast(Type, expression) from typing |
type-arg missing |
Add type arguments: dict[str, Any] instead of dict |
unused-ignore |
Remove stale # type: ignore comments |
Type Annotation Rules
- Functions that modify data in-place and return nothing:
-> None - Functions that call untyped external APIs: add
-> Anyreturn type - Dicts that hold mixed types (str + float): use
dict[str, Any] - Import
Anyfromtypingwhen needed - Import
castfromtypingwhenno-any-returntriggers
Verification Report
After all checks pass, report:
| 检查项 | 状态 |
|---|---|
ruff check . |
✅ |
ruff format --check . |
✅ |
mypy src/ |
✅ |
deptry . |
✅ |
Notes
- All commands use
uv runprefix (project virtual environment) mypyhasstrict = trueinpyproject.toml- expect strict type checkingignore_missing_imports = trueis set, so missing third-party stubs are OK- If
tests.*override shows "unused section" note, it's normal (no tests dir yet) - Never skip a check - all four must pass before committing