#!/usr/bin/env bash # Formatter: Python — ruff format + ruff check # Contract: $1 = absolute file path, format in place, lint, exit 0 if clean / 1 if errors # Missing tools: exit 0 silently FILE="$1" [ -z "$FILE" ] && exit 0 [ -f "$FILE" ] || exit 0 command -v ruff >/dev/null 2>&1 || exit 0 # Format in place ruff format --quiet "$FILE" 2>/dev/null # Auto-fix what we can ruff check --fix --quiet "$FILE" 2>/dev/null # Final lint pass — remaining errors go to stderr ERRORS=$(ruff check "$FILE" 2>&1) if [ $? -ne 0 ]; then echo "$ERRORS" >&2 exit 1 fi exit 0