@starci/eslint-grammar-core 0.30.0 → 0.32.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.
package/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.32.0 - 2026-11-09
4
+
5
+ - Versioned with Grammar 0.32.0 (every surface on the page ground is a card); no rule changes.
6
+
7
+ ## 0.31.0 - 2026-11-09
8
+
9
+ - Changed: released with the Grammar family at 0.31.0 (the final type scale).
10
+ - Changed: `same-line-size` treats `sm` and `md` (and an absent size) as the same 14 step; only 14 vs 12 (`xs`) vs display (`figure`) on one line are findings. `table-cell-type` allows only 14 (`md`, `sm`, absent) and 12 (`xs`) Text in a DataTable cell or ListRow; `lg`, `xl`, `figure`, Heading, Label and h1-h6 stay refused. Messages, docs and `why.ts` no longer name 13 or 16.
11
+
3
12
  ## 0.30.0 - 2026-11-09
4
13
 
5
- - Changed: released with the Grammar family at 0.30.0 (Button sm takes the pill radius; SuggestionChips).
6
- - Added: `suggestion-chips` (`FE_SUGGESTION_CHIPS`, SUGGESTION-CHIPS): two or more Grammar `Button`s that are siblings in a Cluster, Stack or div (or one in a `.map`), each `size="sm"` with no intent or a neutral/alternative one and an `onPress` that sends its own label, are refused; use `SuggestionChips`. `docs/suggestion-chips.md`.
14
+ - Changed: released with the Grammar family at 0.30.0 (Button sm takes the pill radius).
15
+ - Added: `suggestion-buttons` (`FE_SUGGESTION_BUTTONS`, SUGGESTION-BUTTONS): suggestions and quick replies have one pattern, a `Cluster gap="inline"` of neutral `Button size="sm"` (a pill); a row of Grammar `Link`s with an inline handler that passes its own label (`href` absent or `"#"`), a `ChoiceChips` whose `onValueChange` sends the value instead of keeping it, and a HeroUI `Chip` whose `onPress` passes its own label are refused. `docs/suggestion-buttons.md`.
16
+ - Note: `suggestion-chips` was withdrawn before release with SuggestionChips.
7
17
 
8
18
  ## 0.29.0 - 2026-11-09
9
19
 
package/README.md CHANGED
@@ -22,7 +22,7 @@ Grammar-owned structural elements, glyphs and icon sizes, destructive menu entri
22
22
  chip labels that start uppercase, a Button that leads somewhere ending with `endArrow` (no typed or icon arrow), row type sizes in a DataTable cell or ListRow, one size per Cluster line, a row title that is plain text when the row opens (`button-arrow`, `table-cell-type`, `same-line-size`, `row-title-link`), generated art rendered through `Mascot` or `MediaFrame` with every `Mascot` naming its asset slot, the page head composed by `PageHeader`, the pane grid (a `PaneGrid` of `Pane`s, a `Pane` of `PaneSection`s that carry no padding of their own, mounted as `Page chrome="panes"`), the route page as one `Page` with its tabs in the header, heading and token scales, vendor ownership and slot-status composition, and a surface nested in another surface left subordinate (no forced `depth="top"`), and a Freestyle region that names its reason (its raw elements are exempt from the paint and raw-element laws). The pill (`Tabs appearance="primary"`) is only the `switch` header zone of a card, and a page stacks two underline `Tabs` layers at most (`tabs-switch-zone`, `tabs-depth`; `docs/tabs.md`). Each rule's metadata cites
23
23
  its behavioral knowledge source and the governing ownership test. The R318 surface composition
24
24
  rules (nested control variants, panel-list alignment, layout-only CSS) stay in the universal canon.
