#!/usr/bin/env bash # Remove leading `// @ts-nocheck` occurrences (tiny PR safety). # Usage: bash scripts/dev/phase1/remove-ts-nocheck.sh [--apply] set -euo pipefail MODE="dry" [[ "${1-}" == "--apply" ]] && MODE="apply" ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" OUTDIR="$ROOT/reports/phase1-$(date +%Y%m%d-%H%M%S)-ts-nocheck" mkdir -p "$OUTDIR" mapfile -t FILES < <(grep -RIl --include='*.{ts,tsx}' '^// *@ts-nocheck' "$ROOT/src" || true) COUNT="${#FILES[@]}" echo "Found $COUNT files with // @ts-nocheck" printf '%s ' "${FILES[@]}" | tee "$OUTDIR/files.txt" cleanup_file() {( f="$1" tmp="$f.__tmp__" awk 'NR==1 && $0 ~ /^\/\/ *@ts-nocheck/ {print "// TODO(Phase 1): removed ts-nocheck; fix types in Phase 2–3"; next} {print}' "$f" > "$tmp" if [[ "$MODE" == "apply" ]]; then mv "$tmp" "$f" echo "[APPLY] $f" >> "$OUTDIR/changes.log" else echo "[DRY] diff $f" git --no-pager diff --no-index "$f" "$tmp" || true rm -f "$tmp" fi )} for f in "${FILES[@]}"; do [[ -f "$f" ]] && cleanup_file "$f" done echo "Report: $OUTDIR"