@starci/eslint-grammar-core 0.44.0 → 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.
- package/CHANGELOG.md +12 -0
- package/README.md +4 -2
- package/dist/card-content.js +8 -19
- package/dist/{single-child-card.d.ts → card-is-object.d.ts} +2 -2
- package/dist/card-is-object.js +141 -0
- package/dist/choice-controls.d.ts +1 -1
- package/dist/choice-controls.js +5 -5
- package/dist/data-table-surface.d.ts +18 -0
- package/dist/data-table-surface.js +57 -0
- package/dist/index.js +4 -2
- package/dist/lib/why.js +25 -20
- package/dist/no-card-lead-description.js +3 -3
- package/dist/rows-in-card.d.ts +1 -1
- package/dist/rows-in-card.js +13 -12
- package/dist/surface-card-list.d.ts +1 -2
- package/dist/surface-card-list.js +1 -2
- package/dist/surface-card.d.ts +1 -1
- package/dist/surface-card.js +8 -63
- package/dist/surface-depth.js +1 -1
- package/dist/surface-in-surface.js +1 -1
- package/dist/tabs.d.ts +3 -3
- package/dist/tabs.js +21 -20
- package/docs/card-content.md +5 -6
- package/docs/card-is-object.md +42 -0
- package/docs/choice-controls.md +4 -4
- package/docs/data-table-surface.md +27 -0
- package/docs/layout-two-axis.md +3 -3
- package/docs/no-card-lead-description.md +2 -2
- package/docs/no-nested-label.md +3 -3
- package/docs/rows-in-card.md +5 -4
- package/docs/surface-card-list.md +1 -2
- package/docs/surface-card.md +4 -8
- package/docs/surface-depth.md +6 -7
- package/docs/surface-in-surface.md +2 -2
- package/docs/tabs.md +4 -4
- package/package.json +3 -3
- package/runtime/knowledge/ui/presentation/grammar-laws.yaml +32 -23
- package/dist/single-child-card.js +0 -90
- package/docs/single-child-card.md +0 -37
package/docs/surface-card.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
#
|
|
1
|
+
# A card is one object
|
|
2
2
|
|
|
3
3
|
Law module: `surface-card.ts`. Catalogue: R355 FE_SURFACE_CARD_KIND, R366 FE_LABEL_IN_GRID.
|
|
4
4
|
|
|
5
|
-
`SurfaceCard` is one component whose `kind` the compiler checks: `body` (the default), `
|
|
6
|
-
and `tile`; any kind may carry typed `headers` and `footers` zones. What a kind draws is not drawn by hand around it, and where the name sits follows the kind: a card that heads a section has a `label` outside the material, a tile names itself inside.
|
|
5
|
+
`SurfaceCard` is one component whose `kind` the compiler checks: `body` (the default) and `tile`. A card is ONE object (a customer, an agent, a plan, a message), a dialog or an overlay; a body card holds the object's name, facts and commands (`actions`). A collection stands flat in a `Section`: a list is `Section kind="list"`, figures `Section kind="figures"`, a filter or search row the `filter` of a `Section`. What a `Section` draws is not drawn by hand in a card, and where the name sits follows the kind: a body card has a `label` outside the material, a tile names itself inside.
|
|
7
6
|
|
|
8
7
|
Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline. It applies to product
|
|
9
8
|
source; a script or a file no slot owns is not judged.
|
|
@@ -12,11 +11,8 @@ source; a script or a file no slot owns is not judged.
|
|
|
12
11
|
|
|
13
12
|
Finding code: `FE_SURFACE_CARD_KIND` (R355). The direct children of a `SurfaceCard` of the `body` kind (no `kind`, or
|
|
14
13
|
`kind="body"`) are not a raw `ul`, `ol`, `li` or `dl`, not a `Divider`, and not a `SectionHeader` or `Heading` standing as a
|
|
15
|
-
second title.
|
|
14
|
+
second title. Children are read through
|
|
16
15
|
`cond && <x/>`, `cond ? <x/> : <y/>` and `.map`.
|
|
17
|
-
On a `SurfaceCard` or a `Board`, the `children` of a `{ kind: "custom" }` zone written in a `headers` or `footers` array literal hold no
|
|
18
|
-
`Tabs`, `SearchField` or `Divider` (`zone`): filter and search are the typed `filter`, `search` and `toolbar` zones and the card draws
|
|
19
|
-
its own seams. Grammar also refuses them at run time in development.
|
|
20
16
|
|
|
21
17
|
**Invalid** (`src/components/blocks/Runs/component.tsx`)
|
|
22
18
|
|
|
@@ -38,7 +34,7 @@ its own seams. Grammar also refuses them at run time in development.
|
|
|
38
34
|
|
|
39
35
|
Finding code: `FE_LABEL_IN_GRID` (R366). A `SurfaceCard` with a `label` repeated in a `Grid kind="cards"` (two or more as
|
|
40
36
|
direct children, or one written in a `.map`) is refused. A peer you recognise and open is a tile, named inside beside its
|
|
41
|
-
mark; comparing a fact across peers is one `Section kind="list"` or a `
|
|
37
|
+
mark; comparing a fact across peers is one `Section kind="list"` or a `Section` holding a `DataTable`.
|
|
42
38
|
|
|
43
39
|
**Invalid** (`src/components/blocks/Connectors/component.tsx`)
|
|
44
40
|
|
package/docs/surface-depth.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Law module: `surface-depth.ts`. Catalogue: R340 FE_RAISED_SURFACE_IN_SURFACE.
|
|
4
4
|
|
|
5
|
-
A `SurfaceCard` inside another `SurfaceCard` is refused
|
|
5
|
+
A `SurfaceCard` inside another `SurfaceCard` is refused: a card never sits in a card. A white `Pane surface`, `Drawer`, `Dialog`, `AlertDialog` or `Popover` may hold an object card, drawn as everywhere: a 1px `--border` edge and no shadow (BOUNDARY-6). Development throws the card-in-card refusal from the Grammar itself; this rule is its same-file half and R356 closes it across files.
|
|
6
6
|
|
|
7
7
|
Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline. It applies to product
|
|
8
8
|
source (the route, feature, component, hook, foundation, module and transport tiers and the workspace packages); a script or
|
|
@@ -10,7 +10,7 @@ a file no slot owns is not judged.
|
|
|
10
10
|
|
|
11
11
|
## `starci-grammar/no-raised-surface-in-surface`
|
|
12
12
|
|
|
13
|
-
A `SurfaceCard` (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that another `SurfaceCard` of the same file encloses is a finding. A card no element of the file encloses is judged where its parent is written. The fix gives the content to the outer card's own body, or
|
|
13
|
+
A `SurfaceCard` (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that another `SurfaceCard` of the same file encloses is a finding. A card no element of the file encloses is judged where its parent is written. The fix gives the content to the outer card's own body; a list, a table or figures inside it stand flat in a `Section` (`Section kind="list"`, `Section kind="figures"`).
|
|
14
14
|
|
|
15
15
|
**Invalid** (`src/components/blocks/Runs/component.tsx`)
|
|
16
16
|
|
|
@@ -23,11 +23,10 @@ A `SurfaceCard` (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that ano
|
|
|
23
23
|
**Valid** (`src/components/blocks/Runs/component.tsx`)
|
|
24
24
|
|
|
25
25
|
```tsx
|
|
26
|
-
<SurfaceCard
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/>
|
|
26
|
+
<SurfaceCard label="Run">
|
|
27
|
+
<Text>{summary}</Text>
|
|
28
|
+
<Section kind="list" ariaLabel="Steps" items={steps} empty={empty} />
|
|
29
|
+
</SurfaceCard>
|
|
31
30
|
```
|
|
32
31
|
|
|
33
32
|
**Finding code:** `FE_RAISED_SURFACE_IN_SURFACE`
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Law module: `surface-in-surface.ts`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#SURFACE-IN-SURFACE`. Finding code: `FE_SURFACE_IN_SURFACE`.
|
|
4
4
|
|
|
5
|
-
Rows inside a
|
|
5
|
+
Rows inside a drawer, a dialog, a pane band or a rail are a `Section kind="list"`, drawn as everywhere else: flat rows divided by hairlines, aligned with the title (LIST-ONE-LOOK). A hand-made row list is the bare form.
|
|
6
6
|
|
|
7
7
|
Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
|
|
8
8
|
|
|
@@ -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
|
-
<
|
|
25
|
+
<Stack><Section kind="figures" ariaLabel="Totals" items={totals} /><Section kind="list" title="Runs" items={runs} empty={null} /></Stack>
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
|
package/docs/tabs.md
CHANGED
|
@@ -6,7 +6,7 @@ Underline tabs switch panels: the page tabs (`Page header.tabs`) and, inside a t
|
|
|
6
6
|
|
|
7
7
|
## `starci-grammar/tabs-switch-zone`
|
|
8
8
|
|
|
9
|
-
Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in JSX is a finding wherever it stands (a page body, under the page tabs, a pane, a drawer). The pill
|
|
9
|
+
Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in JSX is a finding wherever it stands (a page body, under the page tabs, a pane, a drawer). The pill stands as the `action` of the block's `Section` (`action={<Tabs appearance="primary" ... />}`) and, since 0.37.16, as the value of a row `control` (an object property named `control` in a list row literal, or a JSX attribute `control={...}`, directly or through a fragment, conditional or `&&`): a row-level mode choice such as "Auto | Ask" lives in the row. The item checks (two to four options, no `count`, `href` or `isAttention`) stay in `no-primary-tabs-misuse` (R380).
|
|
10
10
|
|
|
11
11
|
**Invalid**
|
|
12
12
|
|
|
@@ -19,8 +19,8 @@ Finding code: `FE_TABS_SWITCH_ZONE`. A `<Tabs appearance="primary">` written in
|
|
|
19
19
|
**Valid**
|
|
20
20
|
|
|
21
21
|
```tsx
|
|
22
|
-
<
|
|
23
|
-
<
|
|
22
|
+
<Section kind="list" title="Agent" items={[{ id: "send", title: "Send", control: <Tabs appearance="primary" label="Send" items={modes} selectedKey={mode} onSelect={setMode} /> }]} empty={null} />
|
|
23
|
+
<Section title="Cash" action={<Tabs appearance="primary" label="Period" items={periods} selectedKey={period} onSelect={setPeriod} />}><DataTable label="Cash" columns={columns} rows={rows} renderCell={renderCell} emptyContent={empty} /></Section>
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
## `starci-grammar/tabs-depth`
|
|
@@ -50,7 +50,7 @@ The rule reads one file. A set whose page tabs are drawn by another file (a layo
|
|
|
50
50
|
|
|
51
51
|
## `starci-grammar/tabs-in-well`
|
|
52
52
|
|
|
53
|
-
Finding code: `FE_TABS_IN_WELL`. An underline `Tabs` written as a child of a `Page`, `Pane` or `PaneSection` stands loose on the pink well or in a pane body: the second layer is `Page header.subTabs`. A `Tabs` stands in a header row of its own, and passes,
|
|
53
|
+
Finding code: `FE_TABS_IN_WELL`. An underline `Tabs` written as a child of a `Page`, `Pane` or `PaneSection` stands loose on the pink well or in a pane body: the second layer is `Page header.subTabs`. A `Tabs` stands in a header row of its own, and passes, as `kind="filter"`, in the `filter` row of a `Section` (a list's or a region's alike, 0.43.1, `contexts/ui/components/list-table.md` "Filter row"), directly or through a fragment, conditional or `&&`. A `Drawer`, `Dialog`, `Modal`, `Popover` or `Sheet` starts its own surface and ends the climb.
|
|
54
54
|
|
|
55
55
|
**Invalid**
|
|
56
56
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-grammar-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.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": "fe7bc440d0a16a1065ce25e74a37928c826ca7ed",
|
|
72
|
+
"starciSource": "bdee448048ec6c2a121a4b6da7f4838fa0fae3bda7165468b4794a8439f5f4fe"
|
|
73
73
|
}
|
|
@@ -142,14 +142,14 @@ rules:
|
|
|
142
142
|
assert: |-
|
|
143
143
|
Its title is plain text; the row is the one pressable.
|
|
144
144
|
- id: TABS-SWITCH-ZONE
|
|
145
|
-
title: The pill is the
|
|
145
|
+
title: The pill is the action of a Section
|
|
146
146
|
governs: Tabs appearance="primary".
|
|
147
147
|
cases:
|
|
148
148
|
- id: case-1
|
|
149
149
|
when: A mode or period of one block's data is switched among two to four short options
|
|
150
150
|
assert: |-
|
|
151
|
-
It is the
|
|
152
|
-
with no count and no href. A pill written in JSX in a page body, under the page tabs, in a pane or in a drawer
|
|
151
|
+
It is the `action` of the block's `Section` (`<Section title action={<Tabs appearance="primary" label items selectedKey onSelect />} />`),
|
|
152
|
+
with no count and no href; a row-level mode choice is the `control` of its row. A pill written in JSX in a page body, under the page tabs, in a pane or in a drawer
|
|
153
153
|
is refused: views of a page are page tabs, views or filters inside a region are underline `Tabs`.
|
|
154
154
|
- id: TABS-DEPTH
|
|
155
155
|
title: A page stacks two underline layers at most
|
|
@@ -170,7 +170,7 @@ rules:
|
|
|
170
170
|
It is `Page header.subTabs`: inside the white header band, under layer 1, on its own full-width separator, the same size as layer 1
|
|
171
171
|
(14, 40 high, selected weight 500, the 2px underline exactly on the separator) and flush with the band's left inset, the same x as layer 1.
|
|
172
172
|
An underline Tabs written loose in the body of a Page, Pane or PaneSection (the pink well, a pane body) is refused; one in a header row of
|
|
173
|
-
its own,
|
|
173
|
+
its own, kind="filter" in a Section's filter row, is not loose.
|
|
174
174
|
- id: LINK-LOOK
|
|
175
175
|
title: A Link is HeroUI's own link and takes its size from the line
|
|
176
176
|
governs: The look of a Grammar Link.
|
|
@@ -181,14 +181,14 @@ rules:
|
|
|
181
181
|
It is HeroUI v3's link: the primary colour, the underline on hover only, the anchor icon at the end. Its type size and leading are
|
|
182
182
|
inherited (14 in a body, 12 in meta or caption text). A size prop, a size class and an underline or decoration class are refused.
|
|
183
183
|
- id: ROWS-IN-CARD
|
|
184
|
-
title: Key-value and disclosure rows stand in a
|
|
185
|
-
governs: Key-value and disclosure rows
|
|
184
|
+
title: Key-value and disclosure rows stand in a section or an object card
|
|
185
|
+
governs: Key-value and disclosure rows (a plain list of rows is LIST-ONE-LOOK).
|
|
186
186
|
cases:
|
|
187
187
|
- id: case-1
|
|
188
188
|
when: A DescriptionList or DisclosureList is drawn
|
|
189
189
|
assert: |-
|
|
190
|
-
It stands in a Section
|
|
191
|
-
|
|
190
|
+
It stands flat in a Section (`<Section title ...><DescriptionList isDivided items={...} /></Section>`) or, as the facts of ONE object, in the body of that object's
|
|
191
|
+
SurfaceCard. A row primitive with neither around it is refused. ListBox is a navigation list and is not read.
|
|
192
192
|
- id: CARD-NO-DESCRIPTION
|
|
193
193
|
title: A card has no description
|
|
194
194
|
governs: The head of a SurfaceCard and the line above it.
|
|
@@ -197,7 +197,7 @@ rules:
|
|
|
197
197
|
when: A card is drawn with a label
|
|
198
198
|
assert: |-
|
|
199
199
|
The head is the label, a count chip, one fact and one end action; SurfaceCard has no description or subtitle prop. A muted Text written directly above a
|
|
200
|
-
SurfaceCard as its description is refused: the line is a row subtitle (a
|
|
200
|
+
SurfaceCard as its description is refused: the line is a row subtitle (a ListRow subtitle of a Section list, or an option description of a RadioGroup) or, when it explains the card's data, the card note.
|
|
201
201
|
- id: LABEL-SUBLABEL-HIERARCHY
|
|
202
202
|
title: One Label per section; nested groups use a Sublabel
|
|
203
203
|
governs: The Label of a Section or SurfaceCard and the Sublabel of the groups inside it.
|
|
@@ -228,21 +228,20 @@ rules:
|
|
|
228
228
|
The chip is grey; it is pink only when the number is work waiting for the owner (`isAttention`: to handle, to approve, an error). Page tabs
|
|
229
229
|
(layers 1 and 2) hide the chip when the count is 0; filter tabs inside a table or list show a grey 0.
|
|
230
230
|
- id: CARD-ONE-CONTENT
|
|
231
|
-
title: One
|
|
231
|
+
title: One object per card; every card is white with a 1px border
|
|
232
232
|
governs: A SurfaceCard's content and its edge.
|
|
233
233
|
cases:
|
|
234
234
|
- id: case-1
|
|
235
235
|
when: A card is written
|
|
236
236
|
assert: |-
|
|
237
|
-
A card
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
(a FlowGraph's kinds) stands under the card as chips.
|
|
237
|
+
A card is ONE object (a customer, an agent, a plan, a message): its name, its facts and its commands (`actions`). A second list, table, form or graph is not part of it: it stands
|
|
238
|
+
flat in its own Section (a ribbon is `Section kind="figures"`); items of the same kind stay in one list. A card inside a card is refused. A label has no description under it:
|
|
239
|
+
the description is a caption under the card (Section caption, SurfaceCard note), and a legend (a FlowGraph's kinds) stands under the card as chips.
|
|
241
240
|
- id: case-2
|
|
242
241
|
when: A surface is painted
|
|
243
242
|
assert: |-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
Every card is white with a 1px `--border` edge, the card radius and no shadow, on every ground (the pink well, a Pane surface, the aside, a Drawer, a Dialog, a Popover). The Grammar
|
|
244
|
+
draws it; an app never chooses. A FlowGraph inside a card draws no frame of its own.
|
|
246
245
|
- id: ICONS-OUTLINE
|
|
247
246
|
title: Icons are outline only; a tile marks a standalone icon
|
|
248
247
|
governs: Every icon Grammar and an app draw.
|
|
@@ -254,16 +253,26 @@ rules:
|
|
|
254
253
|
row, a card, an empty state or a graph step gets an icon tile (a soft-tone square holding an outline icon). An icon INLINE with text (a status beside a
|
|
255
254
|
label, a search field, a button start icon, a link arrow, meta) is a plain outline icon at text size with no tile. A status (done, running, failed, waiting,
|
|
256
255
|
skipped) is a tone-coloured outline icon with no tile: outline check-circle in success, x-circle in danger, a spinning arrow for running.
|
|
257
|
-
- id:
|
|
258
|
-
title: A
|
|
259
|
-
governs: A SurfaceCard
|
|
256
|
+
- id: CARD-OBJECT
|
|
257
|
+
title: A card is one object; a collection, a form or a placeholder stands flat
|
|
258
|
+
governs: A SurfaceCard of the body kind and what it holds.
|
|
260
259
|
cases:
|
|
261
260
|
- id: case-1
|
|
262
|
-
when: A
|
|
261
|
+
when: A body SurfaceCard holds ONE content and that content is a DataTable, a Section (any kind), a DescriptionList, a DisclosureList or Accordion, a Form, Fieldset or lone field, an EmptyNotice, Markdown or MarkdownArticle, or a chart (BarChart, LineChart, Sparkline, ProportionBar, BubbleMap, FlowGraph, MermaidDiagram)
|
|
263
262
|
assert: |-
|
|
264
|
-
A
|
|
265
|
-
|
|
266
|
-
|
|
263
|
+
A card is ONE object (a customer, an agent, a provider, a plan, a message, an approval), a dialog or an overlay; a collection, a form and a placeholder are never in a card.
|
|
264
|
+
A table is `<Section title ...><DataTable .../></Section>`, a list `Section kind="list"`, facts `<Section title ...><DescriptionList isDivided items={...} /></Section>`,
|
|
265
|
+
disclosures `<Section title ...><DisclosureList .../></Section>`, a form or field `<Section title ...><Form .../></Section>`, an empty state an `EmptyNotice` on its own,
|
|
266
|
+
markdown or a chart a `Section`. A body card with more than one content (an object's name or facts beside a control) is an object. A card with `measure="formCompact"`
|
|
267
|
+
(the sign-in form with no page around it) and a `kind="tile"` card are not judged.
|
|
268
|
+
- id: DATA-TABLE-SURFACE
|
|
269
|
+
title: A table has one flat look
|
|
270
|
+
governs: The `surface` prop of a DataTable (removed in the Grammar family 0.45.0).
|
|
271
|
+
cases:
|
|
272
|
+
- id: case-1
|
|
273
|
+
when: A DataTable is written with a `surface` attribute
|
|
274
|
+
assert: |-
|
|
275
|
+
The attribute is refused whatever its value and the fix removes it. A table is flat, with no frame or card of its own, under the `Section` that titles it.
|
|
267
276
|
- id: NO-RAW-SCROLL
|
|
268
277
|
title: Grammar never shows scrollbars
|
|
269
278
|
governs: Scroll areas an app draws.
|
|
@@ -1,90 +0,0 @@
|
|
|
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; aligned 0.37.8 and 0.43.0): a card groups two or more different parts or carries zones. A card of
|
|
6
|
-
* key-value or choice rows (`kind="table"`, `kind="select"`, `kind="details"`, a `ListBox`, `DisclosureList`, a `DescriptionList`) is valid, alone or not. What is
|
|
7
|
-
* wrong is a card wrapping ONE leaf that stands on its own: a `DataTable` (standalone it draws its own frame), a chart, or a `Section kind="list"` (a list is flat
|
|
8
|
-
* and never a card, LIST-ONE-LOOK). The title sits above it as a `Section` head; a list's own `title` is that head.
|
|
9
|
-
*
|
|
10
|
-
* WHAT IT READS. A Grammar `SurfaceCard` (imported from `@starci/grammar`) with no zones: no `headers` or `footers` prop (an empty array literal counts as none) and no
|
|
11
|
-
* `labelEnd` (head actions). Its body is read through fragments, `cond && <x/>`, `cond ? <x/> : <y/>` and `.map`, ignoring blank text. It is refused when that body is ONE
|
|
12
|
-
* element and that element is a `DataTable`, a chart (`BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`) or a `Section kind="list"`.
|
|
13
|
-
*
|
|
14
|
-
* DECIDED. Key-value and choice rows are never refused here. `Meter`, `Progress` and `ProgressCircle` are single values, not charts. `SurfaceCard kind="figures"`, `details`,
|
|
15
|
-
* `accordion`, `table`, `select` and `tile` are not judged; `SurfaceCard kind="list"` is `surface-card-list`. Kinds, depth and nesting stay with `surface-card-kind`, `no-raised-surface-in-surface` and `surface-depth`.
|
|
16
|
-
*
|
|
17
|
-
* 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 non-Grammar `SurfaceCard`, and non-product source.
|
|
18
|
-
*
|
|
19
|
-
* WHERE IT APPLIES. Product source (`isProductSource`).
|
|
20
|
-
*/
|
|
21
|
-
/** The table, list and chart components that are a surface on their own, with the word the message names them by. */
|
|
22
|
-
const LONE = new Map([
|
|
23
|
-
["DataTable", "table"],
|
|
24
|
-
["BarChart", "chart"],
|
|
25
|
-
["ProportionBar", "chart"],
|
|
26
|
-
["BubbleMap", "chart"],
|
|
27
|
-
["FlowGraph", "chart"],
|
|
28
|
-
["MermaidDiagram", "chart"],
|
|
29
|
-
]);
|
|
30
|
-
/** True when an attribute is an empty array literal (`headers={[]}`), which zones nothing. */
|
|
31
|
-
const isEmptyArray = (attribute) => {
|
|
32
|
-
const value = attribute.value;
|
|
33
|
-
return value?.type === "JSXExpressionContainer" && value.expression.type === "ArrayExpression" && value.expression.elements.length === 0;
|
|
34
|
-
};
|
|
35
|
-
/** True when the card carries a zone or head actions: a `headers` or `footers` prop that is not an empty array, or a `labelEnd`. */
|
|
36
|
-
const hasZones = (opening) => {
|
|
37
|
-
const zoned = ["headers", "footers"].some((name) => {
|
|
38
|
-
const attribute = attributeOf(opening, name);
|
|
39
|
-
return attribute !== undefined && !isEmptyArray(attribute);
|
|
40
|
-
});
|
|
41
|
-
return zoned || attributeOf(opening, "labelEnd") !== undefined;
|
|
42
|
-
};
|
|
43
|
-
/** 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. */
|
|
44
|
-
const loneChild = (context, card) => {
|
|
45
|
-
const body = renderedChildren(card.children);
|
|
46
|
-
if (body.length !== 1)
|
|
47
|
-
return null;
|
|
48
|
-
const child = body[0];
|
|
49
|
-
if (child?.type !== "JSXElement")
|
|
50
|
-
return null;
|
|
51
|
-
const name = elementNameOf(child);
|
|
52
|
-
if (name === null || grammarName(context, child.openingElement) === null)
|
|
53
|
-
return null;
|
|
54
|
-
if (name === "Section" && stringProp(child.openingElement, "kind") === "list")
|
|
55
|
-
return "Section kind=\"list\"";
|
|
56
|
-
return LONE.has(name) ? name : null;
|
|
57
|
-
};
|
|
58
|
-
/** A table component, a chart or a list standing alone is the surface, never wrapped in a card. */
|
|
59
|
-
export const singleChildCard = defineRule({
|
|
60
|
-
meta: {
|
|
61
|
-
type: "problem",
|
|
62
|
-
docs: { description: "SINGLE-CHILD-CARD: a SurfaceCard with no zones whose only content is a DataTable, a chart or a Section kind=\"list\" is a second frame; a card of key-value or choice rows is valid." },
|
|
63
|
-
schema: [],
|
|
64
|
-
messages: {
|
|
65
|
-
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 list is a flat `Section kind=\"list\"` that titles itself. A card groups two or more different parts, or carries zones (tabs, search, head actions); a card of key-value or choice rows (`kind=\"details\"`, `\"select\"`, `\"table\"`) is valid.",
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
create(context) {
|
|
69
|
-
if (!isProductSource(context))
|
|
70
|
-
return {};
|
|
71
|
-
return {
|
|
72
|
-
JSXElement(element) {
|
|
73
|
-
const opening = element.openingElement;
|
|
74
|
-
if (grammarName(context, opening) !== "SurfaceCard" || hasSpread(opening) || hasZones(opening))
|
|
75
|
-
return;
|
|
76
|
-
const child = loneChild(context, element);
|
|
77
|
-
if (child === null)
|
|
78
|
-
return;
|
|
79
|
-
context.report({ node: opening, messageId: "lone", data: { child: `\`${child}\`` } });
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
/** The rules this law contributes to the plugin. */
|
|
85
|
-
export const rules = {
|
|
86
|
-
"single-child-card": singleChildCard,
|
|
87
|
-
};
|
|
88
|
-
defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#SINGLE-CHILD-CARD");
|
|
89
|
-
/** Every rule of this law is an error. */
|
|
90
|
-
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# A lone DataTable, chart or list is the surface, never a card
|
|
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 card of key-value or choice rows (`kind="table"`, `kind="select"`, `kind="details"`, a `ListBox`, `DisclosureList`, `Timeline`, a `DescriptionList`) is valid alone or not (0.37.8). A standalone `DataTable` (`surface="card"`) or chart IS the surface: its title sits above it as a `Section` head and one line under it as `Section caption`, so a card around it is a second card. A list is a flat `Section kind="list"` that titles itself (0.43.0, LIST-ONE-LOOK), so a card around a lone list is refused the same way.
|
|
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 its only body child (looked through fragments, `cond && x`, `cond ? x : y` and `.map`; blank text ignored) is:
|
|
12
|
-
|
|
13
|
-
- table: `DataTable`
|
|
14
|
-
- chart: `BarChart`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
|
|
15
|
-
- list: `Section kind="list"`
|
|
16
|
-
|
|
17
|
-
Not flagged: any key-value or choice card (`kind="table"`, `kind="select"`, `ListBox`, `DisclosureList`, `Timeline`, `DescriptionList`), 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` and `Progress` are single values, not charts.
|
|
18
|
-
|
|
19
|
-
**Invalid**
|
|
20
|
-
|
|
21
|
-
```tsx
|
|
22
|
-
<SurfaceCard label="Runs"><DataTable columns={columns} rows={runs} /></SurfaceCard>
|
|
23
|
-
<SurfaceCard label="Usage"><BarChart data={usage} /></SurfaceCard>
|
|
24
|
-
<SurfaceCard label="Runs"><Section kind="list" ariaLabel="Runs" items={runs} empty={null} /></SurfaceCard>
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
**Valid**
|
|
28
|
-
|
|
29
|
-
```tsx
|
|
30
|
-
<Section title="Runs" caption="Last 30 days"><DataTable columns={columns} rows={runs} /></Section>
|
|
31
|
-
<Section kind="list" title="Runs" items={runs} empty={null} />
|
|
32
|
-
<SurfaceCard label="Runs"><ListBox items={runs} /></SurfaceCard>
|
|
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).
|