| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
set -u |
| 7 |
ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 8 |
FRONTEND="$ROOT/src-tauri/frontend" |
| 9 |
SRC_JS="$FRONTEND/js" |
| 10 |
SRC_HTML="$FRONTEND/index.html $FRONTEND/compose.html" |
| 11 |
SRC_CSS="$FRONTEND/css/styles.css" |
| 12 |
|
| 13 |
violations=0 |
| 14 |
|
| 15 |
report() { |
| 16 |
local rule="$1"; shift |
| 17 |
local msg="$1"; shift |
| 18 |
if [ -n "$*" ]; then |
| 19 |
echo |
| 20 |
echo "[$rule] $msg" |
| 21 |
echo "$*" |
| 22 |
violations=$((violations + 1)) |
| 23 |
fi |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
hits=$(grep -rnE '#[0-9a-fA-F]{3,8}\b' "$SRC_JS" $SRC_HTML 2>/dev/null \ |
| 30 |
| grep -vE '&#[0-9]+;' \ |
| 31 |
| grep -vE 'meta name="theme-color"' \ |
| 32 |
|| true) |
| 33 |
report "no-raw-hex" "Raw hex literal in JS/HTML — use a CSS class or token instead." "$hits" |
| 34 |
|
| 35 |
|
| 36 |
hits=$(grep -rn 'cssText' "$SRC_JS" 2>/dev/null || true) |
| 37 |
report "no-csstext" "style.cssText injection — move styles into a CSS class." "$hits" |
| 38 |
|
| 39 |
|
| 40 |
hits=$(grep -rnE 'var\(--[a-z-]+,\s*#' "$FRONTEND" --include='*.js' --include='*.html' --include='styles.css' 2>/dev/null | grep -v styles.min.css || true) |
| 41 |
report "no-var-fallback-hex" "var(--token, #fallback) — drop the fallback; it bypasses themes." "$hits" |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
hits=$(grep -rnE '\b(window\.)?confirm\(' "$SRC_JS" 2>/dev/null | grep -v '/tests/' | grep -vE 'showConfirmDialog|confirmDelete|//\s*\*|\*\s' || true) |
| 47 |
report "no-window-confirm" "window.confirm() — use GoingsOn.ui.showConfirmDialog instead." "$hits" |
| 48 |
|
| 49 |
|
| 50 |
hits=$(grep -rnE 'style="[^"]*(color|background|border|shadow|font-size|font-family|padding)' "$SRC_JS" $SRC_HTML 2>/dev/null || true) |
| 51 |
report "no-styled-attrs" "Inline style= with color/background/border/shadow/font/padding — use a class." "$hits" |
| 52 |
|
| 53 |
|
| 54 |
hits=$(grep -rnE 'empty-dashboard-list|kanban-empty|virtual-scroller-empty' "$FRONTEND" --include='*.js' --include='*.html' --include='styles.css' 2>/dev/null | grep -v styles.min.css || true) |
| 55 |
report "no-deprecated-empty-states" "Deprecated class — use .empty-state with --compact / --dashboard / --error." "$hits" |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
hits=$(grep -rnE '\b(window\.)?(confirm|prompt|alert)\(' "$SRC_JS" 2>/dev/null \ |
| 60 |
| grep -v '/tests/' \ |
| 61 |
| grep -vE 'showConfirmDialog|showPromptDialog|confirmDelete|//\s|\*\s' || true) |
| 62 |
report "no-native-dialogs" "window.confirm/prompt/alert are banned — use GoingsOn.ui.show{Confirm,Prompt}Dialog or showToast." "$hits" |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
if command -v node >/dev/null 2>&1; then |
| 70 |
if ! js_out=$(node "$SRC_JS/tests/run.js" 2>&1); then |
| 71 |
echo |
| 72 |
echo "[frontend-js-tests] JS test suite failed (includes the CHRONIC-XSS escaping gate):" |
| 73 |
echo "$js_out" | tail -40 |
| 74 |
violations=$((violations + 1)) |
| 75 |
fi |
| 76 |
else |
| 77 |
echo "[frontend-js-tests] WARNING: node not found — skipping JS tests and the XSS gate" |
| 78 |
fi |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
INLINE_HANDLER_BUDGET=389 |
| 90 |
inline_count=$(grep -rlE "\bon[a-z]+=[\"']" "$FRONTEND" --include='*.html' --include='*.js' 2>/dev/null \ |
| 91 |
| grep -v '/tests/' | grep -v '\.min\.' \ |
| 92 |
| tr '\n' '\0' | xargs -0 grep -oE "\bon[a-z]+=[\"']" 2>/dev/null | wc -l | tr -d ' ') |
| 93 |
if [ "$inline_count" -gt "$INLINE_HANDLER_BUDGET" ]; then |
| 94 |
report "inline-handler-ratchet" \ |
| 95 |
"Inline event handlers rose to $inline_count (budget $INLINE_HANDLER_BUDGET). Don't add inline on*= attributes; wire events with addEventListener (data-* + delegation)." \ |
| 96 |
"count $inline_count > budget $INLINE_HANDLER_BUDGET" |
| 97 |
elif [ "$inline_count" -lt "$INLINE_HANDLER_BUDGET" ]; then |
| 98 |
echo "[inline-handler-ratchet] progress: $inline_count inline handlers (budget $INLINE_HANDLER_BUDGET)." |
| 99 |
echo " Lower INLINE_HANDLER_BUDGET in scripts/lint-frontend.sh to $inline_count to lock in the gain." |
| 100 |
fi |
| 101 |
|
| 102 |
if [ $violations -eq 0 ]; then |
| 103 |
echo "frontend lint: clean" |
| 104 |
exit 0 |
| 105 |
else |
| 106 |
echo |
| 107 |
echo "frontend lint: $violations rule(s) failed" |
| 108 |
exit 1 |
| 109 |
fi |
| 110 |
|