Files
ai-development-scaffold/.claude/hooks/pre-commit-tdd.sh
James Bland befb8fbaeb feat: initial Claude Code configuration scaffold
Comprehensive Claude Code guidance system with:

- 5 agents: tdd-guardian, code-reviewer, security-scanner, refactor-scan, dependency-audit
- 18 skills covering languages (Python, TypeScript, Rust, Go, Java, C#),
  infrastructure (AWS, Azure, GCP, Terraform, Ansible, Docker/K8s, Database, CI/CD),
  testing (TDD, UI, Browser), and patterns (Monorepo, API Design, Observability)
- 3 hooks: secret detection, auto-formatting, TDD git pre-commit
- Strict TDD enforcement with 80%+ coverage requirements
- Multi-model strategy: Opus for planning, Sonnet for execution (opusplan)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-20 15:47:34 -05:00

58 lines
1.6 KiB
Bash

#!/bin/bash
# Pre-commit hook to enforce TDD compliance
# Verifies that test files are modified alongside production code
set -e
# Get staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
# Separate test and production files
TEST_FILES=""
PROD_FILES=""
for file in $STAGED_FILES; do
case "$file" in
*test*.py|*_test.py|*tests/*.py)
TEST_FILES="$TEST_FILES $file"
;;
*.test.ts|*.test.tsx|*.spec.ts|*.spec.tsx|*/__tests__/*)
TEST_FILES="$TEST_FILES $file"
;;
*_test.rs|*/tests/*.rs)
TEST_FILES="$TEST_FILES $file"
;;
*.py|*.ts|*.tsx|*.js|*.jsx|*.rs)
# Skip __init__.py, conftest.py, config files
case "$file" in
*__init__.py|*conftest.py|*config*.py|*.config.ts|*.config.js)
;;
*)
PROD_FILES="$PROD_FILES $file"
;;
esac
;;
esac
done
# Check if we have production files without test files
if [ -n "$PROD_FILES" ] && [ -z "$TEST_FILES" ]; then
echo "TDD VIOLATION: Production code changed without test changes"
echo ""
echo "Production files modified:"
for file in $PROD_FILES; do
echo " - $file"
done
echo ""
echo "Please ensure you're following TDD:"
echo " 1. Write a failing test first (RED)"
echo " 2. Write minimum code to pass (GREEN)"
echo " 3. Refactor if needed (REFACTOR)"
echo ""
echo "If this is a legitimate exception (config, types, etc.), use:"
echo " git commit --no-verify"
exit 1
fi
exit 0