@behavioral-agentic-design-system/core 0.45.0 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. package/package.json +17 -3
  2. package/scripts/a11y-lint.cjs +78 -15
  3. package/scripts/bads-sync.mjs +1 -1
  4. package/scripts/build-tokens.cjs +122 -7
  5. package/scripts/check-dark-contrast.mjs +204 -0
  6. package/scripts/check-flush-edges.mjs +245 -0
  7. package/scripts/design-system-advisory/README.md +239 -0
  8. package/scripts/design-system-advisory/check-copy-punctuation.mjs +44 -0
  9. package/scripts/design-system-advisory/check-even-padding.mjs +35 -0
  10. package/scripts/design-system-advisory/check-hand-built-button.mjs +46 -0
  11. package/scripts/design-system-advisory/check-html-nesting.mjs +51 -0
  12. package/scripts/design-system-advisory/check-icon-sizing.mjs +79 -0
  13. package/scripts/design-system-advisory/check-label-case.mjs +92 -0
  14. package/scripts/design-system-advisory/check-native-form-controls.mjs +53 -0
  15. package/scripts/design-system-advisory/check-radius.mjs +56 -0
  16. package/scripts/design-system-advisory/check-raw-values.mjs +61 -0
  17. package/scripts/design-system-advisory/check-small-text.mjs +72 -0
  18. package/scripts/design-system-advisory/check-tap-target.mjs +70 -0
  19. package/scripts/design-system-advisory/defaults.mjs +90 -0
  20. package/scripts/design-system-advisory/fixtures/clean.tsx.fixture +12 -0
  21. package/scripts/design-system-advisory/fixtures/violations.tsx.fixture +19 -0
  22. package/scripts/design-system-advisory/lib.mjs +255 -0
  23. package/scripts/design-system-advisory/run.mjs +189 -0
  24. package/scripts/design-system-advisory/workflow.yml +82 -0
  25. package/scripts/lib/copy-strings.mjs +146 -0
  26. package/scripts/lib/dark-contrast.mjs +120 -0
  27. package/scripts/lib/flush-edges.mjs +294 -0
  28. package/scripts/lib/lab-lint.mjs +62 -0
  29. package/scripts/lib/mount-page.mjs +25 -0
  30. package/scripts/lib/source-scan.mjs +173 -0
  31. package/scripts/lib/tells.mjs +240 -2
  32. package/scripts/lint-arbitrary-tokens.mjs +47 -0
  33. package/scripts/lint-component-token-refs.mjs +63 -0
  34. package/scripts/lint-content-hierarchy.mjs +114 -0
  35. package/scripts/lint-control-baseline.mjs +72 -0
  36. package/scripts/lint-copy-punctuation.mjs +60 -0
  37. package/scripts/lint-even-padding.mjs +58 -0
  38. package/scripts/lint-label-case.mjs +219 -0
  39. package/scripts/lint-microanimation.mjs +2 -2
  40. package/scripts/lint-proximity.mjs +181 -0
  41. package/scripts/lint-slop.mjs +1 -1
  42. package/scripts/lint-spacing-scale.mjs +78 -0
  43. package/scripts/lint-target-size.cjs +132 -0
  44. package/scripts/lint-token-primitives.mjs +307 -0
  45. package/scripts/size-audit.cjs +2 -2
  46. package/scripts/ux-tells.mjs +8 -6
  47. package/scripts/wcag-audit.cjs +25 -4
  48. package/src/api/layers/file.ts +2 -0
  49. package/src/api/site-auth.ts +14 -2
  50. package/src/app/preview/components/page.tsx +183 -14
  51. package/src/app/preview/sticker-sheet/page.tsx +329 -0
  52. package/src/app/preview/sticker-sheet/specimens.tsx +296 -0
  53. package/src/app/shell.tsx +4 -3
  54. package/src/components/Foundations/Colors.stories.tsx +119 -8
  55. package/src/components/home-tab.tsx +6 -1
  56. package/src/components/onboarding-wizard.tsx +1 -1
  57. package/src/components/ui/avatar.tsx +4 -0
  58. package/src/components/ui/chart.tsx +134 -42
  59. package/src/components/ui/checkbox-group.tsx +1 -1
  60. package/src/components/ui/checkbox.tsx +1 -1
  61. package/src/components/ui/combobox.tsx +1 -0
  62. package/src/components/ui/command.tsx +1 -1
  63. package/src/components/ui/date-picker.tsx +2 -0
  64. package/src/components/ui/date-range-picker.tsx +4 -0
  65. package/src/components/ui/file-upload.tsx +21 -2
  66. package/src/components/ui/heatmap.tsx +3 -1
  67. package/src/components/ui/input-group.tsx +5 -2
  68. package/src/components/ui/multi-select.tsx +1 -0
  69. package/src/components/ui/number-field.tsx +390 -0
  70. package/src/components/ui/radio-group.tsx +2 -2
  71. package/src/components/ui/sparkline.tsx +33 -4
  72. package/src/components/ui/spinner.tsx +23 -4
  73. package/src/components/ui/table.tsx +9 -0
  74. package/src/components/ui/week-picker.tsx +0 -12
  75. package/src/data/component-added.json +12 -0
  76. package/src/data/docs-index.ts +22 -1
  77. package/src/data/history.json +162 -162
  78. package/src/data/sticker-sheet.json +9297 -0
  79. package/src/docs-trace-globs.json +1 -0
  80. package/src/lib/chart-motion.ts +41 -0
  81. package/src/lib/get-icon-color.ts +1 -1
  82. package/src/stories/Accordion.stories.tsx +7 -0
  83. package/src/stories/ActionBar.stories.tsx +5 -0
  84. package/src/stories/Affix.stories.tsx +4 -0
  85. package/src/stories/AiBadge.stories.tsx +9 -7
  86. package/src/stories/Alert.stories.tsx +13 -0
  87. package/src/stories/AlertDialog.stories.tsx +4 -0
  88. package/src/stories/Anchor.stories.tsx +5 -0
  89. package/src/stories/AngleSlider.stories.tsx +6 -3
  90. package/src/stories/AspectRatio.stories.tsx +4 -0
  91. package/src/stories/Autocomplete.stories.tsx +6 -0
  92. package/src/stories/Avatar.stories.tsx +10 -0
  93. package/src/stories/Badge.stories.tsx +14 -6
  94. package/src/stories/Blockquote.stories.tsx +6 -0
  95. package/src/stories/BottomNavigation.stories.tsx +4 -0
  96. package/src/stories/Breadcrumb.stories.tsx +3 -0
  97. package/src/stories/Burger.stories.tsx +1 -0
  98. package/src/stories/Button.stories.tsx +24 -0
  99. package/src/stories/ButtonGroup.stories.tsx +9 -0
  100. package/src/stories/Calendar.stories.tsx +3 -0
  101. package/src/stories/Card.stories.tsx +4 -0
  102. package/src/stories/Carousel.stories.tsx +6 -0
  103. package/src/stories/Cascader.stories.tsx +4 -0
  104. package/src/stories/Chart.stories.tsx +46 -1
  105. package/src/stories/ChatBubble.stories.tsx +8 -2
  106. package/src/stories/ChatMarker.stories.tsx +1 -0
  107. package/src/stories/Checkbox.stories.tsx +40 -0
  108. package/src/stories/CheckboxCard.stories.tsx +8 -0
  109. package/src/stories/CheckboxGroup.stories.tsx +20 -0
  110. package/src/stories/Chip.stories.tsx +10 -19
  111. package/src/stories/CircularProgress.stories.tsx +13 -27
  112. package/src/stories/Clipboard.stories.tsx +6 -0
  113. package/src/stories/CloseButton.stories.tsx +6 -4
  114. package/src/stories/Code.stories.tsx +8 -1
  115. package/src/stories/Collapsible.stories.tsx +2 -0
  116. package/src/stories/ColorPicker.stories.tsx +6 -0
  117. package/src/stories/ColorSwatch.stories.tsx +1 -0
  118. package/src/stories/Combobox.stories.tsx +9 -0
  119. package/src/stories/Command.stories.tsx +2 -0
  120. package/src/stories/Container.stories.tsx +8 -0
  121. package/src/stories/ContextMenu.stories.tsx +9 -0
  122. package/src/stories/CopyButton.stories.tsx +12 -36
  123. package/src/stories/DataList.stories.tsx +8 -0
  124. package/src/stories/DataTable.stories.tsx +9 -0
  125. package/src/stories/DateField.stories.tsx +7 -0
  126. package/src/stories/DatePicker.stories.tsx +34 -0
  127. package/src/stories/DateRangePicker.stories.tsx +32 -0
  128. package/src/stories/Dialog.stories.tsx +8 -0
  129. package/src/stories/Drawer.stories.tsx +6 -0
  130. package/src/stories/DropdownMenu.stories.tsx +2 -0
  131. package/src/stories/Editable.stories.tsx +10 -0
  132. package/src/stories/EmptyState.stories.tsx +9 -0
  133. package/src/stories/Field.stories.tsx +7 -0
  134. package/src/stories/Fieldset.stories.tsx +8 -0
  135. package/src/stories/FileButton.stories.tsx +4 -0
  136. package/src/stories/FileUpload.stories.tsx +16 -17
  137. package/src/stories/FloatLabel.stories.tsx +3 -8
  138. package/src/stories/FloatingActionButton.stories.tsx +10 -0
  139. package/src/stories/FloatingIndicator.stories.tsx +4 -0
  140. package/src/stories/FloatingPanel.stories.tsx +6 -0
  141. package/src/stories/FocusTrap.stories.tsx +5 -0
  142. package/src/stories/FormatByte.stories.tsx +6 -0
  143. package/src/stories/FormatDate.stories.tsx +8 -0
  144. package/src/stories/FormatNumber.stories.tsx +9 -0
  145. package/src/stories/Heatmap.stories.tsx +11 -0
  146. package/src/stories/Highlight.stories.tsx +6 -0
  147. package/src/stories/HoverCard.stories.tsx +4 -0
  148. package/src/stories/Image.stories.tsx +9 -0
  149. package/src/stories/Indicator.stories.tsx +19 -0
  150. package/src/stories/Input.stories.tsx +7 -0
  151. package/src/stories/InputClearButton.stories.tsx +3 -0
  152. package/src/stories/InputGroup.stories.tsx +40 -0
  153. package/src/stories/Kbd.stories.tsx +7 -1
  154. package/src/stories/KeyboardShortcut.stories.tsx +2 -0
  155. package/src/stories/Label.stories.tsx +2 -0
  156. package/src/stories/Link.stories.tsx +9 -0
  157. package/src/stories/List.stories.tsx +8 -0
  158. package/src/stories/Listbox.stories.tsx +1 -0
  159. package/src/stories/LoadingDots.stories.tsx +5 -3
  160. package/src/stories/LoadingOverlay.stories.tsx +5 -1
  161. package/src/stories/Mark.stories.tsx +5 -0
  162. package/src/stories/Marquee.stories.tsx +4 -0
  163. package/src/stories/Masonry.stories.tsx +5 -0
  164. package/src/stories/Menubar.stories.tsx +3 -0
  165. package/src/stories/Meter.stories.tsx +11 -17
  166. package/src/stories/MonthPicker.stories.tsx +5 -1
  167. package/src/stories/MotionToggle.stories.tsx +1 -0
  168. package/src/stories/MultiSelect.stories.tsx +9 -0
  169. package/src/stories/NativeSelect.stories.tsx +1 -0
  170. package/src/stories/NavLink.stories.tsx +7 -0
  171. package/src/stories/NavigationMenu.stories.tsx +5 -0
  172. package/src/stories/NavigationRail.stories.tsx +10 -0
  173. package/src/stories/Notification.stories.tsx +13 -34
  174. package/src/stories/NumberField.stories.tsx +214 -0
  175. package/src/stories/NumberInput.stories.tsx +8 -1
  176. package/src/stories/Overlay.stories.tsx +5 -1
  177. package/src/stories/Pagination.stories.tsx +8 -0
  178. package/src/stories/PasswordInput.stories.tsx +2 -0
  179. package/src/stories/PinInput.stories.tsx +9 -2
  180. package/src/stories/Popover.stories.tsx +2 -0
  181. package/src/stories/Progress.stories.tsx +6 -1
  182. package/src/stories/Prose.stories.tsx +8 -0
  183. package/src/stories/QrCode.stories.tsx +2 -0
  184. package/src/stories/Questionnaire.stories.tsx +7 -0
  185. package/src/stories/RadioGroup.stories.tsx +40 -0
  186. package/src/stories/RatingGroup.stories.tsx +8 -4
  187. package/src/stories/Resizable.stories.tsx +4 -2
  188. package/src/stories/Result.stories.tsx +3 -0
  189. package/src/stories/Reveal.stories.tsx +2 -0
  190. package/src/stories/RollingNumber.stories.tsx +5 -0
  191. package/src/stories/ScrollArea.stories.tsx +3 -1
  192. package/src/stories/SearchInput.stories.tsx +8 -6
  193. package/src/stories/SegmentedControl.stories.tsx +11 -0
  194. package/src/stories/Select.stories.tsx +7 -0
  195. package/src/stories/Separator.stories.tsx +6 -0
  196. package/src/stories/Sheet.stories.tsx +5 -0
  197. package/src/stories/Sidebar.stories.tsx +40 -1
  198. package/src/stories/SimpleGrid.stories.tsx +5 -0
  199. package/src/stories/Skeleton.stories.tsx +8 -0
  200. package/src/stories/SkeletonTable.stories.tsx +6 -5
  201. package/src/stories/SkipLink.stories.tsx +3 -0
  202. package/src/stories/Slider.stories.tsx +2 -1
  203. package/src/stories/Sonner.stories.tsx +7 -0
  204. package/src/stories/Sparkline.stories.tsx +14 -1
  205. package/src/stories/Spinner.stories.tsx +20 -10
  206. package/src/stories/Spoiler.stories.tsx +5 -0
  207. package/src/stories/Squircle.stories.tsx +7 -0
  208. package/src/stories/Stack.stories.tsx +7 -0
  209. package/src/stories/StatusBadge.stories.tsx +12 -6
  210. package/src/stories/Stepper.stories.tsx +5 -0
  211. package/src/stories/Switch.stories.tsx +4 -0
  212. package/src/stories/Table.stories.tsx +10 -1
  213. package/src/stories/Tabs.stories.tsx +8 -0
  214. package/src/stories/Tag.stories.tsx +13 -5
  215. package/src/stories/TagsInput.stories.tsx +13 -0
  216. package/src/stories/Text.stories.tsx +12 -0
  217. package/src/stories/Textarea.stories.tsx +9 -0
  218. package/src/stories/ThemeIcon.stories.tsx +6 -3
  219. package/src/stories/TimePicker.stories.tsx +2 -0
  220. package/src/stories/Timeline.stories.tsx +12 -0
  221. package/src/stories/Timer.stories.tsx +4 -0
  222. package/src/stories/Toggle.stories.tsx +7 -5
  223. package/src/stories/ToggleGroup.stories.tsx +5 -0
  224. package/src/stories/ToggleTip.stories.tsx +4 -0
  225. package/src/stories/Toolbar.stories.tsx +6 -0
  226. package/src/stories/Tooltip.stories.tsx +3 -0
  227. package/src/stories/Tour.stories.tsx +3 -0
  228. package/src/stories/TransferList.stories.tsx +3 -0
  229. package/src/stories/TreeSelect.stories.tsx +4 -0
  230. package/src/stories/TreeView.stories.tsx +5 -0
  231. package/src/stories/TypingIndicator.stories.tsx +4 -0
  232. package/src/stories/VisuallyHidden.stories.tsx +3 -0
  233. package/src/stories/Watermark.stories.tsx +6 -0
  234. package/src/stories/WeekPicker.stories.tsx +4 -1
  235. package/src/stories/WordRotate.stories.tsx +5 -0
  236. package/src/stories/YearPicker.stories.tsx +5 -11
  237. package/src/stories/story-groups.json +2 -1
  238. package/src/styles.css +50 -2
  239. package/src/tokens.json +4 -4
  240. package/LICENSE +0 -21
