@starci/eslint-grammar-core 0.60.0 → 0.64.1
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 +20 -0
- package/dist/index.js +2 -0
- package/dist/lib/why.js +5 -0
- package/dist/type-nesting.d.ts +23 -0
- package/dist/type-nesting.js +99 -0
- package/docs/type-nesting.md +43 -0
- package/package.json +3 -3
- package/runtime/knowledge/ui/presentation/grammar-laws.yaml +15 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
Versioned history starts at beta; earlier history is in git.
|
|
4
4
|
|
|
5
|
+
## 0.64.1 - 2026-11-28
|
|
6
|
+
|
|
7
|
+
- Added (owner 2026-11-28 "phông chữ label lúc nhỏ lúc to"): `starci-grammar/type-nesting` (`FE_TYPE_NESTING`, law TYPE-NESTING), at error. It refuses a `Text` with a literal `reading.body`, `reading.title` or `lead` role inside a `Section`, `SurfaceCard`, `Accordion` or `Disclosure` (the reading sizes are the page's own narration), and a headed block whose literal `headingLevel` is not deeper than the block around it. The static half of DNA-COMMON-TYPE-NESTED-NOT-LARGER and DNA-COMMON-TYPE-LEAD-PAGE-ONLY; docs `docs/type-nesting.md`.
|
|
8
|
+
|
|
9
|
+
## 0.64.0 - 2026-11-26
|
|
10
|
+
|
|
11
|
+
- Versioned with @starci/grammar 0.64 (h-grammar-flowgraph-midpoint): the family minor moved with the FlowGraph spine layout (a centred spine, midpoint ports, edge kinds, merge points and bars, the step drawer); no rule changed.
|
|
12
|
+
|
|
13
|
+
## 0.63.0 - 2026-11-26
|
|
14
|
+
|
|
15
|
+
- Versioned with @starci/grammar 0.63 (h-grammar-graph-v2): the family minor moved with the MermaidDiagram graph v2 (brand-coloured logo chips, ports, the edit mark, calls and data, hover focus); no rule changed.
|
|
16
|
+
|
|
17
|
+
## 0.62.0 - 2026-11-26
|
|
18
|
+
|
|
19
|
+
- Versioned with @starci/grammar 0.62 (h-grammar-board-touch): the family minor moved with the Board drag and drop on react-aria (touch, keyboard and screen reader); no rule changed.
|
|
20
|
+
|
|
21
|
+
## 0.61.0 - 2026-11-26
|
|
22
|
+
|
|
23
|
+
- Versioned with @starci/grammar 0.61 (h-grammar-chat-avatars): the family minor moved with the chat card, the avatar cluster and the channel badge; no rule changed.
|
|
24
|
+
|
|
5
25
|
## 0.60.0 - 2026-11-26
|
|
6
26
|
|
|
7
27
|
- Versioned with @starci/grammar 0.60 (h-ci-red-1126): the family minor moved with the Grammar's board and form surfaces; no rule changed.
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ import { rules as sameLineSizeRules } from "./same-line-size.js";
|
|
|
35
35
|
import { rules as surfaceCardRules } from "./surface-card.js";
|
|
36
36
|
import { rules as surfaceDepthRules } from "./surface-depth.js";
|
|
37
37
|
import { rules as surfaceInSurfaceRules } from "./surface-in-surface.js";
|
|
38
|
+
import { rules as typeNestingRules } from "./type-nesting.js";
|
|
38
39
|
import { rules as tabsRules } from "./tabs.js";
|
|
39
40
|
import { rules as tableCellTypeRules } from "./table-cell-type.js";
|
|
40
41
|
import { rules as textRules } from "./text-rules.js";
|
|
@@ -93,6 +94,7 @@ const DECLARED = [
|
|
|
93
94
|
{ law: "tabs", rules: tabsRules },
|
|
94
95
|
{ law: "table-cell-type", rules: tableCellTypeRules },
|
|
95
96
|
{ law: "text-rules", rules: textRules },
|
|
97
|
+
{ law: "type-nesting", rules: typeNestingRules },
|
|
96
98
|
{ law: "tokens", rules: tokensRules },
|
|
97
99
|
{ law: "vendor-boundary", rules: vendorRules },
|
|
98
100
|
];
|
package/dist/lib/why.js
CHANGED
|
@@ -204,6 +204,11 @@ export const why = {
|
|
|
204
204
|
en: "`<file>` sets a type size of its own: a Tailwind text-size utility (`text-sm`, `text-[13px]`), a `fontSize` or a CSS `font-size`.",
|
|
205
205
|
fix: "Type is a Grammar role: use `<Text role=\"label.item\">` or the class of the role, `starci-type-<role>` with dots as dashes (`starci-type-label-item`). The roles: figure, title.page, title.section, label.item, body, label.field, label.group, caption, badge, code; on the public site also display.hero, display.section, display.figure, lead and title.card.",
|
|
206
206
|
},
|
|
207
|
+
"type-nesting": {
|
|
208
|
+
code: "FE_TYPE_NESTING",
|
|
209
|
+
en: "`<file>` draws a reading or lead role (`reading.body`, `reading.title`, `lead`) inside a Section, SurfaceCard, Accordion or Disclosure, or a block that heads no deeper than the block around it.",
|
|
210
|
+
fix: "Inside a block the copy is `body` (a `Text` with no role); keep the reading roles for narration standing directly on the page. A block inside another heads one level deeper (`headingLevel` of the outer block plus one).",
|
|
211
|
+
},
|
|
207
212
|
"site-type-role": {
|
|
208
213
|
code: "FE_SITE_TYPE_ROLE",
|
|
209
214
|
en: "`<file>` is not the public site, and it draws a role of the site group: `display.hero`, `display.section`, `display.figure`, `lead` or `title.card` (`<Text role>` or `starci-type-<role>`).",
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
/**
|
|
3
|
+
* THE TYPE NESTING LAW (TYPE-NESTING, contexts/ui/presentation.md "Nesting and siblings"; DNA-COMMON-TYPE-NESTED-NOT-LARGER and
|
|
4
|
+
* DNA-COMMON-TYPE-LEAD-PAGE-ONLY). Type steps down, or stays equal, as blocks nest: text inside a block is never larger than the
|
|
5
|
+
* block's own heading, and the reading and lead sizes are the page's own narration, never a nested block's.
|
|
6
|
+
*
|
|
7
|
+
* WHAT IT READS, in product source, the part a file states statically:
|
|
8
|
+
* - `lead`: a Grammar `Text` with a literal `role` of `reading.body`, `reading.title` or `lead` inside a Grammar block that owns a
|
|
9
|
+
* heading (`Section`, `SurfaceCard`, `Accordion`, `Disclosure`), at any JSX depth, a prop's JSX (`content={…}`) included;
|
|
10
|
+
* - `level`: a `Section`, `SurfaceCard`, `Accordion` or `Disclosure` with a literal `headingLevel` that is not deeper than the
|
|
11
|
+
* literal `headingLevel` of the nearest such block around it in the same file (a sub-block heads one level deeper).
|
|
12
|
+
*
|
|
13
|
+
* A computed role or level is not judged. What the source cannot show (a block another file renders around this one, a sibling's
|
|
14
|
+
* drawn size) is measured on the live page by the lesson type probe and the DNA laws.
|
|
15
|
+
*/
|
|
16
|
+
/** The roles of long reading and of the site's lead line: larger than body, the page's own narration only. */
|
|
17
|
+
export declare const READING_ROLES: readonly string[];
|
|
18
|
+
/** The Grammar blocks that own a heading, and so a type rank their content must not exceed. */
|
|
19
|
+
export declare const HEADED_BLOCKS: ReadonlySet<string>;
|
|
20
|
+
/** Text inside a block never outranks the block's heading; a sub-block heads one level deeper. */
|
|
21
|
+
export declare const typeNesting: Rule.RuleModule;
|
|
22
|
+
/** The rules this law contributes to the plugin. */
|
|
23
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
@@ -0,0 +1,99 @@
|
|
|
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
|
+
* THE TYPE NESTING LAW (TYPE-NESTING, contexts/ui/presentation.md "Nesting and siblings"; DNA-COMMON-TYPE-NESTED-NOT-LARGER and
|
|
6
|
+
* DNA-COMMON-TYPE-LEAD-PAGE-ONLY). Type steps down, or stays equal, as blocks nest: text inside a block is never larger than the
|
|
7
|
+
* block's own heading, and the reading and lead sizes are the page's own narration, never a nested block's.
|
|
8
|
+
*
|
|
9
|
+
* WHAT IT READS, in product source, the part a file states statically:
|
|
10
|
+
* - `lead`: a Grammar `Text` with a literal `role` of `reading.body`, `reading.title` or `lead` inside a Grammar block that owns a
|
|
11
|
+
* heading (`Section`, `SurfaceCard`, `Accordion`, `Disclosure`), at any JSX depth, a prop's JSX (`content={…}`) included;
|
|
12
|
+
* - `level`: a `Section`, `SurfaceCard`, `Accordion` or `Disclosure` with a literal `headingLevel` that is not deeper than the
|
|
13
|
+
* literal `headingLevel` of the nearest such block around it in the same file (a sub-block heads one level deeper).
|
|
14
|
+
*
|
|
15
|
+
* A computed role or level is not judged. What the source cannot show (a block another file renders around this one, a sibling's
|
|
16
|
+
* drawn size) is measured on the live page by the lesson type probe and the DNA laws.
|
|
17
|
+
*/
|
|
18
|
+
/** The roles of long reading and of the site's lead line: larger than body, the page's own narration only. */
|
|
19
|
+
export const READING_ROLES = Object.freeze(["reading.body", "reading.title", "lead"]);
|
|
20
|
+
/** The Grammar blocks that own a heading, and so a type rank their content must not exceed. */
|
|
21
|
+
export const HEADED_BLOCKS = new Set(["Section", "SurfaceCard", "Accordion", "Disclosure"]);
|
|
22
|
+
/** A literal string or number of an attribute (`role="x"`, `headingLevel={3}`), or null when absent or computed. */
|
|
23
|
+
const literalOf = (attribute) => {
|
|
24
|
+
const value = attribute?.value;
|
|
25
|
+
if (value === undefined || value === null)
|
|
26
|
+
return null;
|
|
27
|
+
if (value.type === "Literal" && (typeof value.value === "string" || typeof value.value === "number"))
|
|
28
|
+
return value.value;
|
|
29
|
+
if (value.type === "JSXExpressionContainer" && value.expression.type === "Literal") {
|
|
30
|
+
const literal = value.expression.value;
|
|
31
|
+
return typeof literal === "string" || typeof literal === "number" ? literal : null;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
/** The headed Grammar blocks around a node, nearest first. */
|
|
36
|
+
const enclosingBlocks = (context, node) => {
|
|
37
|
+
const found = [];
|
|
38
|
+
for (let at = node.parent; at !== undefined && at !== null; at = at.parent) {
|
|
39
|
+
if (at.type !== "JSXElement" || at.openingElement === node)
|
|
40
|
+
continue;
|
|
41
|
+
const name = grammarName(context, at.openingElement);
|
|
42
|
+
if (name !== null && HEADED_BLOCKS.has(name))
|
|
43
|
+
found.push(at.openingElement);
|
|
44
|
+
}
|
|
45
|
+
return found;
|
|
46
|
+
};
|
|
47
|
+
/** Text inside a block never outranks the block's heading; a sub-block heads one level deeper. */
|
|
48
|
+
export const typeNesting = defineRule({
|
|
49
|
+
meta: {
|
|
50
|
+
type: "problem",
|
|
51
|
+
docs: { description: "TYPE-NESTING: the reading and lead roles stand at page level only; a nested block heads one level deeper than the block around it." },
|
|
52
|
+
schema: [],
|
|
53
|
+
messages: {
|
|
54
|
+
lead: "`role=\"{{role}}\"` inside a `{{block}}`: the reading and lead sizes are the page's own narration, and inside a block they draw larger than the block's heading. Use `body` (no role) here; keep `{{role}}` for narration that stands directly on the page.",
|
|
55
|
+
level: "This `{{block}}` heads at level {{level}} inside a `{{outer}}` at level {{outerLevel}}: a block inside another heads one level deeper (`headingLevel={{deeper}}`), so the outline and the type step down together.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
create(context) {
|
|
59
|
+
if (!isProductSource(context))
|
|
60
|
+
return {};
|
|
61
|
+
return {
|
|
62
|
+
JSXOpeningElement(node) {
|
|
63
|
+
const name = grammarName(context, node);
|
|
64
|
+
if (name === null)
|
|
65
|
+
return;
|
|
66
|
+
if (name === "Text") {
|
|
67
|
+
const role = literalOf(attributeOf(node, "role"));
|
|
68
|
+
if (typeof role !== "string" || !READING_ROLES.includes(role))
|
|
69
|
+
return;
|
|
70
|
+
const [nearest] = enclosingBlocks(context, node);
|
|
71
|
+
if (nearest !== undefined)
|
|
72
|
+
context.report({ node: node, messageId: "lead", data: { role, block: grammarName(context, nearest) ?? "block" } });
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (!HEADED_BLOCKS.has(name))
|
|
76
|
+
return;
|
|
77
|
+
const level = literalOf(attributeOf(node, "headingLevel"));
|
|
78
|
+
if (typeof level !== "number")
|
|
79
|
+
return;
|
|
80
|
+
const outer = enclosingBlocks(context, node).find((block) => typeof literalOf(attributeOf(block, "headingLevel")) === "number");
|
|
81
|
+
if (outer === undefined)
|
|
82
|
+
return;
|
|
83
|
+
const outerLevel = literalOf(attributeOf(outer, "headingLevel"));
|
|
84
|
+
if (level > outerLevel)
|
|
85
|
+
return;
|
|
86
|
+
context.report({
|
|
87
|
+
node: node,
|
|
88
|
+
messageId: "level",
|
|
89
|
+
data: { block: name, level: String(level), outer: grammarName(context, outer) ?? "block", outerLevel: String(outerLevel), deeper: String(outerLevel + 1) },
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
/** The rules this law contributes to the plugin. */
|
|
96
|
+
export const rules = {
|
|
97
|
+
"type-nesting": typeNesting,
|
|
98
|
+
};
|
|
99
|
+
defineFamilyRules(rules, "knowledge/ui/presentation/grammar-laws.yaml#TYPE-NESTING");
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# Type nesting
|
|
2
|
+
|
|
3
|
+
Law module: `type-nesting.ts`. Finding code: `FE_TYPE_NESTING`. Knowledge: `runtime/knowledge/ui/presentation/grammar-laws.yaml#TYPE-NESTING`.
|
|
4
|
+
|
|
5
|
+
Type steps down, or stays equal, as blocks nest ([presentation](../../../contexts/ui/presentation.md) "Nesting and siblings"): text inside a
|
|
6
|
+
block is never larger than the block's own heading, blocks of one level share their type, and the reading and lead sizes are the page's
|
|
7
|
+
own narration (DNA-COMMON-TYPE-NESTED-NOT-LARGER, DNA-COMMON-TYPE-SIBLINGS-SAME, DNA-COMMON-TYPE-LEAD-PAGE-ONLY).
|
|
8
|
+
|
|
9
|
+
## `starci-grammar/type-nesting`
|
|
10
|
+
|
|
11
|
+
In product source it reports what the file states statically:
|
|
12
|
+
|
|
13
|
+
- `lead`: a `Text` with a literal `role` of `reading.body`, `reading.title` or `lead` inside a `Section`, `SurfaceCard`, `Accordion` or
|
|
14
|
+
`Disclosure`, at any JSX depth, JSX passed through a prop included;
|
|
15
|
+
- `level`: a `Section`, `SurfaceCard`, `Accordion` or `Disclosure` with a literal `headingLevel` not deeper than the literal
|
|
16
|
+
`headingLevel` of the nearest such block around it.
|
|
17
|
+
|
|
18
|
+
A computed role or level is not judged, and a block another file renders around this one is not seen: the live page is measured by
|
|
19
|
+
the DNA laws and, for lesson pages, by the app's lesson type probe.
|
|
20
|
+
|
|
21
|
+
**Invalid**
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
<Section title="Vì sao không dùng một transaction" headingLevel={2}>
|
|
25
|
+
<Text as="p" role="reading.body">{why}</Text>
|
|
26
|
+
</Section>
|
|
27
|
+
<Section title="Repo tặng bạn" headingLevel={2}>
|
|
28
|
+
<SurfaceCard label="Bản chuẩn StarCi" headingLevel={2} />
|
|
29
|
+
</Section>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Valid**
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<Stack gap="region">
|
|
36
|
+
<Text as="p" role="reading.body">{narration}</Text>
|
|
37
|
+
<Section title="Repo tặng bạn" headingLevel={2}>
|
|
38
|
+
<SurfaceCard label="Bản chuẩn StarCi" headingLevel={3}>
|
|
39
|
+
<Text as="p">{note}</Text>
|
|
40
|
+
</SurfaceCard>
|
|
41
|
+
</Section>
|
|
42
|
+
</Stack>
|
|
43
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-grammar-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.64.1",
|
|
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": "ce6b8ee161d84eb14ceabbc30b95aef0f0f1c5e1",
|
|
72
|
+
"starciSource": "66e9625e9f7cb1fd89fd7e8b225699ae45ae92fa9040beaa35492dae0a14054d"
|
|
73
73
|
}
|
|
@@ -299,6 +299,21 @@ rules:
|
|
|
299
299
|
title.section, label.item, body, label.field, label.group, caption, badge, code; dots as dashes in the class). A Tailwind
|
|
300
300
|
text-size utility, a `fontSize` or a CSS `font-size` in app source is reported (`starci-grammar/no-raw-type-size`, a
|
|
301
301
|
counting rule at warn until both apps migrate, then blocking).
|
|
302
|
+
- id: TYPE-NESTING
|
|
303
|
+
title: Type steps down as blocks nest
|
|
304
|
+
governs: The type role of copy inside a Section, a SurfaceCard, an Accordion or a Disclosure, and the heading level of a block inside another.
|
|
305
|
+
cases:
|
|
306
|
+
- id: case-1
|
|
307
|
+
when: A Text inside a headed block takes a reading or lead role
|
|
308
|
+
assert: |-
|
|
309
|
+
`reading.body`, `reading.title` and `lead` are the page's own narration and stand directly on the page; inside a
|
|
310
|
+
Section, SurfaceCard, Accordion or Disclosure the copy is `body`, so nothing in a block draws larger than its heading
|
|
311
|
+
(DNA-COMMON-TYPE-NESTED-NOT-LARGER, DNA-COMMON-TYPE-LEAD-PAGE-ONLY). Refused by `starci-grammar/type-nesting`.
|
|
312
|
+
- id: case-2
|
|
313
|
+
when: A headed block stands inside another headed block
|
|
314
|
+
assert: |-
|
|
315
|
+
Its literal `headingLevel` is deeper than the enclosing block's, so the outline and the type step down together.
|
|
316
|
+
Refused by `starci-grammar/type-nesting` when both levels are literal.
|
|
302
317
|
- id: SITE-TYPE-ROLES
|
|
303
318
|
title: The site group is the public site's
|
|
304
319
|
governs: Where the five site type roles are drawn.
|