#!/usr/bin/env bash
# Static UI/UX scan of one part of the client: counts what grep can see, for /dev ui and /dev ux.
# Every hit is a candidate: the reviewer confirms it by reading the code (method "misto").
# Usage: ui-scan.sh [path ...] (default: src/client)
set -uo pipefail
if [ "$#" -eq 0 ]; then set -- src/client; fi
for p in "$@"; do [ -e "$p" ] || { echo "path not found: $p" >&2; exit 1; }; done
FILES=$(find "$@" -type f -name '*.tsx' ! -name '*.test.tsx' ! -path '*/node_modules/*' | sort)
UI_FILES=$(printf '%s\n' "$FILES" | grep -v '/components/ui/' || true)
if [ -z "$FILES" ]; then echo "no .tsx files under: $*"; exit 0; fi
# Target is the design system itself: review the primitives instead of excluding them.
if [ -z "$UI_FILES" ]; then UI_FILES="$FILES"; echo "(target is inside components/ui: scanning the primitives)"; fi
section() { printf '\n== %s\n' "$1"; }
# grep over the screen files (design system primitives excluded), printing file:line:text
hits() { [ -z "$UI_FILES" ] && return 0; printf '%s\n' "$UI_FILES" | xargs grep -nE "$1" 2>/dev/null || true; }
total() { grep -c . || true; }
show() { head -"${1:-10}" | sed 's/^/ /'; }
# Prints the tags (file:line) that open with $1 and whose attributes (up to 10 lines) match $2 and not $3.
tag_check() {
local open="$1" must="$2" mustnot="$3"
[ -z "$UI_FILES" ] && return 0
printf '%s\n' "$UI_FILES" | while read -r f; do
awk -v open="$open" -v must="$must" -v mustnot="$mustnot" -v file="$f" '
function flush() { if (tag != "" && tag ~ must && (mustnot == "" || tag !~ mustnot)) print file ":" start; tag = "" }
{
if (tag == "" && $0 ~ open) { tag = $0; start = NR; n = 0 }
else if (tag != "") { tag = tag " " $0; n++ }
if (tag != "" && ($0 ~ /(^|[^=])>[[:space:]]*$/ || $0 ~ /\/>/ || n >= 10)) flush()
}
END { flush() }' "$f"
done
}
echo "scope: $* ($(printf '%s\n' "$FILES" | total) .tsx files, $(printf '%s\n' "$UI_FILES" | grep -c . || true) outside components/ui)"
section "U1 raw HTML controls outside components/ui"
for tag in '/]|$tag\$" | total)
[ "$n" -gt 0 ] && printf ' %-14s %s\n' "$tag" "$n"
done
echo " window.confirm/alert: $(hits '\b(window\.)?(confirm|alert)\(' | grep -vE 'onConfirm|handleConfirm' | total)"
section "U2 height overrides on controls (h-* on Input/Button/SelectTrigger/Textarea in screens)"
tag_check '<(Input|Button|SelectTrigger|Textarea|Combobox|DatePicker)[ >]|<(Input|Button|SelectTrigger|Textarea|Combobox|DatePicker)$' '[" ]h-[0-9]' '' | show
section "V3/V4 arbitrary values (p-[13px], text-[15px], w-[312px])"
ARB=$(hits '[a-z]-\[[0-9.]+(px|rem|em|%|vh|vw)\]')
echo " total: $(printf '%s' "$ARB" | total)"
printf '%s\n' "$ARB" | grep -oE '[a-z:-]+-\[[0-9.]+(px|rem|em|%|vh|vw)\]' | sort | uniq -c | sort -rn | show 12
section "V4 type scale in use (distinct text-* sizes and font-* weights)"
hits '\btext-(xs|sm|base|lg|xl|[2-9]xl)\b' | grep -oE '\btext-(xs|sm|base|lg|xl|[2-9]xl)\b' | sort | uniq -c | sort -rn | tr '\n' ' ' | sed 's/^/ /'; echo
hits '\bfont-(thin|light|normal|medium|semibold|bold|extrabold|black)\b' | grep -oE '\bfont-(thin|light|normal|medium|semibold|bold|extrabold|black)\b' | sort | uniq -c | sort -rn | tr '\n' ' ' | sed 's/^/ /'; echo
section "V5 colors outside the tokens (palette classes, hex, rgb)"
PAL=$(hits '\b(bg|text|border|ring|fill|stroke)-(red|blue|green|yellow|gray|slate|zinc|neutral|stone|orange|amber|lime|emerald|teal|cyan|sky|indigo|violet|purple|fuchsia|pink|rose)-[0-9]{2,3}\b')
echo " palette classes: $(printf '%s' "$PAL" | total) lines"
printf '%s\n' "$PAL" | grep -oE '\b(bg|text|border|ring|fill|stroke)-[a-z]+-[0-9]{2,3}\b' | sort | uniq -c | sort -rn | show 12
echo " hex/rgb literals: $(hits '#[0-9a-fA-F]{3,8}\b|rgba?\(' | grep -v '^\s*//' | total)"
section "V6 icon libraries imported"
hits "from ['\"](react-icons/[a-z0-9]+|lucide-react|@heroicons/[a-z/0-9]+|@radix-ui/react-icons)['\"]" \
| grep -oE "(react-icons/[a-z0-9]+|lucide-react|@heroicons/[a-z/0-9]+|@radix-ui/react-icons)" | sort | uniq -c | sort -rn | show
section "W3 clickable non-interactive elements (div/span/li/tr/td with onClick, no role)"
tag_check '<(div|span|li|tr|td|img)[ >]|<(div|span|li|tr|td|img)$' 'onClick' 'role=' | show 15
section "W3 focus outline removed without focus-visible style"
hits 'outline-none' | grep -v 'focus-visible:' | show
section "W4 icon-only buttons without aria-label (size=\"icon\")"
tag_check '