set -e
echo "Running pre-commit checks..."
echo "🔍 Checking Rust code formatting..."
if ! cargo fmt --check; then
echo "❌ Format check failed. Run 'cargo fmt' to fix."
exit 1
fi
echo "✅ Rust format check passed"
if command -v uv &> /dev/null; then
echo "🔍 Checking Python code formatting with ruff..."
if uv run ruff check python/ --select I 2>/dev/null; then
if ! uv run ruff format --check python/ 2>/dev/null; then
echo "❌ Python format check failed. Run 'uv run ruff format python/' to fix."
exit 1
fi
echo "✅ Python format check passed"
else
echo "⚠️ Skipping Python format check (ruff not installed in uv env)"
fi
fi
echo "🔍 Running clippy..."
FEATURES="rendering,barcodes,signatures,office,ocr"
if ! cargo clippy --all-targets --features "$FEATURES" -- -D warnings; then
echo "❌ Clippy found issues. Fix them before committing."
exit 1
fi
echo "✅ Clippy passed"
echo "🔍 Running clippy with Python feature..."
if ! cargo clippy --features python -- -D warnings; then
echo "❌ Clippy (Python) found issues. Fix them before committing."
exit 1
fi
echo "✅ Clippy (Python) passed"
echo "🔍 Checking build..."
if ! cargo check --features "$FEATURES"; then
echo "❌ Build check failed."
exit 1
fi
echo "✅ Build check passed"
echo "🔍 Checking dependencies with cargo-deny..."
if ! command -v cargo-deny &> /dev/null; then
echo "⚠️ cargo-deny not installed. Run: cargo install cargo-deny"
echo "⚠️ Skipping dependency check..."
else
if ! cargo deny check; then
echo "❌ Dependency check failed."
exit 1
fi
echo "✅ Dependency check passed"
fi
echo "🔍 Running library tests..."
if ! cargo test --lib --features "$FEATURES"; then
echo "❌ Library tests failed."
exit 1
fi
echo "✅ Library tests passed"
echo "🔍 Skipping integration tests (see CI for full test suite)..."
echo "✅ Integration tests skipped (run in CI environment)"
echo "🔍 Skipping doctests (see CI for documentation examples)..."
echo "✅ Doctests skipped (run in CI environment)"
if command -v uv &> /dev/null && [ -d ".venv" ]; then
echo "🔍 Running Python lint with ruff..."
if uv run ruff check python/ 2>/dev/null; then
echo "✅ Python lint passed"
else
echo "⚠️ Python lint issues found (non-blocking for now)"
fi
fi
echo "✅ All pre-commit checks passed!"