Skip to content
Shell
1.2 KB
Raw Blame
#!/bin/bash
# Performance Alert: Warns about potential performance issues

FILE_PATH="$1"
FILE_EXT="${FILE_PATH##*.}"

# Only check JavaScript/TypeScript files
if [[ "$FILE_EXT" == "ts" ]] || [[ "$FILE_EXT" == "tsx" ]] || [[ "$FILE_EXT" == "js" ]] || [[ "$FILE_EXT" == "jsx" ]]; then

  # Check for common performance anti-patterns
  WARNINGS=0

  # Check for inline function definitions in render
  if grep -q "onClick={() =>" "$FILE_PATH" || grep -q "onClick={function" "$FILE_PATH"; then
    echo "⚡ Performance: Consider memoizing inline functions with useCallback"
    WARNINGS=$((WARNINGS + 1))
  fi

  # Check for missing React.memo on components
  if grep -q "export.*function.*Component" "$FILE_PATH"; then
    if ! grep -q "React.memo\|memo(" "$FILE_PATH"; then
      echo "⚡ Performance: Consider wrapping component with React.memo"
      WARNINGS=$((WARNINGS + 1))
    fi
  fi

  # Check for large arrays without virtualization
  if grep -qE "\.map\(.{50,}\)" "$FILE_PATH"; then
    echo "⚡ Performance: Large lists might need virtualization"
    WARNINGS=$((WARNINGS + 1))
  fi

  if [ $WARNINGS -gt 0 ]; then
    echo "💡 Found $WARNINGS performance suggestions (not blocking)"
    echo "CLAUDE_ACTION: consider_performance_optimizations"
  fi
fi

exit 0