arbret/.githooks/pre-commit
counterweight 63a4b0f8a2
Add translation validation git hook
- Create validate-translations.js script to check all translation keys exist in all locales
- Add translation validation to pre-commit hook
- Validates that es, en, ca translation files have matching keys
- Blocks commits if translations are missing or inconsistent
- Prevents incomplete translations from being committed
2025-12-26 11:58:09 +01:00

54 lines
1.7 KiB
Bash
Executable file

#!/bin/bash
# Pre-commit hook to run code quality tools and ensure generated types are up-to-date
set -e
# Get the root of the repository
REPO_ROOT="$(git rev-parse --show-toplevel)"
cd "$REPO_ROOT"
echo "🔧 Running code quality checks (ruff, mypy, bandit, eslint, prettier)..."
echo ""
# Run pre-commit framework hooks on staged files
cd backend && uv run pre-commit run
cd "$REPO_ROOT"
echo ""
echo "🔍 Checking if generated types are fresh..."
# Check if api.ts is staged
if git diff --cached --name-only | grep -q "frontend/app/generated/api.ts"; then
echo "✓ Generated types are staged"
else
# Check if backend schema files have changed
if git diff --cached --name-only | grep -qE "backend/(schemas|models|routes)"; then
# Check if api.ts has unstaged changes (meaning types need to be staged)
if git diff --name-only | grep -q "frontend/app/generated/api.ts"; then
echo "⚠️ Backend schema files changed and generated types have unstaged changes."
echo " Run 'git add frontend/app/generated/api.ts' to stage the changes."
echo ""
echo " To skip this check (not recommended): git commit --no-verify"
exit 1
else
echo "✓ Generated types are up to date (no changes needed)"
fi
fi
fi
echo ""
echo "🔍 Validating translation files..."
# Check if any translation files are staged
if git diff --cached --name-only | grep -q "frontend/locales/"; then
# Run translation validation
if ! node scripts/validate-translations.js; then
exit 1
fi
else
echo "✓ No translation files staged, skipping validation"
fi
echo ""
echo "✅ All pre-commit checks passed"