@starci/eslint-grammar-core 0.43.1 → 0.45.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 (41) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +4 -2
  3. package/dist/app-shell.js +30 -10
  4. package/dist/card-content.js +8 -19
  5. package/dist/{single-child-card.d.ts → card-is-object.d.ts} +2 -2
  6. package/dist/card-is-object.js +141 -0
  7. package/dist/choice-controls.d.ts +1 -1
  8. package/dist/choice-controls.js +5 -5
  9. package/dist/data-table-surface.d.ts +18 -0
  10. package/dist/data-table-surface.js +57 -0
  11. package/dist/index.js +4 -2
  12. package/dist/lib/why.js +26 -21
  13. package/dist/no-card-lead-description.js +3 -3
  14. package/dist/rows-in-card.d.ts +1 -1
  15. package/dist/rows-in-card.js +13 -12
  16. package/dist/surface-card-list.d.ts +1 -2
  17. package/dist/surface-card-list.js +1 -2
  18. package/dist/surface-card.d.ts +1 -1
  19. package/dist/surface-card.js +8 -63
  20. package/dist/surface-depth.js +1 -1
  21. package/dist/surface-in-surface.js +1 -1
  22. package/dist/tabs.d.ts +3 -2
  23. package/dist/tabs.js +26 -19
  24. package/docs/app-shell.md +5 -2
  25. package/docs/card-content.md +5 -6
  26. package/docs/card-is-object.md +42 -0
  27. package/docs/choice-controls.md +4 -4
  28. package/docs/data-table-surface.md +27 -0
  29. package/docs/layout-two-axis.md +3 -3
  30. package/docs/no-card-lead-description.md +2 -2
  31. package/docs/no-nested-label.md +3 -3
  32. package/docs/rows-in-card.md +5 -4
  33. package/docs/surface-card-list.md +1 -2
  34. package/docs/surface-card.md +4 -8
  35. package/docs/surface-depth.md +6 -7
  36. package/docs/surface-in-surface.md +2 -2
  37. package/docs/tabs.md +26 -5
  38. package/package.json +3 -3
  39. package/runtime/knowledge/ui/presentation/grammar-laws.yaml +33 -23
  40. package/dist/single-child-card.js +0 -90
  41. package/docs/single-child-card.md +0 -37
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.45.0 - 2026-11-17
4
+
5
+ - Added: `card-is-object` (`FE_CARD_IS_OBJECT`, law CARD-OBJECT): a Grammar `SurfaceCard` of the body kind (no `kind`, or `kind="body"`) whose only content, through fragments and the layout wrappers `Stack`, `Cluster`, `Inline`, `Grid` and `div`, is a `DataTable`, a `Section` of any kind, a `DescriptionList`, a `DisclosureList`, an `Accordion`, a `Form`, a `Fieldset`, a lone field (`Input`, `Textarea`, `Select`, `ComboBox`, `SearchField`, `NumberField`, `RadioGroup`, `CheckboxGroup`), an `EmptyNotice`, `Markdown`, `MarkdownArticle` or a chart (`BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`) is refused. Message `collection`: "SurfaceCard holds only a `DataTable`: a card is one object (a customer, an agent, a plan, a message). Put the table flat under its Section (`<Section title ...><DataTable .../></Section>`)." with the replacement of each content (list: `Section kind="list"`, facts: `Section` + `DescriptionList isDivided`, disclosures: `Section` + `DisclosureList`, form or field: `Section` + `Form`, empty: `EmptyNotice` on its own, markdown and chart: `Section`). `measure="formCompact"`, a `kind="tile"` card and a card with more than one content are not judged. No autofix. Doc `docs/card-is-object.md`.
6
+ - Added: `data-table-surface` (`FE_DATA_TABLE_SURFACE`): a Grammar `DataTable` with a `surface` attribute, whatever its value, is refused ("`DataTable surface` is removed: a table has one flat look. Drop the `surface` attribute and put the table under its `Section`..."); the autofix removes the attribute and the whitespace before it. Doc `docs/data-table-surface.md`.
7
+ - Removed: `single-child-card` (`FE_SINGLE_CHILD_CARD`, law SINGLE-CHILD-CARD), its spec, doc, why entry and knowledge law; `card-is-object` absorbs it and its still-valid cases (a card around a lone table, chart or list).
8
+ - Changed: `rows-in-card` (`FE_ROWS_IN_CARD`): a `DescriptionList` or `DisclosureList` stands in a `Section` or in the body of an object `SurfaceCard`; the message and doc no longer say rows are always a card, and `DataTable` and `Accordion` no longer count as a host.
9
+ - Changed: `tabs-switch-zone` (`FE_TABS_SWITCH_ZONE`) lets a pill (`Tabs appearance="primary"`) stand as the `action` of a `Section` (the place of the removed `switch` zone) and as a row `control`; `tabs-in-well` no longer treats a `SurfaceCard` as a header row of its own (a card has no header zones), so loose underline tabs in a card body in a page or pane are findings; the messages of `tabs-switch-zone`, `tabs-depth`, `tabs-in-well` name `Section action` and `Section filter`.
10
+ - Changed: `card-one-content` speaks of one object per card (a second collection is its own `Section`, a ribbon is `Section kind="figures"`); the `ribbon` message and the `figures` header zone check are deleted.
11
+ - Changed: `surface-card-kind` (R355) points at `Section kind="list"`, `Section kind="figures"`, `Section filter` and the card's `actions`; the `zone` message and the check of `custom` zones of `headers` and `footers` are deleted with the zones.
12
+ - Changed (messages, docs and hints): `surface-in-surface`, `surface-depth`, `no-label-in-grid`, `no-card-lead-description`, `choice-controls`, `surface-card-list` and the `lib/why.ts` fixes no longer name `kind="table"`, `"details"`, `"figures"`, `"accordion"`, `"select"`, `headers`, `footers` or a `switch` zone; each names its replacement. `one-highlight-per-render` specs use `MessageBubble`.
13
+ - Knowledge (`runtime/knowledge/ui/presentation/grammar-laws.yaml`): CARD-OBJECT and DATA-TABLE-SURFACE added; SINGLE-CHILD-CARD removed; TABS-SWITCH-ZONE, TABS-IN-WELL, ROWS-IN-CARD, CARD-NO-DESCRIPTION and CARD-ONE-CONTENT rewritten for the flat look.
14
+
15
+ ## 0.44.0 - 2026-11-17
16
+
17
+ - Changed: `navbar-control-size` (`FE_NAVBAR_CONTROL_SIZE`) reads a `Switch` by its `kind`, which the Grammar lets win over `size`: `kind="toggle"` passes alone (no `size` needed), a `Switch` with neither `kind` nor `size` passes (the toggle is the default), and `kind="compact"` is refused in the bar with its own message (`compact`: 32x18 breaks the bar's one 40px height, DNA-COMMON-BAR-ONE-HEIGHT) whatever `size` it carries; before, `size="control"` beside `kind="compact"` silenced the rule although the Grammar ignored it. Fix text and docs `docs/app-shell.md` updated.
18
+ - Changed: `tabs-in-well` (`FE_TABS_IN_WELL`) passes a `Tabs kind="filter"` in the `filter` row of a `Section` (list and region alike, directly or through a fragment, conditional or `&&`), the filter row of 0.43.1; a views `Tabs` there, a filter `Tabs` in a section's body or in another element's `filter` prop, and loose tabs stay findings. Message, `grammar-laws.yaml` TABS-IN-WELL and `docs/tabs.md` (now with a `tabs-in-well` section) updated.
19
+
3
20
  ## 0.43.1 - 2026-11-17
4
21
 
5
22
  - Version: moves with the Grammar family (@starci/grammar 0.43.1: the disabled reason on touch, one section filter row, a headless region). No rule changed.
package/README.md CHANGED
@@ -19,13 +19,15 @@ Family helpers and the generated runtime closure belong to this package.
19
19
 
20
20
  The rule IDs remain stable when their namespace moves. Laws cover the fixed app shell and navbar,
21
21
  Grammar-owned structural elements, glyphs and icon sizes, destructive menu entries, status inks,
22
- chip labels that start uppercase, a Button that leads somewhere ending with `endArrow` (no typed or icon arrow), a leading icon only on the primary Button (`button-arrow`, `button-icon-primary-only`), report cards in one axis (`layout-two-axis`), no app-made scroll area (`no-raw-scroll`), underline tabs only in the header band (`tabs-in-well`), a Link that takes its look from the line (`link-look`), outline icons only, no solid icon set (`outline-icons-only`), one content per card and no description under a label (`card-one-content`, `no-label-description`), a Section head that holds one Link or one IconButton and never a Button (`section-head-action`), a tab count passed as `count` and never as "· N" in the label (`tab-count-chip`), 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 or the value of a row `control`, and a page stacks two underline `Tabs` layers at most (`tabs-switch-zone`, `tabs-depth`; `docs/tabs.md`). Each rule's metadata cites
22
+ chip labels that start uppercase, a Button that leads somewhere ending with `endArrow` (no typed or icon arrow), a leading icon only on the primary Button (`button-arrow`, `button-icon-primary-only`), report cards in one axis (`layout-two-axis`), no app-made scroll area (`no-raw-scroll`), underline tabs only in the header band (`tabs-in-well`), a Link that takes its look from the line (`link-look`), outline icons only, no solid icon set (`outline-icons-only`), one object per card and no description under a label (`card-one-content`, `no-label-description`), a Section head that holds one Link or one IconButton and never a Button (`section-head-action`), a tab count passed as `count` and never as "· N" in the label (`tab-count-chip`), 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 `action` of a `Section` or the value of a row `control`, 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
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
  `surface-card-list` (0.43.0, LIST-ONE-LOOK: a list is `Section kind="list"` of `ListRow`s, flat rows aligned with the title, never `SurfaceCard kind="list"`; `docs/surface-card-list.md`).
27
+ `card-is-object` (0.45.0, CARD-OBJECT: a card is one object; a card whose only content is a table, a list, facts, disclosures, a form, a field, an empty notice, markdown or a chart is refused, the message names the flat `Section` form; `docs/card-is-object.md`).
28
+ `data-table-surface` (0.45.0: a `DataTable` has one flat look, its `surface` prop is refused and removed by the fix; `docs/data-table-surface.md`).
27
29
  `message-surfaces` (0.37.31: every chat draws Grammar's faces, the thread `--background`, others' messages flat `--surface`, your own `--accent`; no class or style on `MessageBubble`/`MessageCard`, no class string reaching a message part, no `tone: "surface"` on a `role: "log"` thread; `docs/message-surfaces.md`).
28
- 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"`).
30
+ 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"`) `card-is-object` (a card is one object, never a lone collection) and `page-breadcrumbs` (a console `Page` header states `breadcrumbs`, or `"root"`).
29
31
 
30
32
  ## Migrating from @starci/eslint-canon-fe 8.x
31
33
 
package/dist/app-shell.js CHANGED
@@ -135,20 +135,37 @@ const delegatesImportedBar = (context, expression) => {
135
135
  });