25
- `suggestion-chips` (a row of neutral sm Buttons that send their own label is `SuggestionChips`; `docs/suggestion-chips.md`).
25
+ `suggestion-buttons` (suggestions and quick replies are a Cluster of neutral sm Buttons, never a Link row, ChoiceChips or Chip that sends; `docs/suggestion-buttons.md`).
26
26
  The proximity and composition laws of 2026-11-09 each have a doc: `gap-proximity` (a layout element stands at least one gap step closer than its layout parent), `field-label` (a control is labelled by its own `label` prop), `surface-in-surface` (a hand-made divided row list in a surface is `Section kind="list"`) `single-child-card` (a table, list or chart alone is the surface, not a card's only content) and `page-breadcrumbs` (a console `Page` header states `breadcrumbs`, or `"root"`).
27
27
 
28
28
  ## Migrating from @starci/eslint-canon-fe 8.x
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ import { rules as surfaceCardRules } from "./surface-card.js";
23
23
  import { rules as surfaceDepthRules } from "./surface-depth.js";
24
24
  import { rules as singleChildCardRules } from "./single-child-card.js";
25
25
  import { rules as surfaceInSurfaceRules } from "./surface-in-surface.js";
26
- import { rules as suggestionChipsRules } from "./suggestion-chips.js";
26
+ import { rules as suggestionButtonsRules } from "./suggestion-buttons.js";
27
27
  import { rules as tabsRules } from "./tabs.js";
28
28
  import { rules as tableCellTypeRules } from "./table-cell-type.js";
29
29
  import { rules as textRules } from "./text-rules.js";
@@ -53,7 +53,7 @@ const CONTRIBUTIONS = [
53
53
  { law: "status-colors", rules: statusColorsRules },
54
54
  { law: "surface-card", rules: surfaceCardRules },
55
55
  { law: "surface-depth", rules: surfaceDepthRules },
56
- { law: "suggestion-chips", rules: suggestionChipsRules },
56
+ { law: "suggestion-buttons", rules: suggestionButtonsRules },
57
57
  { law: "surface-in-surface", rules: surfaceInSurfaceRules },
58
58
  { law: "tabs", rules: tabsRules },
59
59
  { law: "table-cell-type", rules: tableCellTypeRules },
package/dist/lib/why.js CHANGED
@@ -176,22 +176,22 @@ export const why = {
176
176
  },
177
177
  "table-cell-type": {
178
178
  code: "FE_TABLE_CELL_TYPE",
179
- en: "A DataTable cell or ListRow title/description in `<file>` draws a heading-size Text (`size=\"figure\"`), a Heading, a Label or an h1-h6.",
180
- fix: "The primary of a row or cell is md 14 / 500 (`<Text isStrong>`), the secondary sm 13 muted (`<Text size=\"sm\" tone=\"muted\">`).",
179
+ en: "A DataTable cell or ListRow title/description in `<file>` draws a Text above 14 (`size=\"lg\"`, `\"xl\"`, `\"figure\"`), a Heading, a Label or an h1-h6.",
180
+ fix: "The primary of a row or cell is 14 / 500 (`<Text isStrong>`), the secondary the same 14 muted (`<Text tone=\"muted\">`), and a small name (meta, count, timestamp) is 12 (`<Text size=\"xs\" tone=\"muted\">`).",
181
181
  },
182
182
  "same-line-size": {
183
183
  code: "FE_SAME_LINE_SIZE",
184
184
  en: "The Text children of one Cluster line in `<file>` have different sizes.",
185
- fix: "One line, one size: give every Text of the line the size of the line's role (md primary, sm secondary). A Badge or chip may stay as it is.",
185
+ fix: "One line, one size: give every Text of the line the same step: 14 (md, sm), 12 (xs) or display (figure); sm and md are the same 14. A Badge or chip may stay as it is.",
186
186
  },
187
187
  "row-title-link": {
188
188
  code: "FE_ROW_TITLE_LINK",
189
189
  en: "A Link is the title of a row in `<file>` that already opens (onPress, onAction, href, chevron, or a DataTable with onRowAction or row hrefs).",
190
190
  fix: "The row is the one pressable: write the title as plain text (`<Text isStrong>`) and keep the destination on the row.",
191
191
  },
192
- "suggestion-chips": {
193
- code: "FE_SUGGESTION_CHIPS",
194
- en: "Two or more neutral `size=\"sm\"` Buttons in `<file>` sit in one row (or one in a `.map`) and each press sends its own label.",
195
- fix: "Quick replies and suggested questions are `SuggestionChips` (pill chips in a labelled toolbar): `<SuggestionChips label items={[{ id, label }]} onSelect={(id) => ...} />`.",
192
+ "suggestion-buttons": {
193
+ code: "FE_SUGGESTION_BUTTONS",
194
+ en: "A Link row, a ChoiceChips or a Chip in `<file>` runs an action or sends its own label as a suggestion.",
195
+ fix: "Suggestions and quick replies are one pattern: a `Cluster gap=\"inline\"` (with `label`) of neutral `Button size=\"sm\"` (a pill).",
196
196
  },
197
197
  };
@@ -3,7 +3,7 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
3
  import { attributeOf, elementOf, grammarBindings, literalAttribute } from "./lib/row-context.js";
4
4
  /**
5
5
  * The same line size law (`FE_SAME_LINE_SIZE`): one line, one size. The `Text` children that stand side by side on one line,
6
- * the direct children of one `Cluster` (and of a `Text` that holds `Text` runs, whose own size starts the line), share one `size`; an absent `size` is `md`.
6
+ * the direct children of one `Cluster` (and of a `Text` that holds `Text` runs, whose own size starts the line), share one `size`; an absent `size` is `md`, and `sm` is the same 14 step as `md` (the final type scale), so only 14 vs 12 (`xs`) vs display (`figure`) mixes are findings.
7
7
  *
8
8
  * WHAT IT READS. The direct `Text` children of a `Cluster` or a `Text`, through fragments, `cond && <Text />` and ternaries. A
9
9
  * `Text` whose `size` is not a literal (a variable, a spread) is skipped. A `Badge`, `StatusDot`, `Chip` or `TagGroup` is not a
@@ -11,13 +11,14 @@ import { attributeOf, elementOf, grammarBindings, literalAttribute } from "./lib
11
11
  */
12
12
  /** The line containers: a Cluster lays its children on one line, a Text holds runs. */
13
13
  const LINES = new Set(["Cluster", "Text"]);
14
- /** The size a Text states: its literal `size`, `md` when it has none, null when it cannot be read. */
14
+ /** The size step a Text states: its literal `size` (`sm` folds into `md`, both 14), `md` when it has none, null when it cannot be read. */
15
15
  const sizeOf = (opening) => {
16
16
  if (opening.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
17
17
  return null;
18
18
  if (attributeOf(opening, "size") === null)
19
19
  return "md";
20
- return literalAttribute(opening, "size");
20
+ const size = literalAttribute(opening, "size");
21
+ return size === "sm" ? "md" : size;
21
22
  };
22
23
  export const sameLineSize = defineRule({
23
24
  meta: {
@@ -25,7 +26,7 @@ export const sameLineSize = defineRule({
25
26
  docs: { description: "FE_SAME_LINE_SIZE: the Text children of one Cluster line share one size." },
26
27
  schema: [],
27
28
  messages: {
28
- mixed: "This Text is `{{size}}` and its line's first Text is `{{first}}`. One line, one size: pick the size of the line's role (md for a primary, sm for a secondary or a meta line) and give every Text of the line that size. A Badge or a chip may stay as it is.",
29
+ mixed: "This Text is `{{size}}` and its line's first Text is `{{first}}`. One line, one size: sizes are 14 (md, sm), 12 (xs, for a small name such as a meta line, count or timestamp) and display (figure): give every Text of the line the same step. A Badge or a chip may stay as it is.",
29
30
  },
30
31
  },
31
32
  create(context) {
@@ -5,8 +5,8 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
5
5
  * The lone surface law (owner, 2026-11-09, SINGLE-CHILD-CARD): a card groups two or more different parts (figures + list +
6
6
  * actions) or carries zones (tabs, search, head actions). A table, a list or a chart standing alone IS the surface: the
7
7
  * title sits above it as a `Section` head and one line sits under it as `Section caption` (muted, sm). The Grammar draws a
8
- * standalone `DataTable` (`surface="card"`) and every `Section kind="list"` as ONE frame (border, card radius), so a
9
- * `SurfaceCard` around either is a second frame around the first.
8
+ * standalone `DataTable` (`surface="card"`) and every `Section kind="list"` as its own card (border, card radius, card shadow), so a
9
+ * `SurfaceCard` around either is a second card around the first.
10
10
  *
11
11
  * WHAT IT READS. A Grammar `SurfaceCard` (imported from `@starci/grammar`) with no zones: no `headers` or `footers` prop (an
12
12
  * empty array literal counts as none) and no `labelEnd` (head actions). Its body is read through fragments, `cond && <x/>`,
@@ -1,5 +1,5 @@
1
1
  import type { Rule } from "eslint";
2
- export declare const suggestionChips: Rule.RuleModule;
2
+ export declare const suggestionButtons: Rule.RuleModule;
3
3
  /** The rules this law contributes to the plugin. */
4
4
  export declare const rules: Record<string, Rule.RuleModule>;
5
5
  /** Every rule of this law is an error. */
@@ -0,0 +1,181 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
+ import { renderedChildren } from "./lib/grammar-jsx.js";
4
+ import { attributeOf, elementOf, grammarBindings, literalAttribute } from "./lib/row-context.js";
5
+ /**
6
+ * The suggestion buttons law (`FE_SUGGESTION_BUTTONS`): suggestions, quick replies and empty-state shortcuts have ONE pattern,
7
+ * a `Cluster gap="inline"` of neutral `Button size="sm"` (every Button size draws a pill). The law flags the ALTERNATIVES
8
+ * drawn as suggestions, in cheap static shapes only:
9
+ * - a row (two or more siblings, or one drawn by a `.map`) of Grammar `Link`s whose `onFollow` or `onPress` is an inline arrow
10
+ * that passes the Link's own label (`{q}` and `send(q)`, `{item.label}` and `ask(item.label)`, or an equal string literal)
11
+ * and whose `href` is absent or `"#"`;
12
+ * - a Grammar `ChoiceChips` whose `onValueChange` is an inline arrow that calls something that is not a state setter with the
13
+ * value, or is a bare send-like function (`send`, `ask`, `submit`, `reply`, `post`, `dispatch`): it sends the choice instead
14
+ * of keeping it selected;
15
+ * - a HeroUI `Chip` (imported from `@heroui/react`) with an `onPress` or `onClick` that passes its own label. Grammar `Badge`
16
+ * takes no action prop and Grammar `TagGroup` only `onRemove(ids)`/`onReorder(ids)`, so neither can send its own label.
17
+ * A spread, a computed prop, a handler that is not readable, a callee named `set*`, `on*`, `handle*` or `update*` is not flagged.
18
+ */
19
+ const PARENTS = new Set(["Cluster", "Stack"]);
20
+ const SENDERS = /^(send|ask|submit|reply|post|dispatch)/;
21
+ const NOT_SENDING = /^(set[A-Z]|on[A-Z]|handle|update)/;
22
+ /** The single expression or text an element states as its label: `{q}` as the node `q`, text as its string. */
23
+ const labelOf = (element) => {
24
+ const children = element.children.filter((child) => !(child.type === "JSXText" && child.value.trim() === ""));
25
+ if (children.length !== 1)
26
+ return null;
27
+ const child = children[0];
28
+ if (child.type === "JSXText")
29
+ return { text: child.value.trim() };
30
+ if (child.type !== "JSXExpressionContainer" || child.expression.type === "JSXEmptyExpression")
31
+ return null;
32
+ if (child.expression.type === "Literal" && typeof child.expression.value === "string")
33
+ return { text: child.expression.value };
34
+ return { node: child.expression };
35
+ };
36
+ /** The one call an inline arrow makes, or null. */
37
+ const callOf = (handler) => {
38
+ let body = handler.body;
39
+ if (body.type === "BlockStatement") {
40
+ const only = body.body.length === 1 ? body.body[0] : undefined;
41
+ body = only?.type === "ExpressionStatement" ? only.expression : null;
42
+ }
43
+ return body !== null && body.type === "CallExpression" ? body : null;
44
+ };
45
+ /** The last name of a callee (`send`, `chat.send` as `send`), or null. */
46
+ const calleeName = (callee) => {
47
+ if (callee.type === "Identifier")
48
+ return callee.name;
49
+ if (callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier")
50
+ return callee.property.name;
51
+ return null;
52
+ };
53
+ /** The inline arrow an attribute holds, or null. */
54
+ const arrowOf = (opening, name) => {
55
+ const value = attributeOf(opening, name)?.value;
56
+ if (value == null || value.type !== "JSXExpressionContainer" || value.expression.type !== "ArrowFunctionExpression")
57
+ return null;
58
+ return value.expression;
59
+ };
60
+ /** True when an inline handler arrow of the element passes the element's own label. */
61
+ const sendsOwnLabel = (element, names, source) => {
62
+ const label = labelOf(element);
63
+ if (label === null)
64
+ return false;
65
+ return names.some((name) => {
66
+ const handler = arrowOf(element.openingElement, name);
67
+ const call = handler === null ? null : callOf(handler);
68
+ if (call === null)
69
+ return false;
70
+ return call.arguments.some((arg) => ("text" in label ? arg.type === "Literal" && arg.value === label.text : arg.type !== "Literal" && source.getText(arg) === source.getText(label.node)));
71
+ });
72
+ };
73
+ /** True when an element sits inside a `.map` callback below its parent. */
74
+ const inMap = (element, parent) => {
75
+ for (let node = element.parent; node !== undefined && node !== parent; node = node.parent) {
76
+ if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression")
77
+ return true;
78
+ }
79
+ return false;
80
+ };
81
+ /** The HeroUI `Chip` local names a file imports from `@heroui/react`. */
82
+ const heroChips = (program) => {
83
+ const names = new Set();
84
+ for (const statement of program.body) {
85
+ if (statement.type !== "ImportDeclaration" || statement.source.value !== "@heroui/react")
86
+ continue;
87
+ for (const specifier of statement.specifiers) {
88
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier" && specifier.imported.name === "Chip")
89
+ names.add(specifier.local.name);
90
+ }
91
+ }
92
+ return names;
93
+ };
94
+ export const suggestionButtons = defineRule({
95
+ meta: {
96
+ type: "problem",
97
+ docs: { description: "FE_SUGGESTION_BUTTONS: suggestions and quick replies are a Cluster of neutral sm Buttons, not Links, ChoiceChips or Chips." },
98
+ schema: [],
99
+ messages: {
100
+ element: "Suggestions and quick replies have one pattern: a `Cluster gap=\"inline\"` of neutral `Button size=\"sm\"` (a pill). {{element}} here runs an action or sends its own label; draw it as a Button.",
101
+ },
102
+ },
103
+ create(context) {
104
+ if (!isProductSource(context))
105
+ return {};
106
+ let bound = new Map();
107
+ let chips = new Set();
108
+ const source = context.sourceCode;
109
+ /** A Grammar Link that passes its own label and goes nowhere. */
110
+ const isLinkSuggestion = (node) => {
111
+ if (node.type !== "JSXElement")
112
+ return false;
113
+ const opening = node.openingElement;
114
+ if (elementOf(opening, bound).grammar !== "Link")
115
+ return false;
116
+ if (opening.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
117
+ return false;
118
+ if (attributeOf(opening, "href") !== null && literalAttribute(opening, "href") !== "#")
119
+ return false;
120
+ return sendsOwnLabel(node, ["onFollow", "onPress"], source);
121
+ };
122
+ return {
123
+ Program(program) {
124
+ bound = grammarBindings(program);
125
+ chips = heroChips(program);
126
+ },
127
+ JSXElement(element) {
128
+ const opening = element.openingElement;
129
+ const { grammar, tag } = elementOf(opening, bound);
130
+ const report = (name) => context.report({ node: opening, messageId: "element", data: { element: name } });
131
+ if (grammar === "ChoiceChips") {
132
+ if (opening.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
133
+ return;
134
+ const value = attributeOf(opening, "onValueChange")?.value;
135
+ if (value == null || value.type !== "JSXExpressionContainer")
136
+ return;
137
+ const handler = value.expression;
138
+ if (handler.type === "Identifier" || handler.type === "MemberExpression") {
139
+ const name = calleeName(handler);
140
+ if (name !== null && SENDERS.test(name) && !NOT_SENDING.test(name))
141
+ report("`ChoiceChips`");
142
+ return;
143
+ }
144
+ if (handler.type !== "ArrowFunctionExpression")
145
+ return;
146
+ const param = handler.params[0];
147
+ const call = callOf(handler);
148
+ if (param?.type !== "Identifier" || call === null)
149
+ return;
150
+ const name = calleeName(call.callee);
151
+ if (name === null || NOT_SENDING.test(name))
152
+ return;
153
+ if (call.arguments.some((arg) => arg.type === "Identifier" && arg.name === param.name))
154
+ report("`ChoiceChips`");
155
+ return;
156
+ }
157
+ if (grammar === null && tag === null && opening.name.type === "JSXIdentifier" && chips.has(opening.name.name)) {
158
+ if (opening.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
159
+ return;
160
+ if (sendsOwnLabel(element, ["onPress", "onClick"], source))
161
+ report("`Chip`");
162
+ return;
163
+ }
164
+ if (!(grammar !== null && PARENTS.has(grammar)) && tag !== "div")
165
+ return;
166
+ const found = renderedChildren(element.children).filter(isLinkSuggestion);
167
+ if (found.length < 2 && !found.some((entry) => inMap(entry, element)))
168
+ return;
169
+ for (const entry of found)
170
+ context.report({ node: entry.openingElement, messageId: "element", data: { element: "`Link`" } });
171
+ },
172
+ };
173
+ },
174
+ });
175
+ /** The rules this law contributes to the plugin. */
176
+ export const rules = {
177
+ "suggestion-buttons": suggestionButtons,
178
+ };
179
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#SUGGESTION-BUTTONS");
180
+ /** Every rule of this law is an error. */
181
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -3,26 +3,28 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
3
  import { attributeOf, descendants, elementOf, grammarBindings, isListRow, keyName, literalAttribute, propertyOf } from "./lib/row-context.js";
4
4
  /**
5
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.
6
+ * the final type scale: 14px text (`Text`, `Text size="md"`, `Text size="sm"`; the primary is 14 / 500 `Text isStrong`, the
7
+ * secondary 14 muted) and 12px for small names (`Text size="xs"`). A Text of another size (`lg`, `xl`, `figure`), a `Heading`, a `Label` or an `h1`-`h6` in a cell or a row is a heading drawn in a list.
8
8
  *
9
9
  * WHAT IT READS.
10
10
  * - the function a `DataTable` takes as `renderCell` (inline, or a function or arrow declared by name in the file), and the
11
11
  * `editor` function of a column object in its `columns` literal;
12
12
  * - the `title` and `description` of a ListRow data object: a row of the `items` of a list collection (`{ kind: "list", items }`,
13
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
14
+ * In those, a `Text` whose literal `size` is not `xs`, `sm` or `md`, any `Heading`, any `Label` and the tags `h1`-`h6` are findings. A row list declared elsewhere
15
15
  * and passed by name is not followed.
16
16
  */
17
+ /** The Text sizes a cell or row takes: 14 (md, sm) and 12 (xs). */
18
+ const CELL_SIZES = new Set(["xs", "sm", "md"]);
17
19
  const HEADING_TAGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6"]);
18
20
  const isFunction = (node) => node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration";
19
21
  export const tableCellType = defineRule({
20
22
  meta: {
21
23
  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." },
24
+ docs: { description: "FE_TABLE_CELL_TYPE: no Text above 14, Heading, Label or h1-h6 in a DataTable cell or a ListRow." },
23
25
  schema: [],
24
26
  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\">`).",
27
+ heading: "{{what}} in {{where}} is a heading drawn in a list. The primary of a row or a cell is 14 / 500 (`<Text isStrong>`), the secondary 14 muted (`<Text tone=\"muted\">`), a small name (meta, count, timestamp) 12 (`<Text size=\"xs\" tone=\"muted\">`).",
26
28
  },
27
29
  },
28
30
  create(context) {
@@ -38,8 +40,9 @@ export const tableCellType = defineRule({
38
40
  continue;
39
41
  const { grammar, tag } = elementOf(node.openingElement, bound);
40
42
  let what = null;
41
- if (grammar === "Text" && literalAttribute(node.openingElement, "size") === "figure")
42
- what = "`Text size=\"figure\"`";
43
+ const size = grammar === "Text" ? literalAttribute(node.openingElement, "size") : null;
44
+ if (size !== null && !CELL_SIZES.has(size))
45
+ what = `\`Text size="${size}"\``;
43
46
  else if (grammar === "Heading" || grammar === "Label")
44
47
  what = `\`${grammar}\``;
45
48
  else if (tag !== null && HEADING_TAGS.has(tag))
@@ -2,24 +2,25 @@
2
2
 
3
3
  Law module: `same-line-size.ts`. Finding code: `FE_SAME_LINE_SIZE`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SAME-LINE-SIZE`.
4
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.
5
+ Texts that stand side by side on one line share one size; the size is the size of the line's role. The final type scale has 14px for all UI text (`md`, and `sm`, which is kept as a name and equals `md`), 12px for small names (`xs`: meta lines, badges, counts, timestamps) and display sizes (`figure`). A line that mixes 14, 12 and display words reads as several lines glued together.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
9
9
  ## `starci-grammar/same-line-size`
10
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.
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 `sm` counts as `md`: both are 14) 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
12
 
13
13
  **Invalid**
14
14
 
15
15
  ```tsx
16
- <Cluster><Text>Deploy</Text><Text size="sm" tone="muted">2 min ago</Text></Cluster>
16
+ <Cluster><Text>Deploy</Text><Text size="xs" tone="muted">2 min ago</Text></Cluster>
17
17
  ```
18
18
 
19
19
  **Valid**
20
20
 
21
21
  ```tsx
22
- <Cluster><Text size="sm">Deploy</Text><Text size="sm" tone="muted">2 min ago</Text></Cluster>
22
+ <Cluster><Text>Deploy</Text><Text size="sm" tone="muted">2 min ago</Text></Cluster>
23
+ <Cluster><Text size="xs">Deploy</Text><Text size="xs" tone="muted">2 min ago</Text></Cluster>
23
24
  <Cluster><Text>Deploy</Text><Badge>Live</Badge></Cluster>
24
25
  ```
25
26
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Law module: `single-child-card.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SINGLE-CHILD-CARD`. Finding code: `FE_SINGLE_CHILD_CARD`.
4
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.
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 its own card (border, card radius, card shadow; the table keeps HeroUI's native look inside), so a card around either is a second card.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
@@ -0,0 +1,34 @@
1
+ # Suggestion buttons
2
+
3
+ Law module: `suggestion-buttons.ts`. Finding code: `FE_SUGGESTION_BUTTONS`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SUGGESTION-BUTTONS`.
4
+
5
+ Suggestions, quick replies and empty-state shortcuts (the assistant drawer, chat composer suggestions) have ONE pattern: a `Cluster gap="inline"` (with a `label`) of neutral `Button size="sm"`. Every Button size draws a pill. The law refuses the alternatives drawn as suggestions: Links, ChoiceChips and Chips that run an action or send their own label.
6
+
7
+ The rule is an error in `coreGrammarConfig`; it cannot be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/suggestion-buttons`
10
+
11
+ Flagged, in cheap static shapes only:
12
+
13
+ - a row (two or more siblings in a Grammar `Cluster` or `Stack`, or a `div`, through fragments, `cond && x`, ternaries and `.map`; or one Link drawn by a `.map`) of Grammar `Link`s whose `onFollow` or `onPress` is an inline arrow passing the Link's own label (`{q}` and `send(q)`, `{item.label}` and `ask(item.label)`, or an equal string literal) and whose `href` is absent or `"#"`;
14
+ - a Grammar `ChoiceChips` whose `onValueChange` is an inline arrow calling something that is not a state setter with the value, or is a bare `send`/`ask`/`submit`/`reply`/`post`/`dispatch` function: it sends the choice instead of keeping it selected;
15
+ - a HeroUI `Chip` (imported from `@heroui/react`) whose `onPress` or `onClick` passes its own label.
16
+
17
+ Grammar `Badge` has no action prop and Grammar `TagGroup` only `onRemove(ids)` and `onReorder(ids)`, so neither is judged. A spread, a computed prop, an unreadable handler, or a callee named `set*`, `on*`, `handle*` or `update*` is not flagged.
18
+
19
+ **Invalid**
20
+
21
+ ```tsx
22
+ <Cluster>{questions.map((q) => <Link key={q} href="#" onFollow={() => send(q)}>{q}</Link>)}</Cluster>
23
+ <ChoiceChips label="Ask" options={options} onValueChange={(v) => send(v)} />
24
+ ```
25
+
26
+ **Valid**
27
+
28
+ ```tsx
29
+ <Cluster gap="inline" label="Suggested questions">
30
+ {questions.map((q) => <Button key={q} size="sm" onPress={() => send(q)}>{q}</Button>)}
31
+ </Cluster>
32
+ ```
33
+
34
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -2,13 +2,13 @@
2
2
 
3
3
  Law module: `table-cell-type.ts`. Finding code: `FE_TABLE_CELL_TYPE`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#TABLE-CELL-TYPE`.
4
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.
5
+ The text of a table cell or a list row is read in a column of equals, so it takes the final type scale: 14px for the text (the primary 14 / 500 `<Text isStrong>`, the secondary 14 muted; `sm` equals `md`) and 12px only for small names (`<Text size="xs" tone="muted">`: meta, count, timestamp). A Text above 14 (`lg`, `xl`, `figure`), a `Heading`, a `Label` or an `h1`-`h6` there is a heading drawn in a list.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
9
9
  ## `starci-grammar/table-cell-type`
10
10
 
11
- Inside the places below, `Text size="figure"`, any `Heading`, any `Label` and the tags `h1`-`h6` are findings:
11
+ Inside the places below, a `Text` with a literal `size` other than `xs`, `sm` or `md` (`lg`, `xl`, `figure`), any `Heading`, any `Label` and the tags `h1`-`h6` are findings:
12
12
 
13
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
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>`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-grammar-core",
3
- "version": "0.30.0",
3
+ "version": "0.32.0",
4
4
  "description": "ESLint rules for the core Grammar's component, token and composition contracts.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -68,6 +68,6 @@
68
68
  "eslint-plugin-react-hooks": "^7.1.1",
69
69
  "typescript": "^6.0.3"
70
70
  },
71
- "gitHead": "60a43b01a0944d2c8252e074946b82f3ee60c988",
72
- "starciSource": "c9f0db9043d7d17e3fb8d7d1e230fde769670e27b4cf7e2c6b27fcc1901fd99f"
71
+ "gitHead": "8669bbcdf4f3cf117598da2896d5732e865b412a",
72
+ "starciSource": "89a210fd714fe385d9979b0d000234f0cc9387f56d9ba62c8d0bdf46a5475c9e"
73
73
  }
@@ -57,15 +57,15 @@ rules:
57
57
  assert: |-
58
58
  It takes `endArrow`; an arrow typed in its label or passed as end content is refused. A Button that does
59
59
  something takes `startGlyph`; never both.
60
- - id: SUGGESTION-CHIPS
61
- title: Quick replies and suggested questions are SuggestionChips
62
- governs: A row of Buttons that suggest something to say or ask.
60
+ - id: SUGGESTION-BUTTONS
61
+ title: Suggestions and quick replies are a Cluster of neutral sm Buttons
62
+ governs: Anything that suggests something to say or ask.
63
63
  cases:
64
64
  - id: case-1
65
- when: A row of neutral sm Buttons each send their own label
65
+ when: A suggestion, quick reply or empty-state shortcut is drawn
66
66
  assert: |-
67
- It is `SuggestionChips` (pill chips, a labelled toolbar), not a Button row; a form value is ChoiceChips and a
68
- label is a Badge or a TagGroup.
67
+ It is a `Cluster gap="inline"` (with `label`) of neutral `Button size="sm"`, which every Button size draws as a
68
+ pill; a Link row, ChoiceChips, TagGroup, Badge or Chip is never a suggestion.
69
69
  - id: TABLE-CELL-TYPE
70
70
  title: Table and row cells take the row type sizes
71
71
  governs: Text inside a DataTable cell or a ListRow.
@@ -73,7 +73,7 @@ rules:
73
73
  - id: case-1
74
74
  when: Text is drawn in a DataTable cell or a ListRow
75
75
  assert: |-
76
- The primary is md 14 / 500, the secondary sm 13 muted; a heading-size Text is refused.
76
+ All text is 14 (the primary 14 / 500, the secondary 14 muted; sm equals md); only a small name (meta, count, timestamp) is 12 (xs). A larger Text, a Heading or a Label is refused.
77
77
  - id: SAME-LINE-SIZE
78
78
  title: One line, one size
79
79
  governs: Text siblings of one inline line.
@@ -81,7 +81,7 @@ rules:
81
81
  - id: case-1
82
82
  when: Texts stand side by side in one Cluster
83
83
  assert: |-
84
- They share one size; a Badge or a chip is exempt.
84
+ They share one size step (14: md and sm are the same; 12: xs; display: figure); a Badge or a chip is exempt.
85
85
  - id: ROW-TITLE-LINK
86
86
  title: A row title is never a link when the row opens
87
87
  governs: The primary of a ListRow or a DataTable row.
@@ -1,122 +0,0 @@
1
- import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
- import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
- import { renderedChildren } from "./lib/grammar-jsx.js";
4
- import { attributeOf, elementOf, grammarBindings, literalAttribute } from "./lib/row-context.js";
5
- /**
6
- * The suggestion chips law (`FE_SUGGESTION_CHIPS`): a row of small neutral Buttons that each send their own label is a set of
7
- * quick replies or suggested questions, and that is `SuggestionChips` (pill chips in a labelled toolbar), not a Button row.
8
- *
9
- * WHAT IT READS. The rendered children of a Grammar `Cluster` or `Stack`, or a `div` (looked through fragments, `cond && x`,
10
- * ternaries and `.map`). A child is a suggestion Button when it is a Grammar `Button` that:
11
- * - states `size="sm"` literally;
12
- * - has no `intent`, or a literal `intent` of `neutral` or `alternative`;
13
- * - has an `onPress` arrow function whose one call passes the same expression as the Button's single child
14
- * (`{q}` and `send(q)`, `{item.label}` and `ask(item.label)`), or the same string literal as the literal child text.
15
- * The parent is a finding when two or more such Buttons are its siblings, or one of them is drawn by a `.map`.
16
- * Anything not readable this cheaply (a spread, a computed size or intent, a handler that is not an inline arrow, a label with
17
- * several children) is not flagged.
18
- */
19
- const PARENTS = new Set(["Cluster", "Stack"]);
20
- const NEUTRAL = new Set(["neutral", "alternative"]);
21
- /** The single expression or text a Button states as its label: `{q}` as the node `q`, text as its string. */
22
- const labelOf = (element) => {
23
- const children = element.children.filter((child) => !(child.type === "JSXText" && child.value.trim() === ""));
24
- if (children.length !== 1)
25
- return null;
26
- const child = children[0];
27
- if (child.type === "JSXText")
28
- return { text: child.value.trim() };
29
- if (child.type !== "JSXExpressionContainer" || child.expression.type === "JSXEmptyExpression")
30
- return null;
31
- if (child.expression.type === "Literal" && typeof child.expression.value === "string")
32
- return { text: child.expression.value };
33
- return { node: child.expression };
34
- };
35
- /** The argument expressions of the one call an inline `onPress` arrow makes, or null. */
36
- const callArguments = (handler) => {
37
- let body = handler.body;
38
- if (body.type === "BlockStatement") {
39
- const only = body.body.length === 1 ? body.body[0] : undefined;
40
- body = only?.type === "ExpressionStatement" ? only.expression : null;
41
- }
42
- return body !== null && body.type === "CallExpression" ? body.arguments : null;
43
- };
44
- /** True when the handler of a Button passes its own label. */
45
- const sendsOwnLabel = (element, source) => {
46
- const label = labelOf(element);
47
- const press = attributeOf(element.openingElement, "onPress")?.value;
48
- if (label === null || press == null || press.type !== "JSXExpressionContainer" || press.expression.type !== "ArrowFunctionExpression")
49
- return false;
50
- const args = callArguments(press.expression);
51
- if (args === null)
52
- return false;
53
- return args.some((arg) => {
54
- if ("text" in label)
55
- return arg.type === "Literal" && arg.value === label.text;
56
- return arg.type !== "Literal" && source.getText(arg) === source.getText(label.node);
57
- });
58
- };
59
- /** True when an element sits inside a `.map` callback below its parent. */
60
- const inMap = (element, parent) => {
61
- for (let node = element.parent; node !== undefined && node !== parent; node = node.parent) {
62
- if (node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression")
63
- return true;
64
- }
65
- return false;
66
- };
67
- export const suggestionChips = defineRule({
68
- meta: {
69
- type: "problem",
70
- docs: { description: "FE_SUGGESTION_CHIPS: a row of neutral sm Buttons that send their own label is SuggestionChips." },
71
- schema: [],
72
- messages: {
73
- chips: "This is a suggestion, drawn as a Button in a row. Use `SuggestionChips` (pill chips, a labelled toolbar) for quick replies and suggested questions: `<SuggestionChips label=\"...\" items={[{ id, label }]} onSelect={(id) => ...} />`.",
74
- },
75
- },
76
- create(context) {
77
- if (!isProductSource(context))
78
- return {};
79
- let bound = new Map();
80
- const source = context.sourceCode;
81
- /** A Grammar Button that is small, neutral and sends its own label. */
82
- const isSuggestion = (node) => {
83
- if (node.type !== "JSXElement")
84
- return false;
85
- const opening = node.openingElement;
86
- if (elementOf(opening, bound).grammar !== "Button")
87
- return false;
88
- if (opening.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
89
- return false;
90
- if (literalAttribute(opening, "size") !== "sm")
91
- return false;
92
- if (attributeOf(opening, "intent") !== null) {
93
- const intent = literalAttribute(opening, "intent");
94
- if (intent === null || !NEUTRAL.has(intent))
95
- return false;
96
- }
97
- return sendsOwnLabel(node, source);
98
- };
99
- return {
100
- Program(program) {
101
- bound = grammarBindings(program);
102
- },
103
- JSXElement(element) {
104
- const { grammar, tag } = elementOf(element.openingElement, bound);
105
- if (!(grammar !== null && PARENTS.has(grammar)) && tag !== "div")
106
- return;
107
- const found = renderedChildren(element.children).filter(isSuggestion);
108
- if (found.length < 2 && !found.some((entry) => inMap(entry, element)))
109
- return;
110
- for (const entry of found)
111
- context.report({ node: entry.openingElement, messageId: "chips" });
112
- },
113
- };
114
- },
115
- });
116
- /** The rules this law contributes to the plugin. */
117
- export const rules = {
118
- "suggestion-chips": suggestionChips,
119
- };
120
- defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#SUGGESTION-CHIPS");
121
- /** Every rule of this law is an error. */
122
- export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -1,31 +0,0 @@
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).