{{cookiecutter.project_name}}/.claude/skills/code-quality-gate/SKILL.md
Automated code quality checks before commits. Use before committing code, when finishing a feature, or when user mentions "ready to commit" or "quality check".
npx skillsauth add afaneor/fastapi-docker-boilerplate code-quality-gateInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Before ANY commit, code must pass ALL stages. No exceptions.
poetry run ruff format .
What it checks:
Action: Auto-fixes issues. Re-run if changes were made.
poetry run ruff check . --fix
What it checks:
Action: Auto-fixes when possible. Manual fixes required for some issues.
poetry run mypy app/ --ignore-missing-imports || true
What it checks:
Action: Fix type errors. Use # type: ignore only as last resort with comment explaining why.
poetry run pytest tests/ -v --maxfail=1
What it checks:
Action: Fix failing tests. Never skip tests.
poetry run ruff check . --select I --fix
What it checks:
Action: Auto-fixes import order.
Run all stages in sequence:
poetry run ruff format . && \
poetry run ruff check . --fix && \
poetry run pytest tests/ -v && \
echo "✅ All quality checks passed!"
# Before git commit
./run_quality_gate.sh
git add .
git commit -m "feat: add user endpoint"
# After large code changes
poetry run pytest tests/ -v --cov=app --cov-report=html
# Full comprehensive check
poetry run ruff check . --statistics
poetry run pytest tests/ -v --cov=app --cov-report=term-missing
If ruff format makes changes:
poetry run ruff format .
git add . # Stage formatted files
Read error messages carefully:
app/api/users.py:45:5: F401 'User' imported but unused
Fix the issue:
# Remove unused import
# from models import User ← Remove this
FAILED tests/test_users.py::test_get_user - AssertionError: ...
Debug and fix:
# Run specific test with output
poetry run pytest tests/test_users.py::test_get_user -v -s
app/api/users.py:45: error: Incompatible return value type
Fix type annotations:
# Before (wrong)
def get_user(id) -> User:
return None # Error: None is not User!
# After (correct)
def get_user(id: int) -> User | None:
return None # OK: None is allowed
Maintain minimum test coverage:
Check coverage:
poetry run pytest tests/ --cov=app --cov-report=term-missing
In rare cases when quality gate blocks urgent fixes:
# Skip only specific check
poetry run ruff check . --ignore E501 # Ignore line length
# Or commit with --no-verify (DOCUMENT WHY!)
git commit -m "hotfix: critical bug" --no-verify
Rules for bypass:
All of these must be true:
ruff format . makes zero changesruff check . returns zero errorsmypy app/ returns zero errors (if enabled)pytest tests/ all tests passpoetry install # Install dependencies first
# Check test file naming
# Must be: test_*.py or *_test.py
ls tests/
# Set PYTHONPATH
export PYTHONPATH="${PYTHONPATH}:$(pwd)"
poetry run pytest tests/
# Run in parallel
poetry run pytest tests/ -n auto
# Run only fast tests
poetry run pytest tests/ -m "not slow"
Create .git/hooks/pre-commit:
#!/bin/bash
echo "Running quality gate..."
poetry run ruff format .
poetry run ruff check . --fix
poetry run pytest tests/ -v --maxfail=1
if [ $? -ne 0 ]; then
echo "❌ Quality gate failed. Commit blocked."
exit 1
fi
echo "✅ Quality gate passed!"
Make it executable:
chmod +x .git/hooks/pre-commit
Quality gate should also run in CI:
# .github/workflows/quality.yml
name: Quality Gate
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: poetry install
- run: poetry run ruff format . --check
- run: poetry run ruff check .
- run: poetry run pytest tests/ --cov=app
Quality gate is not optional. It's the foundation of production-ready code.
No shortcuts. No bypasses. No "I'll fix it later."
✅ Write code → Run quality gate → Fix issues → Commit → Repeat
development
Enforces type hints, docstrings, and Python best practices. Use when writing or refactoring Python code, creating new functions, or when user mentions "production-ready" or "type-safe" code.
development
Detects API keys, passwords, and secrets in code before they reach git. Use before commits, when working with credentials, or when user mentions "security check" or "secrets".
development
Maintainer-only workflow for handling GitHub Secret Scanning alerts on OpenClaw. Use when Codex needs to triage, redact, clean up, and resolve secret leakage found in issue comments, issue bodies, PR comments, or other GitHub content.
development
Maintainer workflow for OpenClaw releases, prereleases, changelog release notes, and publish validation. Use when Codex needs to prepare or verify stable or beta release steps, align version naming, assemble release notes, check release auth requirements, or validate publish-time commands and artifacts.