136
136
  return imported && !controls && !unknown;
137
137
  };
138
- /** Buttons publish the shared 40px height as `md` (their default), while other bar controls publish `control`. */
139
- const hasBarControlHeight = (context, control, name) => {
138
+ /** Whether every value a prop can take is one of the given string literals. */
139
+ const everyLiteral = (context, expression, allowed) => everyValue(context, expression, (value) => value.type === "Literal" && typeof value.value === "string" && allowed.has(value.value));
140
+ const TOGGLE = new Set(["toggle"]);
141
+ const SWITCH_KINDS = new Set(["toggle", "compact"]);
142
+ /**
143
+ * A bar control's height comes from its published API. Buttons publish the shared 40px height as `md` (their default). A `Switch` publishes it
144
+ * as `kind="toggle"`: a stated `kind` wins and the Grammar ignores `size` beside it, so the kind alone decides, and a Switch with no `kind` is
145
+ * the toggle unless `size` says `md` or `lg`. The other bar controls publish `control`.
146
+ */
147
+ const barControlHeight = (context, control, name) => {
148
+ if (name === "Switch") {
149
+ const kind = propOf(context, control, "kind");
150
+ if (kind.known && kind.value !== null && everyLiteral(context, kind.value, SWITCH_KINDS))
151
+ return everyLiteral(context, kind.value, TOGGLE) ? "control" : "compact";
152
+ if (!kind.known || kind.value !== null)
153
+ return "other";
154
+ }
140
155
  const size = propOf(context, control, "size");
141
156
  if (!size.known)
142
- return false;
143
- if ((name === "Button" || name === "IconButton") && (size.value === null
144
- || everyValue(context, size.value, (value) => value.type === "Literal" && value.value === "md")))
145
- return true;
146
- return textProp(context, control, "size") === "control";
157
+ return "other";
158
+ if ((name === "Button" || name === "IconButton" || name === "Switch") && size.value === null)
159
+ return "control";
160
+ if ((name === "Button" || name === "IconButton") && everyLiteral(context, size.value, new Set(["md"])))
161
+ return "control";
162
+ return textProp(context, control, "size") === "control" ? "control" : "other";
147
163
  };
148
164
  /** Every visible control in a navbar band uses the shared control height through its published size API. */
149
165
  export const navbarControlSize = defineRule({
150
166
  meta: meta("FE_NAVBAR_CONTROL_SIZE", "FE-APP-SHELL-2 requires the shared control height on bar controls.", {
151
- control: "FE_NAVBAR_CONTROL_SIZE: {{name}} in the navbar band needs Grammar's shared control height: omit size or use md for Button/IconButton, and use control for the other bar controls.",
167
+ control: "FE_NAVBAR_CONTROL_SIZE: {{name}} in the navbar band needs Grammar's shared control height: omit size or use md for Button/IconButton, kind=\"toggle\" (or no kind and no size) for Switch, and size=\"control\" for the other bar controls.",
168
+ compact: "FE_NAVBAR_CONTROL_SIZE: a Switch kind=\"compact\" (32x18, no thumb glyph) in the navbar band breaks the bar's one 40px height; the bar's switch is kind=\"toggle\" (72x40, the theme switch). Compact is for a setting in a row, a list, a table cell or a toolbar.",
152
169
  }),
153
170
  create(context) {
154
171
  if (!isProductSource(context))
@@ -156,10 +173,13 @@ export const navbarControlSize = defineRule({
156
173
  const reported = new Set();
157
174
  return { JSXOpeningElement(node) {
158
175
  visitBar(context, node, (control, name) => {
159
- if (!isBarControl(context, control, name) || hasBarControlHeight(context, control, name) || reported.has(control))
176
+ if (!isBarControl(context, control, name) || reported.has(control))
177
+ return;
178
+ const height = barControlHeight(context, control, name);
179
+ if (height === "control")
160
180
  return;
161
181
  reported.add(control);
162
- context.report({ node: control, messageId: "control", data: { name } });
182
+ context.report({ node: control, messageId: height === "compact" ? "compact" : "control", data: { name } });
163
183
  });
164
184
  } };
165
185
  },
@@ -2,15 +2,14 @@ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
2
  import { attributeOf, grammarName, stringProp } from "./lib/grammar-jsx.js";
3
3
  import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
4
  /**
5
- * ONE CONTENT PER CARD (owner, 2026-11-09, CARD-ONE-CONTENT). A `SurfaceCard` holds exactly ONE content: a list, an input group (a form), a table, a graph
6
- * or a figures ribbon. Its own controls are allowed (a tab, search or pagination zone, a form footer with Cancel and Save). Several groups are several
7
- * cards, each with a `Sublabel` above it; items of the same kind stay in one list. A card inside a card is `no-raised-surface-in-surface` (R340). A
8
- * label has no description under it: the description is a caption under the card (`Section caption`, `SurfaceCard note`).
5
+ * ONE OBJECT PER CARD (CARD-ONE-CONTENT). A `SurfaceCard` is ONE object (a customer, an agent, a plan, a message): its name, its facts and its commands
6
+ * (`actions`). A second collection, form or graph is not part of the object: it stands flat in its own `Section`. Items of the same kind stay in one list. A card
7
+ * inside a card is `no-raised-surface-in-surface` (R340); a card whose ONLY content is a collection is `card-is-object`. A label has no description under it:
8
+ * the description is a caption under the card (`Section caption`, `SurfaceCard note`).
9
9
  *
10
10
  * WHAT IT READS.
11
11
  * - `card-one-content`: a `SurfaceCard` whose body (any depth, through layout wrappers) holds more than one content component (a list, a description
12
- * list, a table, a graph, a chart, a timeline, a figures strip, a form group), or whose kind is not `figures` and that carries a `figures` header zone
13
- * (a ribbon above another content).
12
+ * list, a table, a graph, a chart, a timeline, a figures strip, a form group).
14
13
  * - `no-label-description`: a `Section` with a `description`, and a labelled `SurfaceCard` (not a tile) with a `description`.
15
14
  *
16
15
  * WHAT IT LEAVES ALONE. A card with one content, a tile (its description is its content), other components, and non-product source.
@@ -51,22 +50,14 @@ const contentsIn = (context, root) => {
51
50
  visit(root);
52
51
  return found;
53
52
  };
54
- const hasFiguresZone = (opening) => {
55
- const headers = attributeOf(opening, "headers");
56
- const expression = headers?.value?.type === "JSXExpressionContainer" ? headers.value.expression : undefined;
57
- if (expression === undefined || expression.type !== "ArrayExpression")
58
- return false;
59
- return expression.elements.some((entry) => entry !== null && entry.type === "ObjectExpression" && entry.properties.some((property) => property.type === "Property" && property.key.type === "Identifier" && property.key.name === "kind" && property.value.type === "Literal" && property.value.value === "figures"));
60
- };
61
53
  /** A card holds one content. */
62
54
  export const cardOneContent = defineRule({
63
55
  meta: {
64
56
  type: "problem",
65
- docs: { description: "CARD-ONE-CONTENT: a SurfaceCard holds exactly one content (a list, a form, a table, a graph or a figures ribbon); several groups are several cards with a Sublabel above each." },
57
+ docs: { description: "CARD-ONE-CONTENT: a SurfaceCard is one object; a second list, form, table or graph in the same card is its own Section." },
66
58
  schema: [],
67
59
  messages: {
68
- many: "This `SurfaceCard` holds {{count}} contents ({{names}}). A card holds ONE: a list, an input group, a table, a graph or a figures ribbon. Several groups are several cards, each with a `Sublabel` above it; items of the same kind stay in one list.",
69
- ribbon: "A `figures` header zone puts a figures ribbon above another content in one card. A ribbon is its own card (`kind=\"figures\"`), with a `Sublabel` above the cards that follow.",
60
+ many: "This `SurfaceCard` holds {{count}} contents ({{names}}). A card is ONE object. A second list, table, form or graph is not part of it: put each flat in its own `Section` (a ribbon is `Section kind=\"figures\"`); items of the same kind stay in one list.",
70
61
  },
71
62
  },
72
63
  create(context) {
@@ -78,15 +69,13 @@ export const cardOneContent = defineRule({
78
69
  if (grammarName(context, opening) !== "SurfaceCard")
79
70
  return;
80
71
  const kind = stringProp(opening, "kind");
81
- if (kind === "figures" || kind === "tile")
72
+ if (kind === "tile")
82
73
  return;
83
74
  const contents = contentsIn(context, { type: "Program", children: element.children });
84
75
  if (contents.length > 1) {
85
76
  const names = contents.map((entry) => grammarName(context, entry) ?? "?").join(", ");
86
77
  context.report({ node: opening, messageId: "many", data: { count: String(contents.length), names } });
87
78
  }
88
- if (hasFiguresZone(opening))
89
- context.report({ node: opening, messageId: "ribbon" });
90
79
  },
91
80
  };
92
81
  },
@@ -1,6 +1,6 @@
1
1
  import type { Rule } from "eslint";
2
- /** A table component, a chart or a list standing alone is the surface, never wrapped in a card. */
3
- export declare const singleChildCard: Rule.RuleModule;
2
+ /** A card is one object: a collection, a form or a placeholder is never its only content. */
3
+ export declare const cardIsObject: Rule.RuleModule;
4
4
  /** The rules this law contributes to the plugin. */
5
5
  export declare const rules: Record<string, Rule.RuleModule>;
6
6
  /** Every rule of this law is an error. */
@@ -0,0 +1,141 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { attributeOf, elementNameOf, grammarName, hasSpread, nameOf, renderedChildren, stringProp } from "./lib/grammar-jsx.js";
3
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
+ /**
5
+ * A card is one object (CARD-OBJECT): a customer, an agent, a provider, a plan, a message, an approval, a dialog or an overlay. A collection (a list, a
6
+ * table, facts, figures, disclosures, a choice), a form and a placeholder stand flat, in a `Section` or on their own, never in a card.
7
+ *
8
+ * WHAT IT READS. In product source, a Grammar `SurfaceCard` of the body kind (no `kind`, or `kind="body"`) whose ONLY content is one of:
9
+ * - a table: `DataTable`
10
+ * - a section: `Section` of any kind (a list, a region or a figures ribbon)
11
+ * - rows: `DescriptionList`, `DisclosureList`, `Accordion`
12
+ * - a form or a lone field: `Form`, `Fieldset`, `Input`, `Textarea`, `Select`, `ComboBox`, `SearchField`, `NumberField`, `RadioGroup`, `CheckboxGroup`
13
+ * - a placeholder: `EmptyNotice`
14
+ * - markdown: `Markdown`, `MarkdownArticle`
15
+ * - a chart: `BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
16
+ * The body is read through fragments, `cond && <x/>`, `cond ? <x/> : <y/>` and `.map`, and through the layout wrappers `Stack`, `Cluster`, `Inline`, `Grid`
17
+ * and a plain `div` that hold that one content.
18
+ *
19
+ * WHAT IT LEAVES ALONE. A card with `measure="formCompact"` (the sign-in form with no page around it), a `kind="tile"` card, a body card with more than one
20
+ * content (an object's name or facts beside a control is an object), a card with a JSX spread, a non-Grammar `SurfaceCard`, and non-product source.
21
+ *
22
+ * NO AUTOFIX. The move changes the structure (the card's `label` becomes the `Section` title), which the author reads.
23
+ */
24
+ /** The layout wrappers read through, so a card holding one `Stack` of one table is a card holding a table. */
25
+ const WRAPPERS = new Set(["Stack", "Cluster", "Inline", "Grid"]);
26
+ const TABLE = {
27
+ content: "a `DataTable`",
28
+ fix: "Put the table flat under its Section (`<Section title ...><DataTable .../></Section>`).",
29
+ };
30
+ const FORM = {
31
+ content: "a form",
32
+ fix: "Put the form flat under a Section (`<Section title ...><Form .../></Section>`); a sign-in form with no page around it keeps `measure=\"formCompact\"`.",
33
+ };
34
+ const FIELD = {
35
+ content: "one field",
36
+ fix: "Put the field in a Section (`<Section title ...><Form><Input .../></Form></Section>`); a sign-in form with no page around it keeps `measure=\"formCompact\"`.",
37
+ };
38
+ const CHART = {
39
+ content: "a chart",
40
+ fix: "Put the chart flat under a Section (`<Section title ...><BarChart .../></Section>`).",
41
+ };
42
+ const DISCLOSURES = {
43
+ content: "disclosures",
44
+ fix: "Put the disclosures flat under a Section (`<Section title ...><DisclosureList items={...} /></Section>`).",
45
+ };
46
+ /** What each lone content is, in the words the message uses, and where it stands instead. */
47
+ const CONTENT = new Map([
48
+ ["DataTable", TABLE],
49
+ ["DescriptionList", { content: "a `DescriptionList`", fix: "Put the facts flat under a Section (`<Section title ...><DescriptionList isDivided items={...} /></Section>`); the facts of ONE object stay in that object's card beside its name or a control." }],
50
+ ["DisclosureList", DISCLOSURES],
51
+ ["Accordion", DISCLOSURES],
52
+ ["Form", FORM],
53
+ ["Fieldset", FORM],
54
+ ["Input", FIELD],
55
+ ["Textarea", FIELD],
56
+ ["Select", FIELD],
57
+ ["ComboBox", FIELD],
58
+ ["SearchField", FIELD],
59
+ ["NumberField", FIELD],
60
+ ["RadioGroup", FIELD],
61
+ ["CheckboxGroup", FIELD],
62
+ ["EmptyNotice", { content: "an `EmptyNotice`", fix: "An empty state stands on its own: drop the card and keep the `EmptyNotice`." }],
63
+ ["Markdown", { content: "`Markdown`", fix: "Put the text flat under a Section (`<Section title ...><Markdown .../></Section>`)." }],
64
+ ["MarkdownArticle", { content: "`MarkdownArticle`", fix: "Put the text flat under a Section (`<Section title ...><MarkdownArticle .../></Section>`)." }],
65
+ ["BarChart", CHART],
66
+ ["LineChart", CHART],
67
+ ["Sparkline", CHART],
68
+ ["ProportionBar", CHART],
69
+ ["BubbleMap", CHART],
70
+ ["FlowGraph", CHART],
71
+ ["MermaidDiagram", CHART],
72
+ ]);
73
+ /** What a `Section` of this kind is and where it stands instead. */
74
+ const sectionContent = (kind) => {
75
+ if (kind === "list")
76
+ return { content: "a `Section kind=\"list\"`", fix: "A list is flat: drop the card and keep `<Section kind=\"list\" title ... items={...} />`, which titles itself." };
77
+ if (kind === "figures")
78
+ return { content: "a `Section kind=\"figures\"`", fix: "A ribbon is flat: drop the card and keep `<Section kind=\"figures\" items={...} />`." };
79
+ return { content: "a `Section`", fix: "A section stands flat on the page: drop the card and keep the `Section`; its title is the card's `label`." };
80
+ };
81
+ /** True when the card is a body card: no `kind`, or `kind="body"`. A `kind` that is not a literal is left to the compiler. */
82
+ const isBodyCard = (opening) => {
83
+ const attribute = attributeOf(opening, "kind");
84
+ return attribute === undefined || stringProp(opening, "kind") === "body";
85
+ };
86
+ /** The one content a list of rendered children holds, looked through the layout wrappers, or null when it holds none or more than one. */
87
+ const loneContent = (context, children) => {
88
+ if (children.length !== 1)
89
+ return null;
90
+ const child = children[0];
91
+ if (child === undefined || child.type !== "JSXElement")
92
+ return null;
93
+ const opening = child.openingElement;
94
+ if (elementNameOf(child) === null || hasSpread(opening))
95
+ return null;
96
+ const grammar = grammarName(context, opening);
97
+ if (grammar === "Section")
98
+ return sectionContent(stringProp(opening, "kind"));
99
+ if (grammar !== null && WRAPPERS.has(grammar))
100
+ return loneContent(context, renderedChildren(child.children));
101
+ if (opening.name.type === "JSXIdentifier" && opening.name.name === "div")
102
+ return loneContent(context, renderedChildren(child.children));
103
+ if (grammar === null)
104
+ return null;
105
+ return CONTENT.get(nameOf(opening.name) ?? "") ?? null;
106
+ };
107
+ /** A card is one object: a collection, a form or a placeholder is never its only content. */
108
+ export const cardIsObject = defineRule({
109
+ meta: {
110
+ type: "problem",
111
+ docs: { description: "CARD-OBJECT: a body SurfaceCard is one object; a card whose only content is a table, a list, facts, disclosures, a form, a field, an empty notice, markdown or a chart is refused." },
112
+ schema: [],
113
+ messages: {
114
+ collection: "SurfaceCard holds only {{content}}: a card is one object (a customer, an agent, a plan, a message). {{fix}}",
115
+ },
116
+ },
117
+ create(context) {
118
+ if (!isProductSource(context))
119
+ return {};
120
+ return {
121
+ JSXElement(element) {
122
+ const opening = element.openingElement;
123
+ if (grammarName(context, opening) !== "SurfaceCard" || hasSpread(opening) || !isBodyCard(opening))
124
+ return;
125
+ if (stringProp(opening, "measure") === "formCompact")
126
+ return;
127
+ const found = loneContent(context, renderedChildren(element.children));
128
+ if (found === null)
129
+ return;
130
+ context.report({ node: opening, messageId: "collection", data: { content: found.content, fix: found.fix } });
131
+ },
132
+ };
133
+ },
134
+ });
135
+ /** The rules this law contributes to the plugin. */
136
+ export const rules = {
137
+ "card-is-object": cardIsObject,
138
+ };
139
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#CARD-OBJECT");
140
+ /** Every rule of this law is an error. */
141
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -10,7 +10,7 @@ import type { Rule } from "eslint";
10
10
  *
11
11
  * A second rule holds the same law for loose buttons: two or more adjacent `Button` or `IconButton` elements (or one written in a
12
12
  * `.map`) that carry `aria-pressed`, `isSelected` or `isActive` are joined buttons acting as tabs, a pill toggle ("This month / Last
13
- * month"). A switch between views or periods of one block is `Tabs` (the primary underline) in the block's `filter` header zone;
13
+ * month"). A switch between views or periods of one block is `Tabs` (the primary underline) in the `filter` row of the block's `Section` (a mode or period pill is `Section action`);
14
14
  * `ChoiceChips` or `RadioGroup` choose a form value; a button holds a command, never a selection state.
15
15
  */
16
16
  /** Each banned component with the replacement its message names. */
@@ -11,14 +11,14 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
11
11
  *
12
12
  * A second rule holds the same law for loose buttons: two or more adjacent `Button` or `IconButton` elements (or one written in a
13
13
  * `.map`) that carry `aria-pressed`, `isSelected` or `isActive` are joined buttons acting as tabs, a pill toggle ("This month / Last
14
- * month"). A switch between views or periods of one block is `Tabs` (the primary underline) in the block's `filter` header zone;
14
+ * month"). A switch between views or periods of one block is `Tabs` (the primary underline) in the `filter` row of the block's `Section` (a mode or period pill is `Section action`);
15
15
  * `ChoiceChips` or `RadioGroup` choose a form value; a button holds a command, never a selection state.
16
16
  */
17
17
  /** Each banned component with the replacement its message names. */
18
18
  export const REPLACEMENTS = {
19
19
  ButtonGroup: "separate `Button`s (one commit, the rest alternative or dismiss), or a `DropdownMenu` for the overflow",
20
20
  FilterButtonGroup: "`Tabs kind=\"filter\"` (compact underline tabs with a `count` each, under the list's search field) to narrow a list that stays in place",
21
- SegmentedControl: "`ChoiceChips` or `RadioGroup` to choose a value of a form, or `Tabs appearance=\"primary\"` (a `switch` header zone) to switch a mode or period of one block",
21
+ SegmentedControl: "`ChoiceChips` or `RadioGroup` to choose a value of a form, or `Tabs appearance=\"primary\"` (in the `action` of its `Section`) to switch a mode or period of one block",
22
22
  };
23
23
  /** The element name of a JSX opening element (`ButtonGroup`, or `Grammar.ButtonGroup` as `ButtonGroup`). */
24
24
  const elementName = (opening) => {
@@ -98,10 +98,10 @@ const selectionButtonsOf = (node, inMap = false) => {
98
98
  export const noButtonViewSwitch = defineRule({
99
99
  meta: {
100
100
  type: "problem",
101
- docs: { description: "R380: no row of Buttons carrying aria-pressed, isSelected or isActive as a view switch; a switch between views or periods is Tabs in the block's filter header zone." },
101
+ docs: { description: "R380: no row of Buttons carrying aria-pressed, isSelected or isActive as a view switch; a switch between views or periods is Tabs in the `filter` row of the block's Section." },
102
102
  schema: [],
103
103
  messages: {
104
- switch: "Buttons that carry `{{attribute}}` side by side are a view switch drawn as joined buttons or pills. Switching between views or periods of one block is `Tabs` (the primary underline) in the block's `filter` header zone; choosing a form value is `ChoiceChips` or `RadioGroup`; a `Button` holds a command, never a selection state.",
104
+ switch: "Buttons that carry `{{attribute}}` side by side are a view switch drawn as joined buttons or pills. Switching between views or periods of one block is `Tabs` (the primary underline) in the `filter` row of the block's `Section`, or a pill (`Tabs appearance=\"primary\"`) in its `action`; choosing a form value is `ChoiceChips` or `RadioGroup`; a `Button` holds a command, never a selection state.",
105
105
  },
106
106
  },
107
107
  create(context) {
@@ -136,7 +136,7 @@ const hasKind = (object, literal) => object.properties.some((property) => proper
136
136
  export const noPrimaryTabsMisuse = defineRule({
137
137
  meta: {
138
138
  type: "problem",
139
- docs: { description: "R380: Tabs appearance=\"primary\" (and the switch header zone) hold two to four short, fixed options with no count, no href and no attention mark; views, filters and navigation are the secondary underline tabs." },
139
+ docs: { description: "R380: Tabs appearance=\"primary\" (a Section `action` or a row `control`) hold two to four short, fixed options with no count, no href and no attention mark; views, filters and navigation are the secondary underline tabs." },
140
140
  schema: [],
141
141
  messages: {
142
142
  primary: "Primary tabs (a pill in a track) switch a mode or period of the same data among two to four short, fixed options: {{problem}}. Views, filters with counts and destinations are the secondary (underline) `Tabs`.",
@@ -0,0 +1,18 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * ONE FLAT TABLE (DATA-TABLE-SURFACE). A `DataTable` has one flat look: no frame, no card, no fill. The Grammar family 0.45.0 deleted its `surface` prop
4
+ * (`card`, `frame`, `none`), so the compiler refuses it where the types are read; this rule names the fix, and applies it, where an app still writes it (a
5
+ * pinned older Grammar, a JavaScript file, an `any` prop).
6
+ *
7
+ * WHAT IT READS. In product source, a Grammar `DataTable` (named or `G.DataTable`) with a `surface` attribute, whatever its value.
8
+ *
9
+ * WHAT IT LEAVES ALONE. A `surface` on another component (`Pane surface` is its own prop), a non-Grammar `DataTable` and non-product source.
10
+ *
11
+ * AUTOFIX. The attribute and the whitespace before it are removed. The table keeps its columns, rows and `footer`.
12
+ */
13
+ /** A `surface` on a `DataTable` is refused, and removed by the fix. */
14
+ export declare const dataTableSurface: Rule.RuleModule;
15
+ /** The rules this law contributes to the plugin. */
16
+ export declare const rules: Record<string, Rule.RuleModule>;
17
+ /** Every rule of this law is an error. */
18
+ export declare const recommended: Record<string, "error">;
@@ -0,0 +1,57 @@
1
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
+ import { attributeOf, grammarName } from "./lib/grammar-jsx.js";
3
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
+ /**
5
+ * ONE FLAT TABLE (DATA-TABLE-SURFACE). A `DataTable` has one flat look: no frame, no card, no fill. The Grammar family 0.45.0 deleted its `surface` prop
6
+ * (`card`, `frame`, `none`), so the compiler refuses it where the types are read; this rule names the fix, and applies it, where an app still writes it (a
7
+ * pinned older Grammar, a JavaScript file, an `any` prop).
8
+ *
9
+ * WHAT IT READS. In product source, a Grammar `DataTable` (named or `G.DataTable`) with a `surface` attribute, whatever its value.
10
+ *
11
+ * WHAT IT LEAVES ALONE. A `surface` on another component (`Pane surface` is its own prop), a non-Grammar `DataTable` and non-product source.
12
+ *
13
+ * AUTOFIX. The attribute and the whitespace before it are removed. The table keeps its columns, rows and `footer`.
14
+ */
15
+ /** A `surface` on a `DataTable` is refused, and removed by the fix. */
16
+ export const dataTableSurface = defineRule({
17
+ meta: {
18
+ type: "problem",
19
+ fixable: "code",
20
+ docs: { description: "DATA-TABLE-SURFACE: a DataTable has one flat look; its `surface` prop is removed in the Grammar family 0.45.0." },
21
+ schema: [],
22
+ messages: {
23
+ surface: "`DataTable surface` is removed: a table has one flat look. Drop the `surface` attribute and put the table under its `Section` (`<Section title ...><DataTable .../></Section>`).",
24
+ },
25
+ },
26
+ create(context) {
27
+ if (!isProductSource(context))
28
+ return {};
29
+ return {
30
+ JSXOpeningElement(opening) {
31
+ if (grammarName(context, opening) !== "DataTable")
32
+ return;
33
+ const attribute = attributeOf(opening, "surface");
34
+ if (attribute === undefined)
35
+ return;
36
+ context.report({
37
+ node: attribute,
38
+ messageId: "surface",
39
+ fix: (fixer) => {
40
+ const text = context.sourceCode.text;
41
+ let start = attribute.range[0];
42
+ while (start > 0 && /\s/.test(text.charAt(start - 1)))
43
+ start -= 1;
44
+ return fixer.removeRange([start, attribute.range[1]]);
45
+ },
46
+ });
47
+ },
48
+ };
49
+ },
50
+ });
51
+ /** The rules this law contributes to the plugin. */
52
+ export const rules = {
53
+ "data-table-surface": dataTableSurface,
54
+ };
55
+ defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#DATA-TABLE-SURFACE");
56
+ /** Every rule of this law is an error. */
57
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
package/dist/index.js CHANGED
@@ -3,8 +3,10 @@ import { SOURCE_FILES, linterOptions as canonLinterOptions, scopeToPackages } fr
3
3
  import { rules as appShellRules } from "./app-shell.js";
4
4
  import { rules as buttonArrowRules } from "./button-arrow.js";
5
5
  import { rules as cardContentRules } from "./card-content.js";
6
+ import { rules as cardIsObjectRules } from "./card-is-object.js";
6
7
  import { rules as chipLabelRules } from "./chip-label.js";
7
8
  import { rules as choiceControlsRules } from "./choice-controls.js";
9
+ import { rules as dataTableSurfaceRules } from "./data-table-surface.js";
8
10
  import { rules as drawingRules } from "./drawing.js";
9
11
  import { rules as fieldLabelRules } from "./field-label.js";
10
12
  import { rules as freestyleRules } from "./freestyle.js";
@@ -32,7 +34,6 @@ import { rules as statusColorsRules } from "./status-colors.js";
32
34
  import { rules as surfaceCardRules } from "./surface-card.js";
33
35
  import { rules as surfaceCardListRules } from "./surface-card-list.js";
34
36
  import { rules as surfaceDepthRules } from "./surface-depth.js";
35
- import { rules as singleChildCardRules } from "./single-child-card.js";
36
37
  import { rules as surfaceInSurfaceRules } from "./surface-in-surface.js";
37
38
  import { rules as suggestionButtonsRules } from "./suggestion-buttons.js";
38
39
  import { rules as tabCountChipRules } from "./tab-count-chip.js";
@@ -46,8 +47,10 @@ const CONTRIBUTIONS = [
46
47
  { law: "app-shell", rules: appShellRules },
47
48
  { law: "button-arrow", rules: buttonArrowRules },
48
49
  { law: "card-content", rules: cardContentRules },
50
+ { law: "card-is-object", rules: cardIsObjectRules },
49
51
  { law: "chip-label", rules: chipLabelRules },
50
52
  { law: "choice-controls", rules: choiceControlsRules },
53
+ { law: "data-table-surface", rules: dataTableSurfaceRules },
51
54
  { law: "drawing", rules: drawingRules },
52
55
  { law: "field-label", rules: fieldLabelRules },
53
56
  { law: "freestyle", rules: freestyleRules },
@@ -71,7 +74,6 @@ const CONTRIBUTIONS = [
71
74
  { law: "no-card-lead-description", rules: noCardLeadDescriptionRules },
72
75
  { law: "no-nested-label", rules: noNestedLabelRules },
73
76
  { law: "section-head-action", rules: sectionHeadActionRules },
74
- { law: "single-child-card", rules: singleChildCardRules },
75
77
  { law: "status-colors", rules: statusColorsRules },
76
78
  { law: "surface-card", rules: surfaceCardRules },
77
79
  { law: "surface-card-list", rules: surfaceCardListRules },