Skip to content

בדיקת העיצוב פוסלת font-family: inherit ו-@font-face, וההודעות שלה מפנות לטוקנים שלא קיימים / Design check rejects font-family: inherit and @font-face, and its messages name tokens that do not exist #11

Open

Description

@mmichaelush

הבקשה הזו תלויה ב-Otzaria/otzaria#5740, שמפרסם את designRules ב-docs/plugin-sdk/spec.json. עד שהוא ימוזג, בדיקת הסחיפה (npm run test:spec-drift) תהיה אדומה גם עם הטלאי, ולכן אני פותח issue ולא PR. אחרי המיזוג אפתח PR מהטלאי שלמטה (git apply עובר על main הנוכחי).

This depends on Otzaria/otzaria#5740, which publishes designRules in docs/plugin-sdk/spec.json. Until it is merged the spec-drift check stays red even with the patch, so this is an issue rather than a PR; I will open a PR from the patch below after the merge (git apply succeeds on the current main).

עברית

כותרת

בדיקת העיצוב פוסלת font-family: inherit ו-@font-face, וההודעות שלה מפנות לטוקנים שלא קיימים

מה הבעיה

בדיקת העיצוב ("מראה תואם לאוצריא", src/extendedValidator.js) סוטה ממדריך העיצוב
(docs/plugin-sdk/DESIGN_GUIDE.md באפליקציה):

  1. font-family: inherit (למשל על כפתור) נפסל, אף שזה דפוס לגיטימי.
  2. font-family בתוך @font-face נפסל. שם הגופן שם הוא ההגדרה עצמה, ולכן תוסף שמצרף גופן
    משלו נכשל בשער.
  3. ההודעות מפנות לטוקנים שלא קיימים:
    • רדיוס: "חובה var(--radius-sm/md/lg/pill)". במדריך יש רק var(--radius) (8), וגלולה אסורה.
    • גופן: "חובה var(--font-main)". זה גופן הקריאה, ולממשק יש var(--font-ui).
    • גודל גופן: "חובה em/rem או var(--font-size-base)". --font-size-base הוא גודל הקריאה
      ואינו בסולם הממשק (var(--text-*)).
  4. כללי העיצוב כתובים פעמיים (ב-Dart באפליקציה ובקוד ה-JS), ולכן סטו זה מזה.

מה מבוקש

  • א. להתיר ב-font-family את inherit, initial, unset, system-ui.
  • ב. הודעת רדיוס: חובה var(--radius) (8). אין גלולות.
  • ג. הודעת גופן: חובה var(--font-ui) לממשק, או var(--font-main) לטקסט ספר.
  • ד. הודעת גודל: חובה var(--text-*) (או em/rem). px מותר רק בכלל שמתייחס לסרגל העליון (ששמו מכיל topbar).
  • ה. כללי העיצוב נקראים מ-designRules שב-spec.json (האפליקציה מפרסמת אותו; npm run sync:spec
    מרענן), ובדיקת הסחיפה (test/specDrift.js) משווה גם אותו. כך כלל או הודעה לא משתנים רק באחד מהמימושים.
  • ז. כללי @font-face לא נבדקים.
  • (שורה ו, שהבודק אינו בודק בכלל: font המקוצר, style="", box-shadow, padding. לא מבוקש עכשיו.)

מה בטלאי

src/extendedValidator.js (הכללים וההודעות נקראים מ-designRules), src/spec.json (נוסף רק
designRules; שאר השדות מתרעננים ב-npm run sync:spec אחרי שהאפליקציה תמוזג), test/run.js
(8 בדיקות חדשות), test/specDrift.js, README.md.

סדר פעולות

  1. האפליקציה (Otzaria/otzaria, dev) מתפרסמת עם designRules ב-docs/plugin-sdk/spec.json.
  2. git apply otzaria-plugin-validator-design-rules.diff ואז npm run sync:spec (מחליף את החלק
    הידני ב-src/spec.json במפרט המלא).
  3. npm test. הבדיקה npm run test:spec-drift תהיה אדומה עד שהשלב הראשון קורה (כמו היום, לפי ה-CI).

איך נבדק

