@starci/eslint-grammar-core 0.27.1 → 0.30.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 (46) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +3 -1
  3. package/dist/button-arrow.d.ts +7 -0
  4. package/dist/button-arrow.js +146 -0
  5. package/dist/field-label.d.ts +7 -0
  6. package/dist/field-label.js +83 -0
  7. package/dist/gap-proximity.d.ts +7 -0
  8. package/dist/gap-proximity.js +194 -0
  9. package/dist/index.js +22 -0
  10. package/dist/lib/cross-file-inputs.js +3 -0
  11. package/dist/lib/grammar-jsx.d.ts +27 -0
  12. package/dist/lib/grammar-jsx.js +136 -0
  13. package/dist/lib/row-context.d.ts +25 -0
  14. package/dist/lib/row-context.js +134 -0
  15. package/dist/lib/why.js +60 -0
  16. package/dist/page-breadcrumbs.d.ts +7 -0
  17. package/dist/page-breadcrumbs.js +103 -0
  18. package/dist/row-title-link.d.ts +6 -0
  19. package/dist/row-title-link.js +172 -0
  20. package/dist/same-line-size.d.ts +6 -0
  21. package/dist/same-line-size.js +93 -0
  22. package/dist/single-child-card.d.ts +7 -0
  23. package/dist/single-child-card.js +103 -0
  24. package/dist/suggestion-chips.d.ts +6 -0
  25. package/dist/suggestion-chips.js +122 -0
  26. package/dist/surface-card.js +1 -1
  27. package/dist/surface-in-surface.d.ts +7 -0
  28. package/dist/surface-in-surface.js +84 -0
  29. package/dist/table-cell-type.d.ts +6 -0
  30. package/dist/table-cell-type.js +122 -0
  31. package/dist/tabs.d.ts +9 -0
  32. package/dist/tabs.js +147 -0
  33. package/docs/button-arrow.md +34 -0
  34. package/docs/field-label.md +26 -0
  35. package/docs/gap-proximity.md +31 -0
  36. package/docs/page-breadcrumbs.md +28 -0
  37. package/docs/row-title-link.md +30 -0
  38. package/docs/same-line-size.md +26 -0
  39. package/docs/single-child-card.md +37 -0
  40. package/docs/suggestion-chips.md +31 -0
  41. package/docs/surface-in-surface.md +28 -0
  42. package/docs/table-cell-type.md +32 -0
  43. package/docs/tabs.md +48 -0
  44. package/package.json +4 -4
  45. package/runtime/bundle.json +1 -0
  46. package/runtime/knowledge/ui/presentation/grammar-laws.yaml +121 -0
