#!/bin/bash # validate_clippy.sh # Generates a comprehensive clippy validation report # Shows current state and progress toward goals set -e cd "$(dirname "$0")/.." OUTPUT_FILE="CLIPPY_VALIDATION_REPORT_$(date +%Y%m%d_%H%M%S).md" echo "Generating clippy validation report..." echo "This may take 5-10 minutes..." echo "" { echo "# Clippy Validation Report" echo "" echo "**Generated**: $(date)" echo "**Workspace**: $(pwd)" echo "**Git Branch**: $(git branch --show-current)" echo "**Git Commit**: $(git rev-parse --short HEAD)" echo "" echo "---" echo "" echo "## Executive Summary" echo "" cargo clippy --workspace --all-targets 2>&1 | tee /tmp/clippy_full.txt > /dev/null TOTAL_WARNINGS=$(grep -c "warning:" /tmp/clippy_full.txt || echo "0") ML_WARNINGS=$(grep "^\`ml\`" /tmp/clippy_full.txt | grep "generated" | grep -oP "\d+" | head -1 || echo "0") COMMON_WARNINGS=$(grep "^\`common\`" /tmp/clippy_full.txt | grep "generated" | grep -oP "\d+" | head -1 || echo "0") echo "| Metric | Count | Target | Status |" echo "|--------|-------|--------|--------|" echo "| **Total Warnings** | $TOTAL_WARNINGS | <100 | $([ $TOTAL_WARNINGS -lt 100 ] && echo "✅" || echo "🔴") |" echo "| **ML Crate** | $ML_WARNINGS | 0 | $([ $ML_WARNINGS -eq 0 ] && echo "✅" || echo "🔴") |" echo "| **Common Crate** | $COMMON_WARNINGS | 0 | $([ $COMMON_WARNINGS -eq 0 ] && echo "✅" || echo "🔴") |" echo "" echo "---" echo "" echo "## Warnings by Crate" echo "" echo "| Crate | Warnings | Change | Status |" echo "|-------|----------|--------|--------|" grep "generated" /tmp/clippy_full.txt | \ grep -v "duplicate" | \ sed 's/warning: `//' | \ sed 's/` (.*) generated /|/' | \ sed 's/ warning.*/|/' | \ sort -t'|' -k2 -rn | \ while IFS='|' read -r crate count; do STATUS="🔴" [ "$count" -lt 10 ] && STATUS="🟡" [ "$count" -lt 5 ] && STATUS="✅" echo "| $crate | $count | - | $STATUS |" done echo "" echo "---" echo "" echo "## Top 20 Warning Categories" echo "" echo "| Category | Count | Severity |" echo "|----------|-------|----------|" grep "warning:" /tmp/clippy_full.txt | \ grep -v "generated\|build failed" | \ sed 's/warning: //' | \ sort | uniq -c | sort -rn | head -20 | \ while read count warning; do SEVERITY="🟢" [[ "$warning" == *"panic"* ]] && SEVERITY="🔴" [[ "$warning" == *"unwrap"* ]] && SEVERITY="🔴" [[ "$warning" == *"indexing"* ]] && SEVERITY="🔴" [[ "$warning" == *"arithmetic"* ]] && SEVERITY="🟡" [[ "$warning" == *"overflow"* ]] && SEVERITY="🟡" echo "| $warning | $count | $SEVERITY |" done echo "" echo "---" echo "" echo "## Safety-Critical Issues (P0)" echo "" echo "These require immediate attention to prevent runtime panics:" echo "" echo "### Indexing that may panic" INDEXING_COUNT=$(grep -c "indexing may panic" /tmp/clippy_full.txt || echo "0") echo "- **Count**: $INDEXING_COUNT" echo "- **Risk**: 🔴 HIGH - Can cause service crashes" echo "- **Fix**: Replace \`array[i]\` with \`array.get(i)?\`" echo "" echo "### Unwrap on Result/Option" UNWRAP_COUNT=$(grep -c "used \`unwrap()\`" /tmp/clippy_full.txt || echo "0") echo "- **Count**: $UNWRAP_COUNT" echo "- **Risk**: 🔴 HIGH - Can cause panics" echo "- **Fix**: Replace with \`?\` operator or proper error handling" echo "" echo "### Arithmetic overflow" ARITHMETIC_COUNT=$(grep -c "arithmetic operation that can potentially result in unexpected side-effects" /tmp/clippy_full.txt || echo "0") echo "- **Count**: $ARITHMETIC_COUNT" echo "- **Risk**: 🟡 MEDIUM - Can cause incorrect calculations" echo "- **Fix**: Use \`.checked_add()\`, \`.checked_mul()\`" echo "" CRITICAL_TOTAL=$((INDEXING_COUNT + UNWRAP_COUNT + ARITHMETIC_COUNT)) echo "**Total Critical Issues**: $CRITICAL_TOTAL" echo "" echo "---" echo "" echo "## Auto-fixable Warnings" echo "" echo "These can be fixed with \`cargo clippy --fix\`:" echo "" AUTO_FIXABLE=0 grep "run \`cargo clippy --fix" /tmp/clippy_full.txt | wc -l | xargs echo "- **Packages with auto-fixes available**:" grep "run \`cargo clippy --fix" /tmp/clippy_full.txt | head -10 echo "" echo "---" echo "" echo "## Recommended Actions" echo "" if [ $CRITICAL_TOTAL -gt 0 ]; then echo "### 🔴 URGENT: Fix Safety-Critical Issues" echo "" echo "Priority: P0 - Block production deployment" echo "Time: 4-6 hours" echo "" echo "1. Fix indexing panics ($INDEXING_COUNT occurrences)" echo "2. Fix unwrap usage ($UNWRAP_COUNT occurrences)" echo "3. Fix arithmetic overflow ($ARITHMETIC_COUNT occurrences)" echo "" fi if [ $TOTAL_WARNINGS -gt 850 ]; then echo "### 🟡 Phase 1: Run Auto-fixes" echo "" echo "Time: 2 hours" echo "Expected reduction: ~850 warnings" echo "" echo "\`\`\`bash" echo "./scripts/auto_fix_safe.sh" echo "\`\`\`" echo "" fi if [ $TOTAL_WARNINGS -gt 100 ]; then echo "### 🟢 Phase 2: Manual Review" echo "" echo "Time: 6-10 hours" echo "Focus: Safety-critical issues, documentation" echo "" fi echo "### ✅ Production Readiness" echo "" if [ $ML_WARNINGS -eq 0 ] && [ $COMMON_WARNINGS -eq 0 ] && [ $CRITICAL_TOTAL -eq 0 ]; then echo "**Status**: ✅ PRODUCTION READY" echo "" echo "- ML crate: Clean ✅" echo "- Common crate: Clean ✅" echo "- Critical issues: None ✅" echo "" echo "Remaining warnings are in non-critical paths and can be addressed post-deployment." else echo "**Status**: 🔴 BLOCKED" echo "" [ $ML_WARNINGS -gt 0 ] && echo "- ML crate: $ML_WARNINGS warnings 🔴" [ $COMMON_WARNINGS -gt 0 ] && echo "- Common crate: $COMMON_WARNINGS warnings 🔴" [ $CRITICAL_TOTAL -gt 0 ] && echo "- Critical issues: $CRITICAL_TOTAL 🔴" fi echo "" echo "---" echo "" echo "## Historical Progress" echo "" echo "| Date | Total Warnings | ML Crate | Common Crate | Notes |" echo "|------|----------------|----------|--------------|-------|" echo "| 2025-10 (Historical) | 2,358 | ~100 | ~200 | Pre-Wave D |" echo "| $(date +%Y-%m-%d) | $TOTAL_WARNINGS | $ML_WARNINGS | $COMMON_WARNINGS | Current |" REDUCTION=$((2358 - TOTAL_WARNINGS)) PERCENT=$((REDUCTION * 100 / 2358)) echo "" echo "**Overall Progress**: $REDUCTION warnings fixed ($PERCENT% reduction) since Oct 2025" echo "" echo "---" echo "" echo "## Full Warning List" echo "" echo "See /tmp/clippy_full.txt for complete output" echo "" echo "\`\`\`bash" echo "# View by category" echo "grep 'warning:' /tmp/clippy_full.txt | grep -v 'generated' | sort | uniq -c | sort -rn" echo "" echo "# View by crate" echo "grep 'generated' /tmp/clippy_full.txt" echo "\`\`\`" echo "" echo "---" echo "" echo "**Report generated by**: \`validate_clippy.sh\`" echo "**Next validation**: Run after Phase 1 auto-fixes" echo "**Contact**: DevOps Team" } | tee "$OUTPUT_FILE" echo "" echo "============================================" echo " Validation Report Complete" echo "============================================" echo "" echo "Report saved to: $OUTPUT_FILE" echo "Full clippy output: /tmp/clippy_full.txt" echo "" echo "Quick summary:" echo " Total warnings: $TOTAL_WARNINGS" echo " ML crate: $ML_WARNINGS" echo " Common crate: $COMMON_WARNINGS" echo " Critical: $CRITICAL_TOTAL" echo "" if [ $ML_WARNINGS -eq 0 ] && [ $COMMON_WARNINGS -eq 0 ]; then echo "✅ SUCCESS - Core crates are clean!" else echo "⚠️ WARNING - Core crates have issues" fi