@starci/eslint-grammar-core 0.28.0 → 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.
- package/CHANGELOG.md +10 -0
- package/README.md +2 -1
- package/dist/index.js +4 -0
- package/dist/lib/why.js +11 -1
- package/dist/single-child-card.d.ts +7 -0
- package/dist/single-child-card.js +103 -0
- package/dist/suggestion-chips.d.ts +6 -0
- package/dist/suggestion-chips.js +122 -0
- package/dist/surface-card.js +1 -1
- package/dist/surface-in-surface.js +1 -1
- package/docs/single-child-card.md +37 -0
- package/docs/suggestion-chips.md +31 -0
- package/docs/surface-in-surface.md +1 -1
- package/package.json +3 -3
- package/runtime/knowledge/ui/presentation/grammar-laws.yaml +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.30.0 - 2026-11-09
|
|
4
|
+
|
|
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`.
|
|
7
|
+
|
|
8
|
+
## 0.29.0 - 2026-11-09
|
|
9
|
+
|
|
10
|
+
- Changed: released with the Grammar family at 0.29.0 (its standalone DataTable and zone text defaults changed); the messages of `surface-card-kind` and `surface-in-surface` that named a bare list card now point at `Section kind="list"`.
|
|
11
|
+
- Added: `single-child-card` (`FE_SINGLE_CHILD_CARD`, SINGLE-CHILD-CARD): a Grammar `SurfaceCard` with no zones (`headers`, `footers`, `labelEnd`) whose only body child is a `DataTable`, a list (`ListBox`, `ItemList`, `DisclosureList`, `Timeline`, `Section kind="list"`) or a chart (`BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`), or that is `kind="table"` or `kind="list"`, is refused; the title is a `Section` head and one line under it is `Section caption`. `docs/single-child-card.md`.
|
|
12
|
+
|
|
3
13
|
## 0.28.0 - 2026-11-09
|
|
4
14
|
|
|
5
15
|
- Changed: released with the Grammar family at 0.28.0; peers `@starci/hfs ~6.5.0`. The new rules below are errors, with no escape.
|
package/README.md
CHANGED
|
@@ -22,7 +22,8 @@ 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
|
-
|
|
25
|
+
`suggestion-chips` (a row of neutral sm Buttons that send their own label is `SuggestionChips`; `docs/suggestion-chips.md`).
|
|
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"`).
|
|
26
27
|
|
|
27
28
|
## Migrating from @starci/eslint-canon-fe 8.x
|
|
28
29
|
|
package/dist/index.js
CHANGED
|
@@ -21,7 +21,9 @@ import { rules as sameLineSizeRules } from "./same-line-size.js";
|
|
|
21
21
|
import { rules as statusColorsRules } from "./status-colors.js";
|
|
22
22
|
import { rules as surfaceCardRules } from "./surface-card.js";
|
|
23
23
|
import { rules as surfaceDepthRules } from "./surface-depth.js";
|
|
24
|
+
import { rules as singleChildCardRules } from "./single-child-card.js";
|
|
24
25
|
import { rules as surfaceInSurfaceRules } from "./surface-in-surface.js";
|
|
26
|
+
import { rules as suggestionChipsRules } from "./suggestion-chips.js";
|
|
25
27
|
import { rules as tabsRules } from "./tabs.js";
|
|
26
28
|
import { rules as tableCellTypeRules } from "./table-cell-type.js";
|
|
27
29
|
import { rules as textRules } from "./text-rules.js";
|
|
@@ -47,9 +49,11 @@ const CONTRIBUTIONS = [
|
|
|
47
49
|
{ law: "pane", rules: paneRules },
|
|
48
50
|
{ law: "row-title-link", rules: rowTitleLinkRules },
|
|
49
51
|
{ law: "same-line-size", rules: sameLineSizeRules },
|
|
52
|
+
{ law: "single-child-card", rules: singleChildCardRules },
|
|
50
53
|
{ law: "status-colors", rules: statusColorsRules },
|
|
51
54
|
{ law: "surface-card", rules: surfaceCardRules },
|
|
52
55
|
{ law: "surface-depth", rules: surfaceDepthRules },
|
|
56
|
+
{ law: "suggestion-chips", rules: suggestionChipsRules },
|
|
53
57
|
{ law: "surface-in-surface", rules: surfaceInSurfaceRules },
|
|
54
58
|
{ law: "tabs", rules: tabsRules },
|
|
55
59
|
{ law: "table-cell-type", rules: tableCellTypeRules },
|
package/dist/lib/why.js
CHANGED
|
@@ -152,7 +152,12 @@ export const why = {
|
|
|
152
152
|
"surface-in-surface": {
|
|
153
153
|
code: "FE_SURFACE_IN_SURFACE",
|
|
154
154
|
en: "A hand-made row list (a Stack, ul, ol or div whose rows are divided by `Divider`) in `<file>` stands inside a SurfaceCard, Drawer, Dialog, PaneSection or main-rail rail.",
|
|
155
|
-
fix: "Use `<Section kind=\"list\">` for rows inside a surface (the Grammar draws them as a nested surface with a border, the card radius and a clip), or
|
|
155
|
+
fix: "Use `<Section kind=\"list\">` for rows inside a surface (the Grammar draws them as a nested surface with a border, the card radius and a clip), or a `Section kind=\"list\"` standing alone (it draws its own frame; a card around a lone list is refused by `single-child-card`).",
|
|
156
|
+
},
|
|
157
|
+
"single-child-card": {
|
|
158
|
+
code: "FE_SINGLE_CHILD_CARD",
|
|
159
|
+
en: "A `SurfaceCard` in `<file>` has no zones and holds one table, list or chart (a `DataTable`, `ListBox`, `ItemList`, `DisclosureList`, `Timeline`, `Section kind=\"list\"`, `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`, or is `kind=\"table\"` or `kind=\"list\"`): a second frame around the one the Grammar already draws.",
|
|
160
|
+
fix: "Drop the card: put the title in a `Section` head (`title`) and one line under it in `Section caption`. A card groups two or more different parts, or carries zones (`headers`, `footers`) or head actions (`labelEnd`).",
|
|
156
161
|
},
|
|
157
162
|
"surface-card-kind": {
|
|
158
163
|
code: "FE_SURFACE_CARD_KIND",
|
|
@@ -184,4 +189,9 @@ export const why = {
|
|
|
184
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).",
|
|
185
190
|
fix: "The row is the one pressable: write the title as plain text (`<Text isStrong>`) and keep the destination on the row.",
|
|
186
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) => ...} />`.",
|
|
196
|
+
},
|
|
187
197
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
/** A table, list or chart standing alone is the surface, never wrapped in a card. */
|
|
3
|
+
export declare const singleChildCard: Rule.RuleModule;
|
|
4
|
+
/** The rules this law contributes to the plugin. */
|
|
5
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
6
|
+
/** Every rule of this law is an error. */
|
|
7
|
+
export declare const recommended: Record<string, "error">;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
|
|
2
|
+
import { attributeOf, elementNameOf, grammarName, hasSpread, renderedChildren, stringProp } from "./lib/grammar-jsx.js";
|
|
3
|
+
import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
|
|
4
|
+
/**
|
|
5
|
+
* The lone surface law (owner, 2026-11-09, SINGLE-CHILD-CARD): a card groups two or more different parts (figures + list +
|
|
6
|
+
* actions) or carries zones (tabs, search, head actions). A table, a list or a chart standing alone IS the surface: the
|
|
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.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT READS. A Grammar `SurfaceCard` (imported from `@starci/grammar`) with no zones: no `headers` or `footers` prop (an
|
|
12
|
+
* empty array literal counts as none) and no `labelEnd` (head actions). Its body is read through fragments, `cond && <x/>`,
|
|
13
|
+
* `cond ? <x/> : <y/>` and `.map`, ignoring blank text. It is refused when that body is ONE element and that element is:
|
|
14
|
+
* - a table: `DataTable`;
|
|
15
|
+
* - a list: `ListBox`, `ItemList`, `DisclosureList`, `Timeline`, or `Section kind="list"`;
|
|
16
|
+
* - a chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`.
|
|
17
|
+
* It is also refused when the card is the data-driven form of the same thing: `SurfaceCard kind="table"` or `kind="list"`.
|
|
18
|
+
*
|
|
19
|
+
* DECIDED. `Meter`, `Progress` and `ProgressCircle` are single values, not charts. `DescriptionList` (term/value facts of one
|
|
20
|
+
* record) and `Accordion` are not read as lists here: a record's facts are the `kind="details"` card. `SurfaceCard
|
|
21
|
+
* kind="figures"`, `details`, `accordion` and `tile` are not judged. `SurfaceCard` rules for kinds, depth and nesting stay with
|
|
22
|
+
* `surface-card-kind`, `no-raised-surface-in-surface` and `surface-depth`; none is read again here.
|
|
23
|
+
*
|
|
24
|
+
* WHAT IT LEAVES ALONE. A card with two or more body children, a card with zones or `labelEnd`, a card with a JSX spread (a
|
|
25
|
+
* prop may arrive that the source does not show), a non-Grammar `SurfaceCard`, and non-product source.
|
|
26
|
+
*
|
|
27
|
+
* WHERE IT APPLIES. Product source (`isProductSource`).
|
|
28
|
+
*/
|
|
29
|
+
/** The table, list and chart components that are a surface on their own, with the word the message names them by. */
|
|
30
|
+
const LONE = new Map([
|
|
31
|
+
["DataTable", "table"],
|
|
32
|
+
["ListBox", "list"],
|
|
33
|
+
["ItemList", "list"],
|
|
34
|
+
["DisclosureList", "list"],
|
|
35
|
+
["Timeline", "list"],
|
|
36
|
+
["BarChart", "chart"],
|
|
37
|
+
["ProportionBar", "chart"],
|
|
38
|
+
["BubbleMap", "chart"],
|
|
39
|
+
["FlowGraph", "chart"],
|
|
40
|
+
["MermaidDiagram", "chart"],
|
|
41
|
+
]);
|
|
42
|
+
/** True when an attribute is an empty array literal (`headers={[]}`), which zones nothing. */
|
|
43
|
+
const isEmptyArray = (attribute) => {
|
|
44
|
+
const value = attribute.value;
|
|
45
|
+
return value?.type === "JSXExpressionContainer" && value.expression.type === "ArrayExpression" && value.expression.elements.length === 0;
|
|
46
|
+
};
|
|
47
|
+
/** True when the card carries a zone or head actions: a `headers` or `footers` prop that is not an empty array, or a `labelEnd`. */
|
|
48
|
+
const hasZones = (opening) => {
|
|
49
|
+
const zoned = ["headers", "footers"].some((name) => {
|
|
50
|
+
const attribute = attributeOf(opening, name);
|
|
51
|
+
return attribute !== undefined && !isEmptyArray(attribute);
|
|
52
|
+
});
|
|
53
|
+
return zoned || attributeOf(opening, "labelEnd") !== undefined;
|
|
54
|
+
};
|
|
55
|
+
/** What the lone child is, as the message names it (`DataTable`, `Section kind="list"`), or null when it is not a surface on its own. */
|
|
56
|
+
const loneChild = (context, card) => {
|
|
57
|
+
const body = renderedChildren(card.children);
|
|
58
|
+
if (body.length !== 1)
|
|
59
|
+
return null;
|
|
60
|
+
const child = body[0];
|
|
61
|
+
if (child?.type !== "JSXElement")
|
|
62
|
+
return null;
|
|
63
|
+
const name = elementNameOf(child);
|
|
64
|
+
if (name === null || grammarName(context, child.openingElement) === null)
|
|
65
|
+
return null;
|
|
66
|
+
if (name === "Section")
|
|
67
|
+
return stringProp(child.openingElement, "kind") === "list" ? "Section kind=\"list\"" : null;
|
|
68
|
+
return LONE.has(name) ? name : null;
|
|
69
|
+
};
|
|
70
|
+
/** A table, list or chart standing alone is the surface, never wrapped in a card. */
|
|
71
|
+
export const singleChildCard = defineRule({
|
|
72
|
+
meta: {
|
|
73
|
+
type: "problem",
|
|
74
|
+
docs: { description: "SINGLE-CHILD-CARD: a SurfaceCard with no zones whose only content is a table, list or chart is a second frame; the title is a Section head." },
|
|
75
|
+
schema: [],
|
|
76
|
+
messages: {
|
|
77
|
+
lone: "A {{child}} standing alone is the surface: drop the SurfaceCard, put its title in a `Section` head (`title`) and one line under it in `Section caption`. A card groups two or more different parts, or carries zones (tabs, search, head actions).",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
create(context) {
|
|
81
|
+
if (!isProductSource(context))
|
|
82
|
+
return {};
|
|
83
|
+
return {
|
|
84
|
+
JSXElement(element) {
|
|
85
|
+
const opening = element.openingElement;
|
|
86
|
+
if (grammarName(context, opening) !== "SurfaceCard" || hasSpread(opening) || hasZones(opening))
|
|
87
|
+
return;
|
|
88
|
+
const kind = stringProp(opening, "kind");
|
|
89
|
+
const child = kind === "table" || kind === "list" ? kind : loneChild(context, element);
|
|
90
|
+
if (child === null)
|
|
91
|
+
return;
|
|
92
|
+
context.report({ node: opening, messageId: "lone", data: { child: kind === child ? child : `\`${child}\`` } });
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
/** The rules this law contributes to the plugin. */
|
|
98
|
+
export const rules = {
|
|
99
|
+
"single-child-card": singleChildCard,
|
|
100
|
+
};
|
|
101
|
+
defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#SINGLE-CHILD-CARD");
|
|
102
|
+
/** Every rule of this law is an error. */
|
|
103
|
+
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
export declare const suggestionChips: Rule.RuleModule;
|
|
3
|
+
/** The rules this law contributes to the plugin. */
|
|
4
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
5
|
+
/** Every rule of this law is an error. */
|
|
6
|
+
export declare const recommended: Record<string, "error">;
|
|
@@ -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 { 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"]));
|
package/dist/surface-card.js
CHANGED
|
@@ -161,7 +161,7 @@ export const surfaceCardKind = defineRule({
|
|
|
161
161
|
docs: { description: "R355: a SurfaceCard of the body kind holds no hand list, no Divider and no SectionHeader or Heading." },
|
|
162
162
|
schema: [],
|
|
163
163
|
messages: {
|
|
164
|
-
list: "`<{{element}}>` is a hand-built list in a `body` card. Rows are `<
|
|
164
|
+
list: "`<{{element}}>` is a hand-built list in a `body` card. Rows are `<Section kind=\"list\" items={...} empty={...} />` (with zones: `<SurfaceCard kind=\"list\" headers={...}>`), which draws every row the same way.",
|
|
165
165
|
divider: "A `Divider` in a card is refused: the card draws its own seams. Bands divided by a line are the typed `headers` and `footers` zones: `<SurfaceCard headers={[{ kind: \"figures\", items }]} />`.",
|
|
166
166
|
zone: "`<{{element}}>` stands in a `custom` zone of a card. Filter and search are the typed zones (`{ kind: \"filter\" | \"search\" | \"toolbar\" }`) and the card draws its own seams, so a `custom` zone holds no `Tabs`, `SearchField` or `Divider`.",
|
|
167
167
|
title: "`<{{element}}>` stands as a second title inside a card. The card has a `label` (and `fact`, `labelEnd`, `note`); a sub-section of one subject is a typed header or footer zone.",
|
|
@@ -57,7 +57,7 @@ export const surfaceInSurface = defineRule({
|
|
|
57
57
|
docs: { description: "SURFACE-IN-SURFACE: a row list divided by Dividers inside a card, drawer, dialog, pane band or rail is a Section kind=list or a SurfaceCard kind=list." },
|
|
58
58
|
schema: [],
|
|
59
59
|
messages: {
|
|
60
|
-
handMade: "This `{{element}}` is a hand-made row list inside {{host}}: its rows are divided by `Divider` elements, so it has no edge, no card radius and no clip. Use `<Section kind=\"list\">` for rows inside a surface (the Grammar draws them as a nested surface), or
|
|
60
|
+
handMade: "This `{{element}}` is a hand-made row list inside {{host}}: its rows are divided by `Divider` elements, so it has no edge, no card radius and no clip. Use `<Section kind=\"list\">` for rows inside a surface (the Grammar draws them as a nested surface), or a `Section kind=\"list\"` with its own frame when the list stands alone (a card around a lone list is refused by `single-child-card`).",
|
|
61
61
|
},
|
|
62
62
|
},
|
|
63
63
|
create(context) {
|
|
@@ -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).
|
|
@@ -22,7 +22,7 @@ A Grammar `Stack`, or a `ul`, `ol` or `div`, whose rendered children include a G
|
|
|
22
22
|
|
|
23
23
|
```tsx
|
|
24
24
|
<Drawer title="Runs"><Section kind="list" items={runs} /></Drawer>
|
|
25
|
-
<SurfaceCard label="Runs" kind="list" items={runs} empty={null} />
|
|
25
|
+
<SurfaceCard label="Runs" kind="list" headers={[{ kind: "filter", /* ... */ }]} items={runs} empty={null} />
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-grammar-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.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": "
|
|
72
|
-
"starciSource": "
|
|
71
|
+
"gitHead": "60a43b01a0944d2c8252e074946b82f3ee60c988",
|
|
72
|
+
"starciSource": "c9f0db9043d7d17e3fb8d7d1e230fde769670e27b4cf7e2c6b27fcc1901fd99f"
|
|
73
73
|
}
|
|
@@ -57,6 +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.
|
|
63
|
+
cases:
|
|
64
|
+
- id: case-1
|
|
65
|
+
when: A row of neutral sm Buttons each send their own label
|
|
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.
|
|
60
69
|
- id: TABLE-CELL-TYPE
|
|
61
70
|
title: Table and row cells take the row type sizes
|
|
62
71
|
governs: Text inside a DataTable cell or a ListRow.
|
|
@@ -100,3 +109,13 @@ rules:
|
|
|
100
109
|
assert: |-
|
|
101
110
|
The page tabs (`Page header.tabs`) and one region set are the two layers; a third nested set is refused.
|
|
102
111
|
Every tab is one size, so only the count of layers is judged.
|
|
112
|
+
- id: SINGLE-CHILD-CARD
|
|
113
|
+
title: A table, list or chart standing alone is the surface
|
|
114
|
+
governs: A SurfaceCard whose only content is a table, a list or a chart.
|
|
115
|
+
cases:
|
|
116
|
+
- id: case-1
|
|
117
|
+
when: A card has no zones (headers, footers, head actions) and holds one DataTable, list (ListBox, ItemList, DisclosureList, Timeline, Section kind="list") or chart (BarChart, ProportionBar, BubbleMap, FlowGraph, MermaidDiagram), or is kind="table" or kind="list"
|
|
118
|
+
assert: |-
|
|
119
|
+
The Grammar draws a standalone DataTable and every Section kind="list" as ONE frame (border, card radius), so the
|
|
120
|
+
card is a second frame. The title sits above as a Section head and one caption sits below (Section caption, muted sm).
|
|
121
|
+
A card groups two or more different parts (figures + list + actions), or carries zones (tabs, search, head actions).
|