@@ -0,0 +1,245 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * check:flush-edges (bin: bads-check-flush-edges) — text never sits right up against the edge of the shape that holds it.
4
+ *
5
+ * WHY THIS EXISTS
6
+ *
7
+ * A booking bar's label sat 6px from the start of a pill whose round end curves in by 22px, so the letters touched the
8
+ * curve. Every gate passed: an even-padding lint reads class pairs, and nothing measured where the text actually lands
9
+ * against the edge it is drawn in. This measures the laid-out page. First found in a client's prototypes, where it now
10
+ * runs over every prototype in every state; ported here so every fork gets the same measure.
11
+ *
12
+ * WHAT IT DOES
13
+ *
14
+ * Opens each route on a running site, at each viewport width, and measures every visible text node under the root
15
+ * selector against the inner edge of its nearest visually bounded ancestor (lib/flush-edges.mjs says exactly how).
16
+ * Closer than the floor on any bounded side fails.
17
+ *
18
+ * SETTINGS. Each one is a flag, or a key under "flushEdges" in bads-checks.config.json (or the file --config names).
19
+ * A flag wins over the file, and the file wins over the default.
20
+ *
21
+ * base --base the running site http://localhost:3000
22
+ * routes --routes a,b the paths to open ["/"]
23
+ * root --root the CSS selector of what to measure "body"
24
+ * viewports --viewports widths, in CSS px [390, 1280]
25
+ * floor --floor least distance from the edge, CSS px 6
26
+ * measure --measure "cap" (capitals to baseline) or "line" "cap"
27
+ * exceptAttr --except-attr the attribute that excuses a container "data-flush-ok"
28
+ * minReason --min-reason least length of that attribute's reason 12
29
+ * frameAttr --frame-attr the attribute naming a design "data-frame-id"
30
+ * probe --probe a window function naming shipped parts none
31
+ * known --known a JSON file of known findings none
32
+ * minMeasured --min-measured fewer text nodes than this fails 1
33
+ * lazySelector --lazy placeholders that must all mount "[data-lazy-skeleton]"
34
+ * (each page is scrolled to the bottom first, so deferred blocks are drawn; "" turns
35
+ * the scroll off, for a page that defers nothing)
36
+ * --report-json f also write every hit to f, as JSON
37
+ *
38
+ * KNOWN FINDINGS. A shipped component a page must not restyle can still fail, and a fork that adopts this check starts
39
+ * with findings nobody has fixed yet. Record them in the known file, { "known": [ ... ] }, each entry with a reason of a
40
+ * sentence, in one of three shapes:
41
+ * { "route": "/x", "text": "Label", "reason": "..." } one hit: that route, text starting with `text`
42
+ * { "shipped": "badge", "count": 12, "reason": "..." } a ratchet: up to `count` hits inside that shipped component
43
+ * (its data-slot, or what the probe names), on any route
44
+ * { "route": "/x", "count": 3, "reason": "..." } a ratchet: up to `count` hits in that route's own markup
45
+ * A ratchet that is exceeded fails, and lists every hit it covers. A ratchet with fewer hits than its count fails a full
46
+ * run and says the number to lower it to, and an exact entry nothing matches fails a full run, so the list only shrinks.
47
+ *
48
+ * A route that will not load, or a run that measures fewer than minMeasured text nodes, FAILS. A check that passes over
49
+ * nothing is how the defect it exists for ships.
50
+ *
51
+ * Usage:
52
+ * bads-check-flush-edges --base http://localhost:3000 --routes /,/pricing
53
+ * bads-check-flush-edges --route /pricing # one route; known entries for other routes are not called stale
54
+ */
55
+ import { existsSync, readFileSync } from "node:fs";
56
+ import { resolve } from "node:path";
57
+ import { DEFAULTS, measureFlushEdges } from "./lib/flush-edges.mjs";
58
+ import { mountEverything } from "./lib/mount-page.mjs";
59
+
60
+ const argv = process.argv.slice(2);
61
+ const flag = (name) => (argv.includes(name) ? argv[argv.indexOf(name) + 1] : undefined);
62
+ const list = (v) => (v === undefined ? undefined : String(v).split(",").map((s) => s.trim()).filter(Boolean));
63
+
64
+ const configPath = resolve(flag("--config") ?? "bads-checks.config.json");
65
+ let fileSettings = {};
66
+ if (existsSync(configPath)) {
67
+ try {
68
+ fileSettings = JSON.parse(readFileSync(configPath, "utf8")).flushEdges ?? {};
69
+ } catch (e) {
70
+ console.error(`✗ flush-edges check: ${configPath} is not valid JSON (${e.message}).`);
71
+ process.exit(1);
72
+ }
73
+ } else if (flag("--config")) {
74
+ console.error(`✗ flush-edges check: no settings file at ${configPath}.`);
75
+ process.exit(1);
76
+ }
77
+
78
+ const pick = (key, fromFlag, fallback) => fromFlag ?? fileSettings[key] ?? fallback;
79
+ const single = flag("--route");
80
+ const settings = {
81
+ base: String(pick("base", flag("--base"), "http://localhost:3000")).replace(/\/$/, ""),
82
+ routes: single ? [single] : pick("routes", list(flag("--routes")), ["/"]),
83
+ root: pick("root", flag("--root"), "body"),
84
+ viewports: pick("viewports", list(flag("--viewports"))?.map(Number), [390, 1280]),
85
+ floor: Number(pick("floor", flag("--floor"), DEFAULTS.floor)),
86
+ measure: pick("measure", flag("--measure"), DEFAULTS.measure),
87
+ exceptAttr: pick("exceptAttr", flag("--except-attr"), DEFAULTS.exceptAttr),
88
+ minReason: Number(pick("minReason", flag("--min-reason"), DEFAULTS.minReason)),
89
+ frameAttr: pick("frameAttr", flag("--frame-attr"), DEFAULTS.frameAttr),
90
+ probe: pick("probe", flag("--probe"), DEFAULTS.probe),
91
+ known: pick("known", flag("--known"), null),
92
+ minMeasured: Number(pick("minMeasured", flag("--min-measured"), 1)),
93
+ reportJson: flag("--report-json") ?? null,
94
+ lazySelector: pick("lazySelector", flag("--lazy"), "[data-lazy-skeleton]"),
95
+ };
96
+
97
+ const problems = [];
98
+ if (!Array.isArray(settings.routes) || !settings.routes.length) problems.push("routes must name at least one path");
99
+ if (!Number.isFinite(settings.floor) || settings.floor <= 0) problems.push(`floor must be a positive number of px, not ${settings.floor}`);
100
+ if (settings.measure !== "cap" && settings.measure !== "line") problems.push(`measure must be "cap" or "line", not ${JSON.stringify(settings.measure)}`);
101
+ if (!settings.viewports.length || settings.viewports.some((w) => !Number.isFinite(w) || w < 200)) problems.push(`viewports must be widths of 200px or more, not ${settings.viewports}`);
102
+ if (!Number.isFinite(settings.minMeasured) || settings.minMeasured < 1) problems.push("minMeasured must be 1 or more: a run that measures nothing is not a pass");
103
+ if (problems.length) {
104
+ console.error(`✗ flush-edges check: bad settings.\n${problems.map((p) => ` ${p}`).join("\n")}`);
105
+ process.exit(1);
106
+ }
107
+
108
+ const failures = [];
109
+ let known = [];
110
+ if (settings.known) {
111
+ try {
112
+ known = JSON.parse(readFileSync(resolve(settings.known), "utf8")).known ?? [];
113
+ } catch (e) {
114
+ console.error(`✗ flush-edges check: cannot read the known findings in ${settings.known} (${e.message}).`);
115
+ process.exit(1);
116
+ }
117
+ for (const k of known) {
118
+ const exact = k.route && k.text && k.count === undefined;
119
+ const ratchet = (k.shipped || k.route) && !k.text && Number.isInteger(k.count) && k.count > 0;
120
+ if (!(exact || ratchet) || !k.reason || k.reason.length < 20)
121
+ failures.push(`${settings.known}: an entry needs route and text, or shipped (or route) and a whole count, and a reason of a sentence: ${JSON.stringify(k)}`);
122
+ }
123
+ }
124
+ const used = new Set();
125
+
126
+ let chromium;
127
+ try {
128
+ ({ chromium } = await import("playwright"));
129
+ } catch {
130
+ console.error("✗ flush-edges check: playwright is not installed. Install it (pnpm add -D playwright).");
131
+ process.exit(1);
132
+ }
133
+ let browser;
134
+ try {
135
+ browser = await chromium.launch();
136
+ } catch (e) {
137
+ console.error("✗ flush-edges check: no Chromium to drive. Run `pnpm exec playwright install chromium`.");
138
+ console.error(` ${String(e.message).split("\n")[0]}`);
139
+ process.exit(1);
140
+ }
141
+
142
+ const options = {
143
+ rootSelector: settings.root,
144
+ floor: settings.floor,
145
+ measure: settings.measure,
146
+ exceptAttr: settings.exceptAttr,
147
+ minReason: settings.minReason,
148
+ frameAttr: settings.frameAttr,
149
+ probe: settings.probe,
150
+ };
151
+ const totals = { measured: 0, excused: 0, dots: 0, pages: 0 };
152
+ const hits = new Map();
153
+ for (const width of settings.viewports) {
154
+ const page = await browser.newPage({ viewport: { width, height: 900 } });
155
+ page.setDefaultTimeout(30000);
156
+ for (const route of settings.routes) {
157
+ try {
158
+ const res = await page.goto(settings.base + route, { waitUntil: "networkidle", timeout: 60000 });
159
+ if (!res || res.status() >= 400) throw new Error(`HTTP ${res?.status() ?? "no response"}`);
160
+ await page.locator(settings.root).first().waitFor({ state: "attached" });
161
+ if (settings.lazySelector !== "") {
162
+ const unmounted = await mountEverything(page, { lazySelector: settings.lazySelector });
163
+ if (unmounted > 0) throw new Error(`${unmounted} deferred block(s) never mounted (${settings.lazySelector}), so they could not be measured`);
164
+ }
165
+ await page.evaluate(() => document.fonts.ready);
166
+ await page.waitForTimeout(500);
167
+ const r = await page.evaluate(`(${measureFlushEdges})(${JSON.stringify(options)})`);
168
+ totals.pages++;
169
+ totals.measured += r.measured;
170
+ totals.excused += r.excused;
171
+ totals.dots += r.dots ?? 0;
172
+ for (const b of r.badReasons) failures.push(`${route}: ${settings.exceptAttr} on ${b.box} needs a reason of ${settings.minReason} characters or more ("${b.text}")`);
173
+ for (const h of r.hits) {
174
+ const key = `${route}|${h.box}|${h.text}`;
175
+ const seen = hits.get(key);
176
+ if (seen) seen.widths.add(width);
177
+ else hits.set(key, { ...h, route, widths: new Set([width]) });
178
+ }
179
+ } catch (e) {
180
+ failures.push(`${route} at ${width}px: stopped because ${String(e.message).split("\n")[0]}`);
181
+ }
182
+ }
183
+ await page.close();
184
+ }
185
+ await browser.close();
186
+
187
+ const describeHit = (h) => {
188
+ const where = `${[...h.widths].join(" and ")}px${h.frame ? `, design ${h.frame}` : ""}${h.shipped ? `, shipped ${h.shipped}` : ""}`;
189
+ return `${h.route}: "${h.text}" is ${h.sides.join(", ")} from the edge of ${h.box} (${where})${h.overflows ? "; the text runs past the box's own padding, so the content is too long for it" : ""}`;
190
+ };
191
+ let knownCount = 0;
192
+ const ratchetHits = new Map();
193
+ for (const h of hits.values()) {
194
+ const k = known.find((x) => x.text && x.route === h.route && h.text.startsWith(x.text));
195
+ if (k) {
196
+ used.add(k);
197
+ knownCount++;
198
+ continue;
199
+ }
200
+ const r = h.shipped ? known.find((x) => !x.text && x.shipped === h.shipped) : known.find((x) => !x.text && !x.shipped && x.route === h.route);
201
+ if (r) {
202
+ if (!ratchetHits.has(r)) ratchetHits.set(r, []);
203
+ ratchetHits.get(r).push(h);
204
+ continue;
205
+ }
206
+ failures.push(describeHit(h));
207
+ }
208
+ for (const k of known) {
209
+ if (k.text) {
210
+ if (!single && !used.has(k)) failures.push(`${settings.known}: nothing matches ${k.route} / "${k.text}" any more. Remove the entry.`);
211
+ continue;
212
+ }
213
+ const got = ratchetHits.get(k) ?? [];
214
+ const name = k.shipped ? `the shipped ${k.shipped}` : `${k.route}'s own markup`;
215
+ if (got.length > k.count) {
216
+ failures.push(`${settings.known}: ${got.length} hit(s) in ${name}, over the ${k.count} recorded. A new one is not grandfathered:`);
217
+ for (const h of got) failures.push(` ${describeHit(h)}`);
218
+ } else {
219
+ knownCount += got.length;
220
+ if (!single && got.length < k.count) failures.push(`${settings.known}: ${name} now has ${got.length} hit(s), fewer than the ${k.count} recorded. Lower the count to ${got.length}${got.length ? "" : " (remove the entry)"}.`);
221
+ }
222
+ }
223
+ if (settings.reportJson) {
224
+ const { writeFileSync } = await import("node:fs");
225
+ writeFileSync(resolve(settings.reportJson), JSON.stringify([...hits.values()].map((h) => ({ ...h, widths: [...h.widths] })), null, "\t"));
226
+ }
227
+
228
+ const wanted = settings.routes.length * settings.viewports.length;
229
+ if (totals.pages < wanted || totals.measured < settings.minMeasured) {
230
+ console.error(`✗ flush-edges check: measured ${totals.measured} text node(s) on ${totals.pages} of ${wanted} page(s). The site, the routes or the root selector are wrong.`);
231
+ for (const f of failures.slice(0, 20)) console.error(` ${f}`);
232
+ process.exit(1);
233
+ }
234
+ if (failures.length) {
235
+ console.error(`✗ flush-edges check: ${failures.length} problem(s). Text must sit at least ${settings.floor}px inside the edge that holds it.\n`);
236
+ for (const f of failures) console.error(` ${f}`);
237
+ console.error(
238
+ `\n Give the container a real inset (the 8px step or more, more again beside a round end). If the text is meant to touch the edge,\n` +
239
+ ` say why on the container: ${settings.exceptAttr}="<reason>". A shipped component you must not restyle goes in the known file.`,
240
+ );
241
+ process.exit(1);
242
+ }
243
+ console.log(
244
+ `✓ flush-edges check: ${totals.measured} text node(s) on ${totals.pages} page(s) (${settings.routes.length} route(s) at ${settings.viewports.join(" and ")}px), all ${settings.floor}px or more inside their edge (${settings.measure} measure); ${totals.excused} excused with ${settings.exceptAttr}, ${knownCount} known finding(s), ${totals.dots} centred mark(s) in a dot not measured.`,
245
+ );
@@ -0,0 +1,239 @@
1
+ # Design system checks (advisory)
2
+
3
+ These checks run on every pull request and report on the lines the pull request adds. They never block a merge. Existing code is never flagged, so you can install them on a large codebase on day one.
4
+
5
+ The kit ships in `@behavioral-agentic-design-system/core` as the `bads-ds-advisory` command. It imports only Node built-ins.
6
+
7
+ ## Install it in your repo
8
+
9
+ 1. Add the package as a dependency of your repo root:
10
+
11
+ ```bash
12
+ pnpm add -D @behavioral-agentic-design-system/core
13
+ ```
14
+
15
+ 1. Copy the workflow into your repo:
16
+
17
+ ```bash
18
+ cp node_modules/@behavioral-agentic-design-system/core/scripts/design-system-advisory/workflow.yml \
19
+ .github/workflows/design-system-advisory.yml
20
+ ```
21
+
22
+ The workflow installs your dependencies so that `npx bads-ds-advisory` finds the installed command. If your repo has its own install command, replace the **Install dependencies** step with it.
23
+
24
+ 1. Point the checks at your code. Add a `designSystemAdvisory` key to `.bads-lint.json` at your repo root. Create the file if it does not exist. For example:
25
+
26
+ ```json
27
+ {
28
+ "designSystemAdvisory": {
29
+ "include": ["^(apps/[^/]+/src|packages/ui/src)/.+\\.(tsx|jsx|ts)$"],
30
+ "atomsPath": "packages/ui/src/atoms/",
31
+ "components": {
32
+ "Select": { "name": "Dropdown", "importPath": "@acme/ui/atoms/dropdown" }
33
+ },
34
+ "checks": {
35
+ "label-case": { "properNouns": ["Acme Cloud"] },
36
+ "icon-sizing": { "iconDirs": ["packages/ui/src/icons"] }
37
+ },
38
+ "rulesDoc": "docs/design-system.md",
39
+ "readmePath": "docs/design-system-checks.md"
40
+ }
41
+ }
42
+ ```
43
+
44
+ 1. To confirm the setup, run the checks on your branch:
45
+
46
+ ```bash
47
+ npx bads-ds-advisory
48
+ ```
49
+
50
+ ## The checks
51
+
52
+ | Check | ID | Flags | Exempt a line with |
53
+ | --- | --- | --- | --- |
54
+ | Small text | `small-text` | A named class under the floor (Tailwind's `text-xs` is 12px), `text-[Npx]` or `text-[Nrem]` under the floor, inline `fontSize` under the floor | `type-scale-ok: <who chose this size and why>` |
55
+ | Raw values | `raw-values` | `bg-[#1d4ed8]`, `text-[rgb(...)]`, inline `color: "#f00"`, arbitrary sizes such as `w-[437px]` or `p-[1.5rem]` | `raw-value-ok: <why>` |
56
+ | Tap target | `tap-target` | A fixed `h-`, `w-` or `size-` class under 44px (`h-8`, `size-6`) on a button or a tag with `onClick`. `min-h-11 min-w-11` clears it | `tap-target-ok: <why>` |
57
+ | Hand-built button | `hand-built-button` | A native `<button>` with its own fill and rounded corners, which is the design system's `Button` drawn by hand | `hand-built-ok: <why>` |
58
+ | Native form control | `native-form-control` | A native `<input>`, `<select>` or `<textarea>`, which is a design-system control drawn by hand. Hidden and file inputs pass | `native-control-ok: <why>` |
59
+ | Uneven padding | `even-padding` | `px-N` and `py-M` with different values on one line | `uneven-padding-ok: <why>` |
60
+ | Title Case label | `label-case` | Title Case in button text and in `label`, `cta`, `title`, `ctaLabel` and `buttonText` props | `label-case-ok: <why>` |
61
+ | Copy punctuation | `copy-punctuation` | An em dash, three typed periods, or a typed `\uXXXX` in JSX text | `copy-ok: <why>` |
62
+ | Corner radius | `radius` | A button with words that is `rounded-full`, and `rounded-[var(--...)]` | `radius-ok: <role>` |
63
+ | Icon size class ignored | `icon-sizing` | `size-N`, `h-N` or `w-N` on an icon component that never reads `className` | `icon-size-ok: <why>` |
64
+ | Block inside a paragraph | `html-nesting` | A `<div>`, list, heading or other block inside a native `<p>` | `html-nesting-ok: <why>` |
65
+
66
+ Each check also explains itself in the comment at the top of its own `check-*.mjs` file.
67
+
68
+ 14px is a soft floor for new text. Avoid smaller text wherever you can. If a person chooses a smaller size, build it and flag it with the marker, naming who chose it and why.
69
+
70
+ ## Settings
71
+
72
+ The checks read their settings from the `designSystemAdvisory` key of `.bads-lint.json` at the repo root. To read another file, pass `--config=<file>`. `.bads-lint.json` is the same file that `bads-lint-target-size` reads for `minTargetPx`.
73
+
74
+ Flags win over the file, and the file wins over the defaults. Objects merge key by key. An array in the file replaces the default array, so a custom `include` does not keep the default paths. The one exception is `checks["label-case"].properNouns`, which adds to the built-in list.
75
+
76
+ | Setting | Default | What it does |
77
+ | --- | --- | --- |
78
+ | `include` | `["^(app\|components\|packages/core/src)/.+\\.(tsx\|jsx\|ts)$"]` | Regular expressions for the repo-relative paths to scan |
79
+ | `exclude` | Tests, specs, stories, mocks, e2e, snapshots, generated code, `.d.ts` | Regular expressions for paths to skip, even when they match `include` |
80
+ | `baseRef` | `"origin/main"` | The branch a run compares with when you pass no `--base` |
81
+ | `components` | The BADS primitives: `Button`, `Input`, `Textarea`, `NativeSelect`, `Checkbox`, `RadioGroup` under `@behavioral-agentic-design-system/core/components/ui/` | What a hand-built control is replaced with. Keys are `Button`, `Input`, `TextArea`, `Select`, `Checkbox` and `Radio`. Each value is `{ "name", "importPath" }` |
82
+ | `componentRoots` | `[{ "dir": "packages/core/src/components/ui", "importPrefix": "@behavioral-agentic-design-system/core/components/ui", "layer": "ui" }]` | The folders `listComponents()` reads |
83
+ | `atomsPath` | `"packages/core/src/components/ui/"` | A regular expression for the folder that holds the real controls. `native-form-control` skips it |
84
+ | `rulesDoc` | `null` | The rules document the PR comment names. `null` leaves it out |
85
+ | `readmePath` | This file, under `node_modules` | The page the PR comment points to for reproducing a run |
86
+ | `checks.<id>` | On | `false` switches a check off. An object changes that check's settings |
87
+ | `checks.small-text.floorPx` | `14` | The text size floor in px |
88
+ | `checks.small-text.namedSizes` | `{ "text-xs": 12 }` | Named text classes and their size in px. Set your theme's real value. BADS sets `text-xs` to 14 |
89
+ | `checks.small-text.suggest` | `"text-sm"` | The class the fix suggests |
90
+ | `checks.tap-target.minPx` | The top-level `minTargetPx` in `.bads-lint.json`, then `44` | The tap target floor in px |
91
+ | `checks.tap-target.unitPx` | `4` | Pixels per spacing unit. The unit floor is `minPx / unitPx`, so 44px is `h-11` |
92
+ | `checks.label-case.properNouns` | `[]` | Proper nouns to add to the built-in list (months, days, `I`, `US`, `USA` and large brands such as Google, Apple, Stripe, PayPal, Visa and Mastercard). A noun of several words passes only as the whole phrase |
93
+ | `checks.label-case.properNounsFile` | `"label-case-nouns.json"` | A JSON file of the form `{ "properNouns": [...] }`. `bads-lint-label-case` reads the same file |
94
+ | `checks.label-case.props` | `["label", "cta", "title", "ctaLabel", "buttonText"]` | Prop and key names that hold a label |
95
+ | `checks.raw-values.tokenExamples` | `"bg-background or text-destructive"` | The token classes the fix names |
96
+ | `checks.raw-values.opacityExample` | `"bg-foreground/50"` | The opacity modifier example the fix names |
97
+ | `checks.radius.buttonRadius` | `` "`rounded-md`, the radius `Button` uses" `` | The radius the fix suggests for a button with words |
98
+ | `checks.radius.utilities` | The `rounded` utilities | The classes the fix suggests in place of a radius variable |
99
+ | `checks.icon-sizing.iconDirs` | `[]` | Folders of icon components. With none, the check reports nothing |
100
+
101
+ To change a setting for one run, use a flag:
102
+
103
+ | Flag | What it does |
104
+ | --- | --- |
105
+ | `--include=<regex>`, `--exclude=<regex>` | Replace the scope. Repeat the flag for more than one pattern |
106
+ | `--off=<check-id>` | Switch a check off. Repeatable |
107
+ | `--base-ref=<ref>` | Compare with another branch |
108
+ | `--set=<dotted.path>=<value>` | Set any setting. The value is read as JSON, or as text when it is not JSON. For example, `--set=checks.small-text.floorPx=16` |
109
+ | `--config=<file>` | Read the settings from another file |
110
+
111
+ ## Exempt a line
112
+
113
+ To exempt a line, put the marker in a comment on the same line or the line above. The marker needs a reason after a colon. A bare marker does nothing.
114
+
115
+ ```tsx
116
+ {/* type-scale-ok: hint under a field, the designer chose 12px */}
117
+ <p className="text-xs">...</p>
118
+ ```
119
+
120
+ Keep the comment on one line directly above the line you exempt. A comment that your formatter splits over three lines (`{`, the comment, `}`) sits two lines above the element and does not count.
121
+
122
+ The check looks for the marker name anywhere on the line or the line above, not only inside a comment. Text on the same line that contains the marker name and a reason, such as `<p>type-scale-ok: x</p>`, also exempts the line. Do not rely on this.
123
+
124
+ ## What it scans
125
+
126
+ - Only lines **added** in the pull request. Existing code is never flagged.
127
+ - Files that match `include` and no `exclude`.
128
+ - Skipped on purpose: media query variants (`min-[640px]:`), border widths, percentages, `calc()` and `var()` values.
129
+
130
+ It is a line pattern match, not a parser. It misses values built at run time and can flag a value that is fine. A false positive is useful feedback. See [Report a false positive or a miss](#report-a-false-positive-or-a-miss).
131
+
132
+ ## Test it locally
133
+
134
+ You need Node 20 or later. Run the commands from the repo root. In BADS, the kit is at `packages/core/scripts/design-system-advisory/`. In a client repo, it is under `node_modules/@behavioral-agentic-design-system/core/scripts/design-system-advisory/`.
135
+
136
+ ### Run the unit tests
137
+
138
+ In BADS:
139
+
140
+ ```bash
141
+ node --test packages/core/scripts/design-system-advisory/advisory.test.mjs
142
+ ```
143
+
144
+ `pnpm test:scripts` runs the same tests with the other script tests.
145
+
146
+ ### Run it on the fixtures
147
+
148
+ ```bash
149
+ node packages/core/scripts/design-system-advisory/run.mjs \
150
+ --file=packages/core/scripts/design-system-advisory/fixtures/violations.tsx.fixture
151
+ ```
152
+
153
+ The run reads your `.bads-lint.json`, so the count depends on your settings. With the default settings, expect 11 findings (5 small text, 6 raw values) and `exit code is 0`. With BADS's own `.bads-lint.json`, where `text-xs` is 14px, expect 9. The two lines marked `OK` in the fixture produce nothing, which shows that the markers work.
154
+
155
+ ```bash
156
+ node packages/core/scripts/design-system-advisory/run.mjs \
157
+ --file=packages/core/scripts/design-system-advisory/fixtures/clean.tsx.fixture
158
+ ```
159
+
160
+ Expected: `No findings in 1 scanned file(s).`
161
+
162
+ ### Run it the way a pull request does
163
+
164
+ 1. On a throwaway branch, add a violation to a file in scope:
165
+
166
+ ```tsx
167
+ <p className="text-[11px] bg-[#1d4ed8] w-[437px]">test</p>
168
+ ```
169
+
170
+ 1. Commit it, then run the checks against `main`:
171
+
172
+ ```bash
173
+ pnpm check:ds-advisory
174
+ ```
175
+
176
+ Expected: three findings, each with the file, the line you added, and a fix. Nothing else in the file is reported. Run `echo $?` and check that it prints `0`.
177
+
178
+ 1. Change the line to `text-sm bg-background w-12` and run again. Expected: no findings.
179
+
180
+ Other options:
181
+
182
+ ```bash
183
+ pnpm check:ds-advisory -- --format=markdown # the PR comment text
184
+ pnpm check:ds-advisory -- --format=github # the annotation lines
185
+ pnpm check:ds-advisory -- --base=<sha> --head=<sha>
186
+ pnpm check:ds-advisory -- --strict # exit 1 on findings, to see what blocking would look like
187
+ ```
188
+
189
+ ## Test it in CI
190
+
191
+ 1. Push your scratch branch and open a **draft** pull request. Do not merge it.
192
+ 1. The **Design system checks (advisory)** job runs.
193
+ 1. Confirm each of these:
194
+ - The job finishes. An orange warning icon rather than a red cross is expected.
195
+ - On the **Files changed** tab, a warning annotation sits on each line you added, and only on those lines.
196
+ - The pull request has one comment that starts with "Design system checks (advisory)" and has a table of findings.
197
+ - When you push a fix commit, the same comment updates (no new comment appears) and says no findings.
198
+ - Merging is not blocked. The job is not a required check.
199
+ 1. Close the pull request and delete the branch.
200
+
201
+ ## What good looks like
202
+
203
+ - Every finding is on a line the pull request added.
204
+ - The fix text tells you what to do without reading anything else.
205
+ - Nothing flagged is something you would defend writing.
206
+
207
+ ## Report a false positive or a miss
208
+
209
+ Open an issue on the BADS repo. Include the line of code, what the check said, and what it should have said. Each report improves the pattern or becomes a test case in `advisory.test.mjs`.
210
+
211
+ ## Move a check to blocking
212
+
213
+ To make the checks block a merge, remove `continue-on-error` from the job, pass `--strict`, and add the job to your required checks. Wait until the advisory run has a low false-positive rate and the owning team agrees.
214
+
215
+ ## Files
216
+
217
+ | File | Purpose |
218
+ | --- | --- |
219
+ | `run.mjs` | Entry point (`bads-ds-advisory`). Reads the settings and the diff, runs the checks, and prints the report |
220
+ | `lib.mjs` | Settings, diff parsing, scope rules, marker handling, and `listComponents()` |
221
+ | `defaults.mjs` | The default settings and the built-in proper nouns |
222
+ | `check-*.mjs` | One check each |
223
+ | `fixtures/` | One file that violates and one that passes |
224
+ | `advisory.test.mjs` | Unit tests (`node:test`) |
225
+ | `workflow.yml` | The workflow a client copies into `.github/workflows/` |
226
+
227
+ ## Add a check
228
+
229
+ Every `check-*.mjs` in this folder loads automatically. There is nothing to register. Export an object with these fields:
230
+
231
+ | Field | What it is |
232
+ | --- | --- |
233
+ | `id`, `title` | The short name, and the heading used in the PR comment |
234
+ | `marker` | The comment text that exempts a line, for example `raw-value-ok` |
235
+ | `order` | Optional. Lower runs and reports first. The default is 100 |
236
+ | `scanLine(text, settings)` | For a rule one line can show. Returns hits |
237
+ | `scanFile({ file, lines, text, settings })` | For a rule that needs more than one line. `lines` are the lines the pull request added, and `text` is the whole file or `null`. Return hits that carry a `line` |
238
+
239
+ `settings` is the check's own entry under `checks.<id>`, merged over its defaults, with the whole run's settings under `$all`. Put a new check's defaults in `defaults.mjs`. A hit is `{ found, message, fix }`. Hits on lines the pull request did not add are dropped. Add unit tests to `advisory.test.mjs` and a row to the table in [The checks](#the-checks).
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Copy punctuation. Flags an em dash, three typed periods and a typed `\uXXXX` in JSX text.
3
+ *
4
+ * A person reads this text. Use a comma, a period or parentheses instead of an em dash.
5
+ * Use the ellipsis character `…`, not `...`. Use the character itself, not its escape code.
6
+ * An en dash is right for a range. A spread (`...rest`) is not copy and passes.
7
+ *
8
+ * Mark text only the team reads with `copy-ok: <why>` on the line or the line above.
9
+ */
10
+ const EM_DASH = /\u2014/;
11
+ const THREE_DOTS = /(?<=[\w"'`!?)])\.\.\.(?=["'`<\s}]|$)/;
12
+ const TYPED_ESCAPE = />[^<{]*\\u[0-9a-fA-F]{4}/;
13
+
14
+ export const copyPunctuation = {
15
+ id: "copy-punctuation",
16
+ title: "Copy punctuation",
17
+ marker: "copy-ok",
18
+ order: 70,
19
+ scanLine(text) {
20
+ const hits = [];
21
+ if (EM_DASH.test(text)) {
22
+ hits.push({
23
+ found: "—",
24
+ message: "An em dash does not survive being read aloud.",
25
+ fix: "Use a comma, a period or parentheses. An en dash `–` is right for a range. If only the team reads this string, flag it with `copy-ok: <why>`.",
26
+ });
27
+ }
28
+ if (THREE_DOTS.test(text)) {
29
+ hits.push({
30
+ found: "...",
31
+ message: "Three typed periods are not the ellipsis character.",
32
+ fix: "Use `…`. If only the team reads this string, flag it with `copy-ok: <why>`.",
33
+ });
34
+ }
35
+ if (TYPED_ESCAPE.test(text)) {
36
+ hits.push({
37
+ found: "\\u",
38
+ message: "A typed escape code in JSX text renders exactly as typed.",
39
+ fix: "Write the character itself, or put the string in braces: `{\"\\u2019\"}`.",
40
+ });
41
+ }
42
+ return hits;
43
+ },
44
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Even padding. Flags `px-N` paired with a different `py-N` on one line.
3
+ *
4
+ * Padding is the same on every side unless a person chose otherwise and said why.
5
+ * `px-3 py-1` is two values picked one at a time. Grow the smaller side to match and use `p-3`.
6
+ * This check reads one line. It does not see padding split across lines or built by `cn()`.
7
+ *
8
+ * Mark an intended exception with `uneven-padding-ok: <why>` on the line or the line above.
9
+ */
10
+ const PAD = /(?<![\w-])((?:[a-z0-9-]+:)*)p([xy])-(\d+(?:\.\d+)?|\[[^\]\s]+\])(?![\w./[-])/g;
11
+
12
+ export const evenPadding = {
13
+ id: "even-padding",
14
+ title: "Uneven padding",
15
+ marker: "uneven-padding-ok",
16
+ order: 50,
17
+ scanLine(text) {
18
+ const seen = new Map();
19
+ for (const m of text.matchAll(PAD)) {
20
+ const entry = seen.get(m[1]) ?? {};
21
+ entry[m[2]] = m[3];
22
+ seen.set(m[1], entry);
23
+ }
24
+ const hits = [];
25
+ for (const [variant, { x, y }] of seen) {
26
+ if (x === undefined || y === undefined || x === y) continue;
27
+ hits.push({
28
+ found: `${variant}px-${x} ${variant}py-${y}`,
29
+ message: `Padding is ${x} beside and ${y} above. Nobody said why.`,
30
+ fix: `Grow the smaller side to match and use \`${variant}p-${Number(x) > Number(y) || Number.isNaN(Number(y)) ? x : y}\`. If a person chose uneven padding, flag it with \`uneven-padding-ok: <why>\`.`,
31
+ });
32
+ }
33
+ return hits;
34
+ },
35
+ };
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Hand-built button. Flags a native `button` that is drawn as a filled, rounded button.
3
+ *
4
+ * The design system ships `Button`. It has the right sizes, states, focus ring and tap target. A
5
+ * `button` with its own fill and rounded corners is a second copy that drifts from it. A `button`
6
+ * with no fill, such as a text link or an icon button, is fine.
7
+ *
8
+ * Settings: `components.Button` (`{ name, importPath }`), the component the fix names.
9
+ *
10
+ * Mark an intended exception with `hand-built-ok: <why>` on the line or the line above.
11
+ */
12
+ import { settingsFor } from "./lib.mjs";
13
+
14
+ const ID = "hand-built-button";
15
+ const LOOK_AHEAD = 8;
16
+ const FILLED = /(?<![\w-])bg-(?!transparent\b|none\b)[a-z]/;
17
+ const ROUNDED = /(?<![\w-])rounded(?!-full\b)(?![\w-]*-none)/;
18
+
19
+ export const handBuiltButton = {
20
+ id: ID,
21
+ title: "Hand-built button",
22
+ marker: "hand-built-ok",
23
+ order: 30,
24
+ scanFile({ lines, text, settings }) {
25
+ if (text === null) return [];
26
+ const { name, importPath } = settingsFor(settings, ID).$all.components.Button;
27
+ const all = text.split("\n");
28
+ const hits = [];
29
+ for (const { n, text: line } of lines) {
30
+ if (!/<button\b/.test(line)) continue;
31
+ const opening = [];
32
+ for (let i = n - 1; i < Math.min(all.length, n - 1 + LOOK_AHEAD); i++) {
33
+ opening.push(all[i]);
34
+ if (/>\s*$/.test(all[i]) && !/=>\s*$/.test(all[i])) break;
35
+ }
36
+ if (!FILLED.test(opening.join("\n")) || !ROUNDED.test(opening.join("\n"))) continue;
37
+ hits.push({
38
+ line: n,
39
+ found: "<button>",
40
+ message: `A native button with its own fill and rounded corners is a hand-built copy of \`${name}\`.`,
41
+ fix: `Use \`${name}\` from \`${importPath}\`. If the design system has no variant you need, flag it with \`hand-built-ok: <why>\`.`,
42
+ });
43
+ }
44
+ return hits;
45
+ },
46
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * HTML nesting. Flags a block element inside a native `<p>`.
3
+ *
4
+ * A `<p>` holds phrasing content only. A `<div>`, `<p>`, list, heading, `<section>`, `<article>`,
5
+ * `<hr>` or `<table>` inside it throws React hydration error #418 in the browser while the build passes.
6
+ * This check reads source, so it sees native tags only. A component that renders a `<div>` on its
7
+ * own, such as `Separator`, is not seen. Look at the rendered HTML for those.
8
+ *
9
+ * Mark an intended exception with `html-nesting-ok: <why>` on the line or the line above.
10
+ */
11
+ const BLOCK = /<(div|ul|ol|li|section|article|hr|table|h[1-6])(?=[\s/>])/g;
12
+ const OPEN_P = /<p(?=[\s>])/g;
13
+
14
+ export const htmlNesting = {
15
+ id: "html-nesting",
16
+ title: "Block inside a paragraph",
17
+ marker: "html-nesting-ok",
18
+ order: 100,
19
+ scanFile({ lines, text }) {
20
+ if (text === null) return [];
21
+ const added = new Set(lines.map((l) => l.n));
22
+ const all = text.split("\n");
23
+ const hits = [];
24
+ let depth = 0;
25
+ for (let i = 0; i < all.length; i++) {
26
+ const line = all[i];
27
+ const events = [];
28
+ for (const m of line.matchAll(OPEN_P)) events.push({ at: m.index, kind: "open" });
29
+ for (const m of line.matchAll(/<\/p>/g)) events.push({ at: m.index, kind: "close" });
30
+ for (const m of line.matchAll(BLOCK)) events.push({ at: m.index, kind: "block", tag: m[1] });
31
+ events.sort((a, b) => a.at - b.at);
32
+ for (const e of events) {
33
+ if (e.kind === "open") {
34
+ if (depth > 0 && added.has(i + 1)) hits.push(nested(i + 1, "p"));
35
+ depth++;
36
+ } else if (e.kind === "close") depth = Math.max(0, depth - 1);
37
+ else if (depth > 0 && added.has(i + 1)) hits.push(nested(i + 1, e.tag));
38
+ }
39
+ }
40
+ return hits;
41
+ },
42
+ };
43
+
44
+ function nested(line, tag) {
45
+ return {
46
+ line,
47
+ found: `<${tag}>`,
48
+ message: `A \`<${tag}>\` inside a \`<p>\` is invalid HTML. React reports hydration error #418.`,
49
+ fix: "Change the outer `<p>` to a `<div>`, or move the block out of it. If it is deliberate, flag it with `html-nesting-ok: <why>`.",
50
+ };
51
+ }