על עותק זמני של המאגר (בלי node_modules, אין תלויות): node test/run.js לפני: 79 passed, 0 failed.
אחרי: 87 passed, 0 failed. עם הטלאי על הקוד הישן של extendedValidator.js נכשלות 7 מהבדיקות החדשות
(80 passed, 7 failed). git apply --check על המאגר האמיתי: עובר.


English

Title

Design check rejects font-family: inherit and @font-face, and its messages point at tokens that do not exist

Problem

The design check (src/extendedValidator.js) has drifted from the design guide
(docs/plugin-sdk/DESIGN_GUIDE.md in the app):

  1. font-family: inherit (e.g. on a button) is rejected, although it is a legitimate pattern.
  2. font-family inside @font-face is rejected. The family name there is the definition itself, so a plugin
    that bundles its own font fails the gate.
  3. The messages name tokens that do not exist: var(--radius-sm/md/lg/pill) (the guide has only
    var(--radius) = 8 and pills are not allowed), var(--font-main) (the reading font; UI uses var(--font-ui)),
    var(--font-size-base) (the reading size, not part of the UI scale var(--text-*)).
  4. The rules are written twice (Dart in the app, and here), so they drifted.

Requested

  • a. Allow inherit, initial, unset, system-ui as font-family values.
  • b. Radius message: var(--radius) (8), no pills. c. Font message: var(--font-ui) for UI, var(--font-main) for book text.
  • d. Font-size message: var(--text-*) (or em/rem); px only in a rule that targets the top bar (selector contains topbar).
  • e. Read the design rules from designRules in spec.json (published by the app; refreshed with npm run sync:spec)
    and compare it in test/specDrift.js, so a rule cannot change in only one implementation.
  • g. Do not check the contents of @font-face rules.
  • (Row f, things the validator does not check at all: shorthand font, inline style="", box-shadow, padding: not requested now.)

Patch

הטלאי המלא בתחתית ההודעה: src/extendedValidator.js, src/spec.json (only designRules
added; run npm run sync:spec once the app change is on dev to replace it with the full spec), test/run.js
(8 new tests), test/specDrift.js, README.md.

Verified

On a temp copy of the repo (no node_modules, no dependencies): node test/run.js before: 79 passed, 0 failed;
after: 87 passed, 0 failed; with the patched tests on the old extendedValidator.js: 80 passed, 7 failed.
git apply --check against the real repo succeeds.

