| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
set -u |
| 8 |
ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 9 |
FRONTEND="$ROOT/src-tauri/frontend" |
| 10 |
SRC_JS="$FRONTEND/js" |
| 11 |
SRC_HTML="$FRONTEND/index.html" |
| 12 |
SRC_CSS="$FRONTEND/css/styles.css" |
| 13 |
|
| 14 |
violations=0 |
| 15 |
|
| 16 |
report() { |
| 17 |
local rule="$1"; shift |
| 18 |
local msg="$1"; shift |
| 19 |
if [ -n "$*" ]; then |
| 20 |
echo |
| 21 |
echo "[$rule] $msg" |
| 22 |
echo "$*" |
| 23 |
violations=$((violations + 1)) |
| 24 |
fi |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
hits=$(grep -rnE '#[0-9a-fA-F]{3,8}\b' "$SRC_JS" "$SRC_HTML" 2>/dev/null \ |
| 32 |
| grep -vE '&#[0-9]+;' \ |
| 33 |
| grep -v 'js/themes.js' \ |
| 34 |
| grep -v 'js/tests/' \ |
| 35 |
|| true) |
| 36 |
report "no-raw-hex" "Raw hex literal in JS/HTML — use a CSS class or themed token." "$hits" |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
hits=$(grep -rn 'cssText' "$SRC_JS" 2>/dev/null | grep -v 'js/tests/' || true) |
| 42 |
report "no-csstext" "style.cssText injection — move styles into a CSS class." "$hits" |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
hits=$(grep -rnE 'var\(--[a-z-]+,\s*#' "$FRONTEND" \ |
| 47 |
--include='*.js' --include='*.html' --include='styles.css' 2>/dev/null || true) |
| 48 |
report "no-var-fallback-hex" "var(--token, #fallback) — drop the fallback; it bypasses themes." "$hits" |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
hits=$(grep -rnE 'style="[^"]*(color|background|border|shadow|font-size|font-family|padding)' \ |
| 55 |
"$SRC_JS" "$SRC_HTML" 2>/dev/null || true) |
| 56 |
report "no-styled-attrs" "Inline style= with color/background/border/shadow/font/padding — use a class." "$hits" |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
hits=$(grep -rnE '\.style\.(color|background|backgroundColor|borderColor|font|fontFamily|fontSize|paddingTop|paddingBottom|paddingLeft|paddingRight|margin|marginTop|marginBottom|marginLeft|marginRight|gap|opacity)\b' \ |
| 63 |
"$SRC_JS" 2>/dev/null | grep -v 'js/tests/' || true) |
| 64 |
report "no-style-color-from-js" "JS-set color/background/border/font/margin/padding/gap/opacity — use a class." "$hits" |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
hits=$(grep -rnE '\b(window\.)?(confirm|prompt|alert)\s*\(' "$SRC_JS" 2>/dev/null \ |
| 71 |
| grep -vE 'showConfirmDialog|showPromptDialog|confirmAction|confirmDelete|confirmBtn|\.confirm-message|/\*|\*\s|// ' \ |
| 72 |
| grep -v 'js/tests/' || true) |
| 73 |
report "no-native-dialogs" "window.confirm/prompt/alert are banned — use BB.ui.show{Confirm,Prompt}Dialog or showToast." "$hits" |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
root_tokens=$(awk '/^:root \{/{flag=1; next} /^\}/{flag=0} flag' "$SRC_CSS" \ |
| 81 |
| grep -oE -- '--[a-z-]+' | sort -u || true) |
| 82 |
unmapped="" |
| 83 |
for tok in $root_tokens; do |
| 84 |
|
| 85 |
if grep -E -- "$tok:[^;]*;.*(invariant|composition)" "$SRC_CSS" >/dev/null 2>&1; then continue; fi |
| 86 |
|
| 87 |
if grep -F -- "'$tok'" "$SRC_JS/themes.js" >/dev/null 2>&1; then continue; fi |
| 88 |
unmapped="$unmapped$tok"$'\n' |
| 89 |
done |
| 90 |
if [ -n "$unmapped" ]; then |
| 91 |
report "theme-token-coverage" "Token in :root is neither themed nor marked invariant/composition." "$unmapped" |
| 92 |
fi |
| 93 |
|
| 94 |
if [ $violations -eq 0 ]; then |
| 95 |
echo "frontend lint: clean" |
| 96 |
exit 0 |
| 97 |
else |
| 98 |
echo |
| 99 |
echo "frontend lint: $violations rule(s) failed" |
| 100 |
exit 1 |
| 101 |
fi |
| 102 |
|