@@ -0,0 +1,122 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
+ import { attributeOf, descendants, elementOf, grammarBindings, isListRow, keyName, literalAttribute, propertyOf } from "./lib/row-context.js";
4
+ /**
5
+ * The table and row type law (`FE_TABLE_CELL_TYPE`): the cells of a DataTable and the copy of a ListRow take the row type sizes,
6
+ * the primary at md 14 / 500 (`Text isStrong`) and the secondary at sm 13 muted (`Text size="sm" tone="muted"`). A heading-size
7
+ * Text, a `Heading`, a `Label` or an `h1`-`h6` in a cell or a row is a heading drawn in a list.
8
+ *
9
+ * WHAT IT READS.
10
+ * - the function a `DataTable` takes as `renderCell` (inline, or a function or arrow declared by name in the file), and the
11
+ * `editor` function of a column object in its `columns` literal;
12
+ * - the `title` and `description` of a ListRow data object: a row of the `items` of a list collection (`{ kind: "list", items }`,
13
+ * or `Section` / `SurfaceCard` written `kind="list"`), through `.map` callbacks, or the `row` of a `<ListRow>`.
14
+ * In those, `Text size="figure"`, any `Heading`, any `Label` and the tags `h1`-`h6` are findings. A row list declared elsewhere
15
+ * and passed by name is not followed.
16
+ */
17
+ const HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
18
+ const isFunction = (node) => node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration";
19
+ export const tableCellType = defineRule({
20
+ meta: {
21
+ type: "problem",
22
+ docs: { description: "FE_TABLE_CELL_TYPE: no heading-size Text, Heading, Label or h1-h6 in a DataTable cell or a ListRow." },
23
+ schema: [],
24
+ messages: {
25
+ heading: "{{what}} in {{where}} is a heading drawn in a list. The primary of a row or a cell is md 14 / 500 (`<Text isStrong>`), the secondary sm 13 muted (`<Text size=\"sm\" tone=\"muted\">`).",
26
+ },
27
+ },
28
+ create(context) {
29
+ if (!isProductSource(context))
30
+ return {};
31
+ let bound = new Map();
32
+ const source = context.sourceCode;
33
+ const reported = new Set();
34
+ /** Report every heading-size element under a node. */
35
+ const scan = (root, where) => {
36
+ for (const node of descendants(root, source)) {
37
+ if (node.type !== "JSXElement" || reported.has(node))
38
+ continue;
39
+ const { grammar, tag } = elementOf(node.openingElement, bound);
40
+ let what = null;
41
+ if (grammar === "Text" && literalAttribute(node.openingElement, "size") === "figure")
42
+ what = "`Text size=\"figure\"`";
43
+ else if (grammar === "Heading" || grammar === "Label")
44
+ what = `\`${grammar}\``;
45
+ else if (tag !== null && HEADING_TAGS.has(tag))
46
+ what = `\`<${tag}>\``;
47
+ if (what === null)
48
+ continue;
49
+ reported.add(node);
50
+ context.report({ node, messageId: "heading", data: { what, where } });
51
+ }
52
+ };
53
+ /** The function a renderCell expression names: itself, or a function declared by that name in this file. */
54
+ const functionOf = (expression) => {
55
+ if (isFunction(expression))
56
+ return expression;
57
+ if (expression.type !== "Identifier")
58
+ return null;
59
+ let scope = source.getScope(expression);
60
+ while (scope) {
61
+ const variable = scope.set.get(expression.name);
62
+ if (variable) {
63
+ for (const def of variable.defs) {
64
+ if (def.type === "FunctionName")
65
+ return def.node;
66
+ {
67
+ const init = def.node.init;
68
+ if (init && isFunction(init))
69
+ return init;
70
+ }
71
+ }
72
+ return null;
73
+ }
74
+ scope = scope.upper;
75
+ }
76
+ return null;
77
+ };
78
+ return {
79
+ Program(program) {
80
+ bound = grammarBindings(program);
81
+ },
82
+ JSXElement(element) {
83
+ if (elementOf(element.openingElement, bound).grammar !== "DataTable")
84
+ return;
85
+ const render = attributeOf(element.openingElement, "renderCell")?.value;
86
+ if (render?.type === "JSXExpressionContainer") {
87
+ const fn = functionOf(render.expression);
88
+ if (fn)
89
+ scan(fn, "a DataTable cell");
90
+ }
91
+ const columns = attributeOf(element.openingElement, "columns")?.value;
92
+ if (columns?.type !== "JSXExpressionContainer" || columns.expression.type !== "ArrayExpression")
93
+ return;
94
+ for (const column of columns.expression.elements) {
95
+ if (column?.type !== "ObjectExpression")
96
+ continue;
97
+ const editor = propertyOf(column, "editor")?.value;
98
+ if (editor && isFunction(editor))
99
+ scan(editor, "a DataTable cell");
100
+ }
101
+ },
102
+ ObjectExpression(object) {
103
+ if (!isListRow(object, bound))
104
+ return;
105
+ for (const property of object.properties) {
106
+ if (property.type !== "Property")
107
+ continue;
108
+ const name = keyName(property);
109
+ if (name === "title" || name === "description")
110
+ scan(property.value, "a ListRow");
111
+ }
112
+ },
113
+ };
114
+ },
115
+ });
116
+ /** The rules this law contributes to the plugin. */
117
+ export const rules = {
118
+ "table-cell-type": tableCellType,
119
+ };
120
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#TABLE-CELL-TYPE");
121
+ /** Every rule of this law is an error. */
122
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
package/dist/tabs.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ import type { Rule } from "eslint";
2
+ /** No pill in JSX: the pill is the `switch` header zone of a card. */
3
+ export declare const tabsSwitchZone: Rule.RuleModule;
4
+ /** At most two underline layers. */
5
+ export declare const tabsDepth: Rule.RuleModule;
6
+ /** The rules this law contributes to the plugin. */
7
+ export declare const rules: Record<string, Rule.RuleModule>;
8
+ /** Every rule of this law is an error. */
9
+ export declare const recommended: Record<string, "error">;
package/dist/tabs.js ADDED
@@ -0,0 +1,147 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
+ /**
4
+ * The Tabs laws (`contexts/ui/components/tabs.md`, owner-approved 2026-11-09): where the pill stands, and how many
5
+ * underline layers a page stacks.
6
+ *
7
+ * `tabs-switch-zone`. The pill (`Tabs appearance="primary"`) is a mode or period switch of one block. The Grammar draws it
8
+ * only as the `switch` header zone of a `SurfaceCard` (`headers={[{ kind: "switch", label, items, selectedKey, onSelect }]}`);
9
+ * a `<Tabs appearance="primary">` written in JSX (a page body, under the page tabs, a pane, a drawer) is a finding. The
10
+ * item checks (two to four, no count, no href) stay in `no-primary-tabs-misuse`.
11
+ *
12
+ * `tabs-depth`. A page stacks at most two underline layers: the page tabs (`Page header.tabs`) and one region set. A `Tabs`
13
+ * is nested in another when it stands in the panel the other selects: inside a conditional or `&&` whose test reads the
14
+ * other's `selectedKey`, or, for page tabs, in the children of a `Page` whose `header` carries `tabs`. A drawer, dialog,
15
+ * modal, popover or sheet starts its own surface and ends the climb. Every tab is one size, so a layer's size is not judged; only the count is.
16
+ */
17
+ /** The element name of a JSX opening element (`Tabs`, or `Grammar.Tabs` as `Tabs`). */
18
+ const elementName = (opening) => {
19
+ const name = opening.name;
20
+ if (name.type === "JSXIdentifier")
21
+ return name.name;
22
+ if (name.type === "JSXMemberExpression")
23
+ return name.property.name;
24
+ return null;
25
+ };
26
+ /** The attribute of an opening element by name, or undefined. */
27
+ const attributeOf = (opening, name) => opening.attributes.find((entry) => entry.type === "JSXAttribute" && entry.name.type === "JSXIdentifier" && entry.name.name === name);
28
+ /** The string literal an attribute passes (`kind="filter"` or `kind={"filter"}`), or null when it is absent or dynamic. */
29
+ const literalOf = (attribute) => {
30
+ if (attribute === undefined || attribute.value === null)
31
+ return null;
32
+ const value = attribute.value.type === "JSXExpressionContainer" ? attribute.value.expression : attribute.value;
33
+ return value.type === "Literal" && typeof value.value === "string" ? value.value : null;
34
+ };
35
+ /** Whether a `Tabs` element draws the pill. */
36
+ const isPill = (opening) => literalOf(attributeOf(opening, "appearance")) === "primary";
37
+ /** No pill in JSX: the pill is the `switch` header zone of a card. */
38
+ export const tabsSwitchZone = defineRule({
39
+ meta: {
40
+ type: "problem",
41
+ docs: {
42
+ description: "A pill (Tabs appearance=\"primary\") stands only as the switch header zone of a SurfaceCard; written in JSX anywhere else it is a finding.",
43
+ url: "knowledge/ui/presentation/grammar-laws.yaml#TABS-SWITCH-ZONE",
44
+ },
45
+ schema: [],
46
+ messages: {
47
+ pill: "A pill (`Tabs appearance=\"primary\"`) switches a mode or period of one block and is drawn only as the `switch` header zone of its card: `headers={[{ kind: \"switch\", label, items, selectedKey, onSelect }]}`, two to four short options with no count and no href. Written here it stands loose in the page. Views of a page are page tabs (`Page header.tabs`); views or filters inside a region are underline `Tabs`.",
48
+ },
49
+ },
50
+ create(context) {
51
+ if (!isProductSource(context))
52
+ return {};
53
+ return {
54
+ JSXOpeningElement(opening) {
55
+ if (elementName(opening) !== "Tabs" || !isPill(opening))
56
+ return;
57
+ context.report({ node: opening, messageId: "pill" });
58
+ },
59
+ };
60
+ },
61
+ });
62
+ /** A boundary that starts its own surface: the page tabs above it are not its parent layer. */
63
+ const SURFACE_BOUNDARIES = new Set(["Drawer", "Dialog", "Modal", "Popover", "Sheet"]);
64
+ /** Whether a source text reads a name as a whole word or member chain (`view` in `view === "a"`, not in `preview`). */
65
+ const reads = (text, name) => {
66
+ const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
67
+ return new RegExp(`(?<![\\w$.])${escaped}(?![\\w$])`).test(text);
68
+ };
69
+ /** Whether a `Page` element's `header` passes an object literal that carries `tabs`. */
70
+ const pageHasHeaderTabs = (page) => {
71
+ const header = attributeOf(page.openingElement, "header");
72
+ const value = header?.value?.type === "JSXExpressionContainer" ? header.value.expression : null;
73
+ return value?.type === "ObjectExpression" && value.properties.some((property) => property.type === "Property" && property.key.type === "Identifier" && property.key.name === "tabs");
74
+ };
75
+ /** At most two underline layers. */
76
+ export const tabsDepth = defineRule({
77
+ meta: {
78
+ type: "problem",
79
+ docs: {
80
+ description: "A page stacks at most two underline Tabs layers (page tabs and one region set).",
81
+ url: "knowledge/ui/presentation/grammar-laws.yaml#TABS-DEPTH",
82
+ },
83
+ schema: [],
84
+ messages: {
85
+ depth: "This underline `Tabs` is layer {{layers}} ({{chain}}). A page stacks at most two underline layers: the page tabs (`Page header.tabs`) and one region set inside a tab's panel. Fold the third level into a `switch` zone, a filter zone of a card, a list, or a drawer.",
86
+ },
87
+ },
88
+ create(context) {
89
+ if (!isProductSource(context))
90
+ return {};
91
+ const underlines = [];
92
+ return {
93
+ JSXOpeningElement(opening) {
94
+ if (elementName(opening) !== "Tabs" || isPill(opening))
95
+ return;
96
+ const key = attributeOf(opening, "selectedKey");
97
+ const expression = key?.value?.type === "JSXExpressionContainer" ? key.value.expression : null;
98
+ const readable = expression !== null && expression.type !== "JSXEmptyExpression" && expression.type !== "Literal";
99
+ underlines.push({ opening, key: readable ? context.sourceCode.getText(expression) : null });
100
+ },
101
+ "Program:exit"() {
102
+ for (const current of underlines) {
103
+ const owners = new Set();
104
+ let pageTabs = false;
105
+ let child = current.opening;
106
+ for (let node = child.parent; node !== undefined && node !== null; child = node, node = node.parent) {
107
+ if (node.type === "JSXElement") {
108
+ const name = elementName(node.openingElement);
109
+ if (name !== null && SURFACE_BOUNDARIES.has(name))
110
+ break;
111
+ if (name === "Page" && node.children.includes(child) && pageHasHeaderTabs(node))
112
+ pageTabs = true;
113
+ continue;
114
+ }
115
+ let test = null;
116
+ if (node.type === "ConditionalExpression" && child !== node.test)
117
+ test = node.test;
118
+ else if (node.type === "LogicalExpression" && node.operator === "&&" && child === node.right)
119
+ test = node.left;
120
+ else if (node.type === "SwitchCase" && node.parent.type === "SwitchStatement" && node.consequent.includes(child))
121
+ test = node.parent.discriminant;
122
+ if (test === null)
123
+ continue;
124
+ const text = context.sourceCode.getText(test);
125
+ for (const other of underlines)
126
+ if (other !== current && other.key !== null && reads(text, other.key))
127
+ owners.add(other);
128
+ }
129
+ const layers = owners.size + 1 + (pageTabs ? 1 : 0);
130
+ if (layers < 2)
131
+ continue;
132
+ const chain = `${pageTabs ? "page tabs, " : ""}${owners.size > 0 ? `${String(owners.size)} enclosing set${owners.size > 1 ? "s" : ""}, ` : ""}this set`;
133
+ if (layers > 2)
134
+ context.report({ node: current.opening, messageId: "depth", data: { layers: String(layers), chain } });
135
+ }
136
+ },
137
+ };
138
+ },
139
+ });
140
+ /** The rules this law contributes to the plugin. */
141
+ export const rules = {
142
+ "tabs-switch-zone": tabsSwitchZone,
143
+ "tabs-depth": tabsDepth,
144
+ };
145
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#TABS-SWITCH-ZONE");
146
+ /** Every rule of this law is an error. */
147
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -0,0 +1,34 @@
1
+ # Button arrows
2
+
3
+ Law module: `button-arrow.ts`. Finding code: `FE_BUTTON_ARROW`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#BUTTON-ARROW`.
4
+
5
+ A Button that leads somewhere (a page, a tab, a next step) ends with the Grammar arrow: `endArrow`. It slides toward the reading end on hover and focus and is mirrored in RTL. A Button that does something starts with a `startGlyph`. A typed `→` or a passed-in arrow icon does neither, so the law refuses them. Start and end keep their meaning: the start says what the action is, the end says where it goes.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/button-arrow`
10
+
11
+ A `Button` bound to `@starci/grammar` is a finding when:
12
+
13
+ - its label (children text, a string, a template, the branches of a conditional) states an arrow: `→ ← ➜ ➔ ⟶ › »` or ASCII `->` (message `label`);
14
+ - its `endContent` is an arrow: an element named `Arrow*` or `ChevronRight*`, or an element whose `source`, `glyph` or `name` is such an identifier or a string naming `arrow`, `chevron-right` or `chevron-end` (message `endContent`);
15
+ - it sets `endArrow` together with `startGlyph` or `startContent` (message `both`; the Button type refuses the pair as well).
16
+
17
+ `Button` takes its label as children only, so there is no string label prop to read. `IconButton` has no label and no `endArrow`; `TextAction` takes `endContent` but no `endArrow`; neither is judged.
18
+
19
+ **Invalid**
20
+
21
+ ```tsx
22
+ <Button href="/runs">View runs →</Button>
23
+ <Button href="/runs" endContent={<Icon source={ArrowRightIcon} />}>View runs</Button>
24
+ <Button href="/runs" endArrow startGlyph="send">View runs</Button>
25
+ ```
26
+
27
+ **Valid**
28
+
29
+ ```tsx
30
+ <Button href="/runs" endArrow>View runs</Button>
31
+ <Button onPress={send} startGlyph="send">Send</Button>
32
+ ```
33
+
34
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,26 @@
1
+ # A control is labelled by its own label prop
2
+
3
+ Law module: `field-label.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#FIELD-LABEL`. Finding code: `FE_FIELD_LABEL`.
4
+
5
+ The Field contract spaces label to control 8, control to help 4 and field to field 24 (the Form or the field stack). A `Text` placed beside a control as its label is spaced by whoever placed it.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/field-label`
10
+
11
+ A Grammar `Text` or `Label`, or a plain `label` or `span` with literal text, standing immediately before a Grammar form control (Input, Select, Textarea, NumberField, ComboBox, Autocomplete, CheckboxGroup, RadioGroup, ChoiceChips, Switch, DatePicker, DateField, TimeField, SearchField, Slider, CopyField) among the same parent's children (looked through fragments, conditions and `.map`), when the control has no `label` prop (an `aria-label` alone does not count), is refused. A control with a spread is not judged.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Text>Name</Text>
17
+ <Input value={name} onChange={setName} />
18
+ ```
19
+
20
+ **Valid**
21
+
22
+ ```tsx
23
+ <Input label="Name" value={name} onChange={setName} />
24
+ ```
25
+
26
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,31 @@
1
+ # Children stand closer than their container's siblings
2
+
3
+ Law module: `gap-proximity.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#GAP-PROXIMITY`. Finding code: `FE_GAP_PROXIMITY`.
4
+
5
+ Inside any container, its children stand at least one step closer than the container stands to its siblings. The gap roles rise strictly: identity 4, inline 8, row 12, section 24, region 32.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/gap-proximity`
10
+
11
+ A Grammar layout element nested directly in another (through fragments, `cond ? <x/> : null`, `cond && <x/>` and `items.map(() => <x/>)`) whose gap role is not below its parent's is refused. Roles: `Stack` and `Cluster` their literal `gap`; `PaneSection` its `gap` (default `inline`); `Section` row; `Grid` by kind (`cards`, `week`, `week-summary` inline; `sections`, `pair`, `featured`, `form` section; `main-rail` region); `Form` and `Fieldset` section.
12
+
13
+ Left alone: a `SurfaceCard`, `Drawer`, `Dialog`, `AlertDialog` or `Popover` resets the comparison (a surface is its own edge); a field stack (`Stack gap="section"` whose children are all form controls) directly in a `Form` or `Fieldset`; `Grid kind="main-rail"` as parent or child; a non-literal `gap`; an element in between that is not a layout element.
14
+
15
+ **Invalid**
16
+
17
+ ```tsx
18
+ <Stack gap="section"><Stack gap="section"><Text>A</Text></Stack></Stack>
19
+ <Section><Section kind="list" /></Section>
20
+ ```
21
+
22
+ **Valid**
23
+
24
+ ```tsx
25
+ <Stack gap="section"><Stack gap="row"><Text>A</Text></Stack></Stack>
26
+ <Form><Stack gap="section"><Input label="Name" /><Select label="Role" /></Stack></Form>
27
+ ```
28
+
29
+ The message names the child and its role, the parent and its role, and the role to use: one step below the parent (a `Section` or a `Grid` fixes its own role, so the parent steps up or the element is not nested there).
30
+
31
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,28 @@
1
+ # Every console page states its trail
2
+
3
+ Law module: `page-breadcrumbs.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#PAGE-BREADCRUMBS`. Finding code: `FE_PAGE_BREADCRUMBS`.
4
+
5
+ Every page of the app console gives the reader a way up. The root page of a console says so with `breadcrumbs: "root"`, which draws no trail.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/page-breadcrumbs`
10
+
11
+ A Grammar `Page` whose `header` is an object literal (in place, or a `const` of the same file) with no `breadcrumbs` property is refused. Not judged: no `header` (a sign-in card, a landing), a `header` that is not an object literal, a header with a spread.
12
+
13
+ Console pages are the `Page` elements drawn in a page owner or layout owner (`fe.feature`, kind `pages` or `layouts`) that is not a segment boundary (`*ErrorPage`, `*LoadingPage`, `*NotFoundPage`) and is not mounted only under the app's `(auth)` route group, and in an app block (`fe.components`, kind `blocks`), which may draw the page from client data.
14
+
15
+ **Invalid**
16
+
17
+ ```tsx
18
+ <Page header={{ title: "Main account" }}>...</Page>
19
+ ```
20
+
21
+ **Valid**
22
+
23
+ ```tsx
24
+ <Page header={{ title: "Main account", breadcrumbs: { label: "Trail", items } }}>...</Page>
25
+ <Page header={{ title: "Overview", breadcrumbs: "root" }}>...</Page>
26
+ ```
27
+
28
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,30 @@
1
+ # Row titles are not links
2
+
3
+ Law module: `row-title-link.ts`. Finding code: `FE_ROW_TITLE_LINK`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#ROW-TITLE-LINK`.
4
+
5
+ When a row opens something, the row is the one pressable and its title is plain text. A `Link` inside the title adds a second target and a second tab stop on the same row for the same destination.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/row-title-link`
10
+
11
+ - A ListRow data object (a row of the `items` of a list collection, or the `row` of a `<ListRow>`) whose `title` holds a Grammar `Link` while the same object has `onPress`, `onAction`, `href`, `onFollow` or `chevron` (message `row`).
12
+ - A `DataTable` whose rows open (`onRowAction`, or an inline `rows` literal or `.map` whose objects carry an `href`) and whose `renderCell` returns a `Link` for the row-header column: the column marked `isRowHeader`, else the first column of an inline `columns` literal. A `Link` in the branch of another column is not judged; a `Link` outside any column branch is (message `cell`).
13
+
14
+ A row that does not open may hold a link in its title. A Link in the description is not the title.
15
+
16
+ **Invalid**
17
+
18
+ ```tsx
19
+ <Section kind="list" items={[{ id: "a", title: <Link href="/a">A</Link>, href: "/a" }]} />
20
+ <DataTable onRowAction={open} renderCell={(row) => <Link href={row.href}>{row.name}</Link>} … />
21
+ ```
22
+
23
+ **Valid**
24
+
25
+ ```tsx
26
+ <Section kind="list" items={[{ id: "a", title: "A", href: "/a" }]} />
27
+ <DataTable onRowAction={open} renderCell={(row) => <Text isStrong>{row.name}</Text>} … />
28
+ ```
29
+
30
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,26 @@
1
+ # One line, one size
2
+
3
+ Law module: `same-line-size.ts`. Finding code: `FE_SAME_LINE_SIZE`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SAME-LINE-SIZE`.
4
+
5
+ Texts that stand side by side on one line share one size; the size is the size of the line's role (md for a primary line, sm for a secondary or meta line). A line that mixes 14px and 13px words reads as two lines glued together.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/same-line-size`
10
+
11
+ Among the direct `Text` children of one `Cluster` (and of a `Text` that holds `Text` runs, whose own size is the line size), seen through fragments, `cond && <Text />` and ternaries, the first `Text` sets the line's size (an absent `size` is `md`) and every later `Text` of another size is a finding. A `Text` whose `size` is not a literal, or that has a spread attribute, is skipped. `Badge`, `StatusDot`, `Chip` and `TagGroup` are not `Text`, so they are exempt. Nested Clusters are separate lines.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Cluster><Text>Deploy</Text><Text size="sm" tone="muted">2 min ago</Text></Cluster>
17
+ ```
18
+
19
+ **Valid**
20
+
21
+ ```tsx
22
+ <Cluster><Text size="sm">Deploy</Text><Text size="sm" tone="muted">2 min ago</Text></Cluster>
23
+ <Cluster><Text>Deploy</Text><Badge>Live</Badge></Cluster>
24
+ ```
25
+
26
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,37 @@
1
+ # A table, list or chart standing alone is the surface
2
+
3
+ Law module: `single-child-card.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SINGLE-CHILD-CARD`. Finding code: `FE_SINGLE_CHILD_CARD`.
4
+
5
+ A card (`SurfaceCard`) groups two or more different parts (figures + list + actions), or carries zones (tabs, search, head actions). A table, list or chart standing alone IS the surface: its title sits above it as a `Section` head and one line sits under it as `Section caption` (muted, sm). The Grammar draws a standalone `DataTable` (`surface="card"`) and every `Section kind="list"` as one frame (border, card radius), so a card around either is a second frame.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/single-child-card`
10
+
11
+ A Grammar `SurfaceCard` is refused when it has no zones (no `headers` or `footers` prop, an empty array counts as none, and no `labelEnd`) and either:
12
+
13
+ - its only body child (looked through fragments, `cond && x`, `cond ? x : y` and `.map`; blank text ignored) is a table, a list or a chart:
14
+ - table: `DataTable`
15
+ - list: `ListBox`, `ItemList`, `DisclosureList`, `Timeline`, `Section kind="list"`
16
+ - chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
17
+ - or it is `kind="table"` or `kind="list"` (the data-driven form of the same lone table or list).
18
+
19
+ Not flagged: a card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread, `kind` `figures`, `details`, `accordion` or `tile`, a non-Grammar `SurfaceCard`, and non-product source. `Meter`, `Progress` and `DescriptionList` (a record's term/value facts; its card is `kind="details"`) are not read as table, list or chart.
20
+
21
+ **Invalid**
22
+
23
+ ```tsx
24
+ <SurfaceCard label="Runs"><DataTable columns={columns} rows={runs} /></SurfaceCard>
25
+ <SurfaceCard label="Runs" kind="list" items={runs} empty={null} />
26
+ ```
27
+
28
+ **Valid**
29
+
30
+ ```tsx
31
+ <Section title="Runs" caption="Last 30 days"><DataTable columns={columns} rows={runs} /></Section>
32
+ <Section title="Runs" caption="Last 30 days" kind="list" items={runs} />
33
+ <SurfaceCard label="Runs" headers={[{ kind: "search", /* ... */ }]}><DataTable columns={columns} rows={runs} /></SurfaceCard>
34
+ <SurfaceCard label="Runs"><Text>3 failed</Text><DataTable columns={columns} rows={runs} /></SurfaceCard>
35
+ ```
36
+
37
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,31 @@
1
+ # Suggestion chips
2
+
3
+ Law module: `suggestion-chips.ts`. Finding code: `FE_SUGGESTION_CHIPS`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SUGGESTION-CHIPS`.
4
+
5
+ Quick replies and suggested questions (the assistant drawer, chat composer suggestions, empty-state shortcuts) are `SuggestionChips`: pill chips, 28px high, in a labelled toolbar, each chip a button. A row of small neutral Buttons that each send their own label is the same thing drawn without the toolbar label and the chip look, so the law refuses it.
6
+
7
+ The rule is an error in `coreGrammarConfig`; it cannot be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/suggestion-chips`
10
+
11
+ The rendered children of a Grammar `Cluster` or `Stack`, or a `div` (through fragments, `cond && x`, ternaries and `.map`) are a finding when two or more of them are suggestion Buttons, or one is drawn by a `.map`. A suggestion Button is a Grammar `Button` that:
12
+
13
+ - states `size="sm"` literally;
14
+ - has no `intent`, or a literal `intent` of `neutral` or `alternative`;
15
+ - has an inline arrow `onPress` whose one call passes the same expression as the Button's single child (`{q}` and `send(q)`, `{item.label}` and `ask(item.label)`), or the same string literal as the literal child text.
16
+
17
+ A spread, a computed `size` or `intent`, a handler that is not an inline arrow, a label with several children, or a handler that sends something else (an id) is not judged.
18
+
19
+ **Invalid**
20
+
21
+ ```tsx
22
+ <Cluster>{questions.map((q) => <Button key={q} size="sm" onPress={() => send(q)}>{q}</Button>)}</Cluster>
23
+ ```
24
+
25
+ **Valid**
26
+
27
+ ```tsx
28
+ <SuggestionChips label="Suggested questions" items={questions.map((q) => ({ id: q, label: q }))} onSelect={send} />
29
+ ```
30
+
31
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,28 @@
1
+ # A list of rows inside a surface is a nested surface
2
+
3
+ Law module: `surface-in-surface.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SURFACE-IN-SURFACE`. Finding code: `FE_SURFACE_IN_SURFACE`.
4
+
5
+ The Grammar wraps a `Section kind="list"` placed in a card body, a drawer, a dialog, a pane band or a rail as a nested surface (a 1px separator border, the card radius, clipped). A hand-made row list is the bare form.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/surface-in-surface`
10
+
11
+ A Grammar `Stack`, or a `ul`, `ol` or `div`, whose rendered children include a Grammar `Divider` between other children, inside a `SurfaceCard`, `Drawer`, `Dialog`, `PaneSection` or the `rail` of a `Grid kind="main-rail"`, is refused. A card inside a card is `no-raised-surface-in-surface` and a `Divider` directly in a `body` card is `surface-card-kind`; neither is read again.
12
+
13
+ **Invalid**
14
+
15
+ ```tsx
16
+ <Drawer title="Runs">
17
+ <Stack gap="row">{runs.map((run) => <Fragment key={run.id}><Cluster gap="inline">...</Cluster><Divider /></Fragment>)}</Stack>
18
+ </Drawer>
19
+ ```
20
+
21
+ **Valid**
22
+
23
+ ```tsx
24
+ <Drawer title="Runs"><Section kind="list" items={runs} /></Drawer>
25
+ <SurfaceCard label="Runs" kind="list" headers={[{ kind: "filter", /* ... */ }]} items={runs} empty={null} />
26
+ ```
27
+
28
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -0,0 +1,32 @@
1
+ # Table and row type
2
+
3
+ Law module: `table-cell-type.ts`. Finding code: `FE_TABLE_CELL_TYPE`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#TABLE-CELL-TYPE`.
4
+
5
+ The text of a table cell or a list row is read in a column of equals, so it takes the row type sizes: the primary is md 14 / 500 (`<Text isStrong>`), the secondary is sm 13 muted (`<Text size="sm" tone="muted">`). A heading-size Text, a `Heading`, a `Label` or an `h1`-`h6` there is a heading drawn in a list.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/table-cell-type`
10
+
11
+ Inside the places below, `Text size="figure"`, any `Heading`, any `Label` and the tags `h1`-`h6` are findings:
12
+
13
+ - the function a `DataTable` takes as `renderCell` (inline, or a function or arrow declared by name in the file), and the `editor` function of a column object in its `columns` literal;
14
+ - the `title` and `description` of a ListRow data object: a row of the `items` of a list collection (`{ kind: "list", items }`, or `Section` / `SurfaceCard` written `kind="list"`, also through a `.map` callback), or the `row` of a `<ListRow>`.
15
+
16
+ A row list declared elsewhere and passed by name is not followed. A `figure` Text outside a cell or row (a KPI) is not judged.
17
+
18
+ **Invalid**
19
+
20
+ ```tsx
21
+ <DataTable renderCell={(row) => <Text size="figure">{row.name}</Text>} … />
22
+ <Section kind="list" items={rows.map((r) => ({ id: r.id, title: <Heading level={3}>{r.name}</Heading> }))} />
23
+ ```
24
+
25
+ **Valid**
26
+
27
+ ```tsx
28
+ <DataTable renderCell={(row) => <Text isStrong>{row.name}</Text>} … />
29
+ <Section kind="list" items={rows.map((r) => ({ id: r.id, title: r.name, description: r.note }))} />
30
+ ```
31
+
32
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
package/docs/tabs.md ADDED
@@ -0,0 +1,48 @@
1
+ # Tabs: where the pill stands, and how many layers
2
+
3
+ Law module: `tabs.ts`. Knowledge: `grammar-laws.yaml` `TABS-SWITCH-ZONE`, `TABS-DEPTH`. Component law: `contexts/ui/components/tabs.md`.
4
+
5
+ Underline tabs switch panels: the page tabs (`Page header.tabs`) and, inside a tab's panel, a region set. The pill (`appearance="primary"`) is a different thing: a mode or period switch of one block's data. Both rules are errors in `coreGrammarConfig`; none can be switched off or suppressed inline.
6
+
7
+ ## `starci-grammar/tabs-switch-zone`
8
+
9
+ Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in JSX is a finding wherever it stands (a page body, under the page tabs, a pane, a drawer). The pill is drawn only as the `switch` header zone of a card, which has no JSX to write. The item checks (two to four options, no `count`, `href` or `isAttention`) stay in `no-primary-tabs-misuse` (R380).
10
+
11
+ **Invalid**
12
+
13
+ ```tsx
14
+ <Page header={{ title, tabs }}>
15
+ <Tabs appearance="primary" label="Views" items={views} selectedKey={view} onSelect={setView} />
16
+ </Page>
17
+ ```
18
+
19
+ **Valid**
20
+
21
+ ```tsx
22
+ <SurfaceCard kind="list" label="Cash" headers={[{ kind: "switch", label: "Period", items: periods, selectedKey: period, onSelect: setPeriod }]} items={rows} empty={empty} />
23
+ ```
24
+
25
+ ## `starci-grammar/tabs-depth`
26
+
27
+ Finding code: `FE_TABS_DEPTH`. Over the underline `Tabs` of one file. Every tab is one size, so only the layer count is judged.
28
+
29
+ - `depth`: a page stacks at most two underline layers, the page tabs and one region set. A `Tabs` is in the panel of another when it stands inside a conditional, `&&` or `switch` case whose test reads the other's `selectedKey`; it is in the page's panel when it stands in the children of a `Page` whose `header` object carries `tabs`. A `Tabs` that is the third layer is the finding. A `Drawer`, `Dialog`, `Modal`, `Popover` or `Sheet` starts its own surface and ends the climb.
30
+
31
+ **Invalid**
32
+
33
+ ```tsx
34
+ <Page header={{ title, tabs }}>
35
+ <Tabs label="Status" items={statuses} selectedKey={status} onSelect={setStatus} />
36
+ {status === "open" && <Tabs label="Inbox" items={inbox} selectedKey={inboxView} onSelect={setInboxView} />}
37
+ </Page>
38
+ ```
39
+
40
+ **Valid**
41
+
42
+ ```tsx
43
+ <Page header={{ title, tabs }}>
44
+ <Tabs label="Status" items={statuses} selectedKey={status} onSelect={setStatus} />
45
+ </Page>
46
+ ```
47
+
48
+ The rule reads one file. A set whose page tabs are drawn by another file (a layout, or a frame component such as a renderer package) is not judged against them: that link is runtime composition, not an import the rule can follow.