otzaria-plugin-validator-design-rules.diff
diff --git a/README.md b/README.md
index ea9260b..b6435ad 100644
--- a/README.md
+++ b/README.md
@@ -264,6 +264,8 @@ build/**
 
 - `<html>` ללא `dir="rtl"` / `lang="he"`, צבעי hex/rgb/שמות באנגלית מקודדים,
   `font-family`/`font-size`/`border-radius` מקודדים, או היעדר שימוש ב‑`var(--color-*)`.
+  ‏`font-family` מתיר `inherit`, `initial`, `unset` ו‑`system-ui`, ו‑`@font-face` אינו נבדק.
+  כללי העיצוב וההודעות נקראים מ‑`designRules` שב‑`src/spec.json` (מקור: האפליקציה).
 
 ## הרצה מקומית
 
diff --git a/src/extendedValidator.js b/src/extendedValidator.js
index 7cc7030..0126d6b 100644
--- a/src/extendedValidator.js
+++ b/src/extendedValidator.js
@@ -83,9 +83,19 @@ function scanCodeForApiUsage(text) {
 
 // ---- Design compliance (DESIGN_GUIDE.md) ------------------------------------
 
-const ALLOWED_COLOR_KEYWORDS = new Set([
-  'inherit', 'initial', 'unset', 'revert', 'currentcolor', 'transparent', 'none',
-])
+// כללי העיצוב (מילות מפתח מותרות, סלקטור הסרגל העליון, כללי @ שמדולגים,
+// הודעות הכשל) נקראים מ-`designRules` שבעותק המצורף של המפרט, ואינם מקודדים כאן.
+// המקור הוא plugin_design_rules.dart באפליקציה; `npm run sync:spec` מרענן אותו.
+// הם נקראים מהעותק המצורף בלבד: מפרט חי ישן, בלי designRules, לא יכול לבטל אותם.
+const { designRules: DESIGN_RULES } = require('./spec.json')
+
+const ALLOWED_COLOR_KEYWORDS = new Set(DESIGN_RULES.colorKeywords)
+const FONT_FAMILY_KEYWORDS = new Set(DESIGN_RULES.fontFamilyKeywords)
+const TOP_BAR_SELECTOR_RE = new RegExp(DESIGN_RULES.topBarSelectorPattern, 'i')
+const SKIPPED_AT_RULES_RE = new RegExp(
+  '@(?:' + DESIGN_RULES.skippedAtRules.join('|') + ')\\s*\\{[^}]*\\}',
+  'gi'
+)
 const NAMED_COLOR_RE = /\b(black|white|red|green|blue|yellow|gray|grey|purple|orange|pink|brown|cyan|magenta|silver|gold|maroon|navy|teal|olive|aqua|fuchsia|lime|violet|indigo|coral|crimson|salmon|khaki|beige|ivory|wheat|tan|chocolate|tomato|turquoise|orchid)\b/i
 const HEX_COLOR_RE = /#[0-9a-fA-F]{3,8}\b/g
 const RGB_HSL_RE = /\b(?:rgb|rgba|hsl|hsla)\s*\(/g
@@ -93,6 +103,9 @@ const COLOR_PROP_RE = /(?:^|[\s;{])(color|background(?:-color)?|border(?:-(?:top
 
 const stripCssComments = (css) => css.replace(/\/\*[\s\S]*?\*\//g, '')
 
+// תוכן של כללי @ שאינם נבדקים (`@font-face`: שם הגופן שם הוא ההגדרה עצמה).
+const stripSkippedAtRules = (css) => css.replace(SKIPPED_AT_RULES_RE, '')
+
 // הסלקטור של הכלל שבתוכו נמצא ההיסט — לחריגים תלויי-סלקטור בסריקת ה-CSS.
 // (סריקה טקסטואלית: נסוגים אל ה-'{' הפותח, והסלקטור הוא מה שלפניו עד סוף
 //  הכלל/הבלוק הקודם.)
@@ -105,7 +118,7 @@ function selectorAtOffset(css, index) {
 
 // פס כותרת התוסף — הסלקטור המוסכם ב-DESIGN_GUIDE (`.topbar` / `.top-bar`).
 function isTopBarSelector(selector) {
-  return /top-?bar/i.test(selector)
+  return TOP_BAR_SELECTOR_RE.test(selector)
 }
 
 // קבצים מגיעים כטקסט מהתיקייה וכ-Buffer מהארכיון — שני הצרכנים, אותה סריקה.
@@ -147,7 +160,7 @@ function checkDesignCompliance(files) {
   }
 
   for (const { name, css } of cssChunks) {
-    const stripped = stripCssComments(css).replace(/--[a-zA-Z_][\w-]*\s*:\s*[^;}]+;?/g, '')
+    const stripped = stripSkippedAtRules(stripCssComments(css)).replace(/--[a-zA-Z_][\w-]*\s*:\s*[^;}]+;?/g, '')
     const seen = new Set()
     const addOnce = (type, message) => {
       if (seen.has(type)) return
@@ -184,10 +197,10 @@ function checkDesignCompliance(files) {
     let fmMatch
     while ((fmMatch = fontFamRe.exec(stripped)) !== null) {
       const value = fmMatch[1].trim()
-      if (!/var\s*\(\s*--font/i.test(value)) {
-        addOnce('font-family', `${name}: font-family מקודד ("${value.slice(0, 50)}"). חובה var(--font-main)`)
-        break
-      }
+      if (/var\s*\(\s*--font/i.test(value)) continue
+      if (FONT_FAMILY_KEYWORDS.has(value.toLowerCase())) continue
+      addOnce('font-family', `${name}: font-family מקודד ("${value.slice(0, 50)}"). ${DESIGN_RULES.hints.fontFamily}`)
+      break
     }
 
     const fontSizeRe = /font-size\s*:\s*([^;}]+)/gi
@@ -201,7 +214,7 @@ function checkDesignCompliance(files) {
       // שהפס לא יתנפח עם גופן הקריאה של המשתמש. נאכף לפי שם הסלקטור.
       if (isTopBarSelector(selectorAtOffset(stripped, fsMatch.index))) continue
       if (/\d+\s*px/i.test(value)) {
-        addOnce('font-size-px', `${name}: font-size ב-px קבוע ("${value.slice(0, 30)}"). חובה em/rem או var(--font-size-base) (px מותר רק בסלקטור פס הכותרת — ראו DESIGN_GUIDE.md)`)
+        addOnce('font-size-px', `${name}: font-size ב-px קבוע ("${value.slice(0, 30)}"). ${DESIGN_RULES.hints.fontSizePx}`)
         break
       }
     }
@@ -214,7 +227,7 @@ function checkDesignCompliance(files) {
       if (/^0(?:px)?(?:\s+0(?:px)?)*$/.test(value)) continue
       if (/^\d+(?:\.\d+)?\s*%$/.test(value)) continue
       if (/\d+\s*px/i.test(value)) {
-        addOnce('radius-px', `${name}: border-radius ב-px קבוע ("${value.slice(0, 30)}"). חובה var(--radius-sm/md/lg/pill)`)
+        addOnce('radius-px', `${name}: border-radius ב-px קבוע ("${value.slice(0, 30)}"). ${DESIGN_RULES.hints.radiusPx}`)
         break
       }
     }
diff --git a/src/spec.json b/src/spec.json
index 7465e7f..8bea078 100644
--- a/src/spec.json
+++ b/src/spec.json
@@ -603,5 +603,31 @@
   "versions": {
     "whenCondition": "0.9.97",
     "headless": "0.9.98"
+  },
+  "designRules": {
+    "colorKeywords": [
+      "currentcolor",
+      "inherit",
+      "initial",
+      "none",
+      "revert",
+      "transparent",
+      "unset"
+    ],
+    "fontFamilyKeywords": [
+      "inherit",
+      "initial",
+      "system-ui",
+      "unset"
+    ],
+    "topBarSelectorPattern": "top-?bar",
+    "skippedAtRules": [
+      "font-face"
+    ],
+    "hints": {
+      "fontFamily": "חובה var(--font-ui) לממשק, או var(--font-main) לטקסט ספר",
+      "fontSizePx": "חובה var(--text-*) (או em/rem). px מותר רק בכלל שמתייחס לסרגל העליון (ששמו מכיל topbar)",
+      "radiusPx": "חובה var(--radius) (8). אין גלולות"
+    }
   }
 }
diff --git a/test/run.js b/test/run.js
index 2086361..c6a9c53 100644
--- a/test/run.js
+++ b/test/run.js
@@ -124,6 +124,59 @@ test('font-size in px is still blocked outside the top bar', () => {
   )
 })
 
+// font-family: מילות המפתח inherit/initial/unset/system-ui מותרות (inherit על
+// כפתור הוא דפוס לגיטימי), וגם בלי var(--font-*).
+for (const keyword of ['inherit', 'initial', 'unset', 'system-ui']) {
+  test(`font-family: ${keyword} is allowed`, () => {
+    const files = new Map([['style.css', `body { color: var(--color-primary); } button { font-family: ${keyword}; }`]])
+    const d = checkDesignCompliance(files)
+    assert.ok(!d.violations.some((v) => v.includes('font-family')), d.violations.join(' | '))
+  })
+}
+
+test('a hardcoded font-family is still blocked', () => {
+  const files = new Map([['style.css', 'body { color: var(--color-primary); font-family: serif; }']])
+  const d = checkDesignCompliance(files)
+  assert.strictEqual(d.violations.filter((v) => v.includes('font-family')).length, 1)
+})
+
+// font-family בתוך @font-face הוא ההגדרה של הגופן, לא שימוש בו.
+test('font-family inside @font-face is not checked, but other rules still are', () => {
+  const face = '@font-face { font-family: "MyFont"; src: url(my.woff2); }'
+  const clean = checkDesignCompliance(new Map([['style.css', `body { color: var(--color-primary); } ${face}`]]))
+  assert.ok(!clean.violations.some((v) => v.includes('font-family')), clean.violations.join(' | '))
+  const dirty = checkDesignCompliance(new Map([['style.css', `body { color: var(--color-primary); } ${face} .a { font-family: serif; }`]]))
+  assert.strictEqual(dirty.violations.filter((v) => v.includes('font-family')).length, 1)
+})
+
+// ההודעות מגיעות מ-designRules שבמפרט; הן מפנות לטוקנים שקיימים ב-DESIGN_GUIDE.
+test('design violation messages point at tokens that exist in the guide', () => {
+  const css = 'body { color: var(--color-primary); font-family: serif; } .a { font-size: 18px; border-radius: 12px; }'
+  const d = checkDesignCompliance(new Map([['style.css', css]]))
+  const joined = d.violations.join('\n')
+  assert.ok(joined.includes('var(--font-ui) לממשק, או var(--font-main) לטקסט ספר'), joined)
+  assert.ok(joined.includes('var(--text-*)') && joined.includes('topbar'), joined)
+  assert.ok(joined.includes('var(--radius) (8). אין גלולות'), joined)
+  assert.ok(!/radius-(sm|md|lg|pill)|font-size-base/.test(joined), joined)
+})
+
+test('the vendored spec carries designRules, and the validator uses exactly them', () => {
+  const rules = vendoredSpec.designRules
+  assert.ok(rules, 'src/spec.json חסר designRules (npm run sync:spec)')
+  for (const key of ['colorKeywords', 'fontFamilyKeywords', 'skippedAtRules']) {
+    assert.ok(Array.isArray(rules[key]) && rules[key].length > 0, key)
+  }
+  assert.ok(typeof rules.topBarSelectorPattern === 'string' && rules.topBarSelectorPattern)
+  for (const key of ['fontFamily', 'fontSizePx', 'radiusPx']) {
+    assert.ok(typeof rules.hints[key] === 'string' && rules.hints[key], key)
+  }
+  // כל מילת מפתח שבמפרט מותרת בפועל, בלי מילה שהמפרט אינו מכיר.
+  for (const keyword of rules.fontFamilyKeywords) {
+    const d = checkDesignCompliance(new Map([['s.css', `a { color: var(--color-primary); font-family: ${keyword}; }`]]))
+    assert.ok(!d.violations.some((v) => v.includes('font-family')), keyword)
+  }
+})
+
 test('top-bar exception does not leak to the next rule', () => {
   const files = new Map([
     ['style.css', '.topbar { font-size: 16px; } .card { font-size: 18px; }'],
diff --git a/test/specDrift.js b/test/specDrift.js
index 819cd06..c2d5545 100644
--- a/test/specDrift.js
+++ b/test/specDrift.js
@@ -47,6 +47,18 @@ function diffScalar(label, mine, theirs) {
   return mine === theirs ? [] : [`  ${label}: חי=${theirs} מצורף=${mine}`]
 }
 
+function diffDesignRules(mine, theirs) {
+  const a = mine || {}
+  const b = theirs || {}
+  return [
+    ...diff('designRules.colorKeywords', a.colorKeywords || [], b.colorKeywords || []),
+    ...diff('designRules.fontFamilyKeywords', a.fontFamilyKeywords || [], b.fontFamilyKeywords || []),
+    ...diff('designRules.skippedAtRules', a.skippedAtRules || [], b.skippedAtRules || []),
+    ...diffScalar('designRules.topBarSelectorPattern', a.topBarSelectorPattern, b.topBarSelectorPattern),
+    ...diffMap('designRules.hints', a.hints, b.hints),
+  ]
+}
+
 // אחזור המפרט החי כ-JSON גולמי. parseSpecJson משמש לאימות צורה בלבד — קובץ
 // קטוע או סכימה לא מוכרת נדחים לפני ההשוואה.
 async function fetchLiveSpec(url) {
@@ -138,6 +150,9 @@ async function main() {
       (live.manifest || {}).stability || []
     ),
     ...diffMap('versions', vendored.versions, live.versions),
+    // כללי העיצוב: הבודק קורא אותם מהעותק המצורף, ולכן סחיפה כאן משנה את
+    // מה שנפסל בפועל.
+    ...diffDesignRules(vendored.designRules, live.designRules),
   ]
 
   // שדה חדש שנוסף למפרט החי ואינו מושווה למעלה — אחרת הרחבת הסכימה נשארת
@@ -146,6 +161,7 @@ async function main() {
     'schemaVersion', 'generatedBy', 'source', 'permissions', 'baselinePermissions',
     'legacyPermissionAliases', 'apiMethods', 'undocumentedApiMethods', 'events',
     'methodMinVersions', 'methodPermissions', 'settings', 'manifest', 'versions',
+    'designRules',
   ])
   const unknown = Object.keys(live).filter((k) => !compared.has(k))
   if (unknown.length) {

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions