#!/bin/bash # Dead Code Analysis Script for Foxhunt Workspace echo "=== FOXHUNT DEAD CODE ANALYSIS ===" echo "" # 1. Find public items that might be unused echo "1. PUBLIC API SURFACE ANALYSIS" echo "-------------------------------" find . -name "*.rs" -type f -not -path "./target/*" -exec grep -l "^pub fn\|^pub struct\|^pub enum\|^pub trait" {} \; | wc -l echo " files with public items found" echo "" # 2. Find large commented code blocks echo "2. LARGE COMMENTED CODE BLOCKS (>10 lines)" echo "-------------------------------------------" find . -name "*.rs" -type f -not -path "./target/*" -print0 | while IFS= read -r -d '' file; do awk '/^[[:space:]]*\/\// {count++} !/^[[:space:]]*\/\// {if (count >= 10) print FILENAME":"NR-count"-"NR-1":"count" lines"; count=0} END {if (count >= 10) print FILENAME":"NR-count"-"NR":"count" lines"}' "$file" done | head -20 echo "" # 3. Find empty or nearly empty modules echo "3. EMPTY OR MINIMAL MODULES" echo "----------------------------" find . -name "*.rs" -type f -not -path "./target/*" -exec sh -c 'lines=$(wc -l < "$1"); if [ "$lines" -lt 10 ]; then echo "$1: $lines lines"; fi' _ {} \; | head -20 echo "" # 4. Find test modules with no tests echo "4. TEST MODULES WITHOUT TESTS" echo "------------------------------" find . -name "*.rs" -type f -not -path "./target/*" -exec grep -l "#\[cfg(test)\]" {} \; | while read file; do if ! grep -q "#\[test\]" "$file"; then echo "$file - has #[cfg(test)] but no #[test] functions" fi done | head -10 echo "" # 5. Find feature-gated code echo "5. FEATURE-GATED CODE" echo "----------------------" find . -name "*.rs" -type f -not -path "./target/*" -exec grep -l "#\[cfg(feature" {} \; | head -10 echo "" # 6. Analyze Cargo.toml dependencies echo "6. DEPENDENCY ANALYSIS PER CRATE" echo "---------------------------------" find . -name "Cargo.toml" -not -path "./target/*" | head -5 echo "" echo "=== ANALYSIS COMPLETE ==="