zero-check-pipeline/validate/lint.sh

55 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
TARGET="${1:-.}"
errors=0
echo "=== Lint Scan ==="
has_python=$(find "$TARGET" -name "*.py" -not -path "*/.*" | head -1)
has_go=$(find "$TARGET" -name "*.go" -not -path "*/.*" | head -1)
if [ -z "$has_python" ] && [ -z "$has_go" ]; then
printf "${YELLOW}!${NC} No Python or Go files found — skipping\n"
exit 0
fi
if [ -n "$has_python" ]; then
if ! command -v ruff &>/dev/null; then
printf "${RED}${NC} ruff not installed\n"
exit 2
fi
echo "-- Python (ruff) --"
if ruff check "$TARGET" 2>/dev/null; then
printf "${GREEN}${NC} Python lint clean\n"
else
printf "${RED}${NC} Python lint errors found\n"
errors=$((errors + 1))
fi
fi
if [ -n "$has_go" ]; then
if ! command -v golangci-lint &>/dev/null; then
printf "${YELLOW}!${NC} golangci-lint not installed — skipping Go lint\n"
else
echo "-- Go (golangci-lint) --"
if golangci-lint run "$TARGET/..." 2>/dev/null; then
printf "${GREEN}${NC} Go lint clean\n"
else
printf "${RED}${NC} Go lint errors found\n"
errors=$((errors + 1))
fi
fi
fi
if [ "$errors" -gt 0 ]; then
exit 1
else
exit 0
fi