@starci/eslint-grammar-core 0.52.2 → 0.54.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 (59) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +8 -14
  3. package/dist/app-shell.d.ts +0 -11
  4. package/dist/app-shell.js +2 -190
  5. package/dist/button-arrow.d.ts +0 -7
  6. package/dist/button-arrow.js +1 -50
  7. package/dist/index.d.ts +13 -3
  8. package/dist/index.js +18 -19
  9. package/dist/lib/app-shell-scope.d.ts +0 -2
  10. package/dist/lib/app-shell-scope.js +0 -19
  11. package/dist/lib/app-shell.d.ts +0 -4
  12. package/dist/lib/app-shell.js +0 -25
  13. package/dist/lib/cross-file-inputs.js +2 -3
  14. package/dist/lib/why.js +5 -65
  15. package/dist/mascot.d.ts +0 -21
  16. package/dist/mascot.js +4 -69
  17. package/dist/no-raw-type-size.d.ts +27 -0
  18. package/dist/no-raw-type-size.js +107 -0
  19. package/dist/same-line-size.js +9 -0
  20. package/dist/table-cell-type.js +4 -0
  21. package/docs/app-shell.md +1 -37
  22. package/docs/button-arrow.md +1 -26
  23. package/docs/mascot.md +6 -34
  24. package/docs/no-raw-type-size.md +35 -0
  25. package/docs/rows-in-card.md +1 -1
  26. package/package.json +3 -3
  27. package/runtime/knowledge/patterns/fe/ui.yaml +0 -7
  28. package/runtime/knowledge/ui/composition/app-shell.yaml +4 -4
  29. package/runtime/knowledge/ui/presentation/grammar-laws.yaml +11 -0
  30. package/runtime/modules/goal/source-phrases.yaml +0 -4
  31. package/dist/chip-label.d.ts +0 -14
  32. package/dist/chip-label.js +0 -117
  33. package/dist/data-table-surface.d.ts +0 -18
  34. package/dist/data-table-surface.js +0 -57
  35. package/dist/lib/app-shell-cluster.d.ts +0 -6
  36. package/dist/lib/app-shell-cluster.js +0 -75
  37. package/dist/lib/app-shell-create.d.ts +0 -5
  38. package/dist/lib/app-shell-create.js +0 -37
  39. package/dist/lib/app-shell-owner.d.ts +0 -7
  40. package/dist/lib/app-shell-owner.js +0 -97
  41. package/dist/lib/status-tones.generated.d.ts +0 -2
  42. package/dist/lib/status-tones.generated.js +0 -8
  43. package/dist/message-surfaces.d.ts +0 -6
  44. package/dist/message-surfaces.js +0 -158
  45. package/dist/status-colors.d.ts +0 -19
  46. package/dist/status-colors.js +0 -217
  47. package/dist/suggestion-buttons.d.ts +0 -6
  48. package/dist/suggestion-buttons.js +0 -181
  49. package/dist/surface-card-list.d.ts +0 -20
  50. package/dist/surface-card-list.js +0 -47
  51. package/dist/tab-count-chip.d.ts +0 -7
  52. package/dist/tab-count-chip.js +0 -65
  53. package/docs/chip-label.md +0 -30
  54. package/docs/data-table-surface.md +0 -27
  55. package/docs/message-surfaces.md +0 -37
  56. package/docs/status-colors.md +0 -43
  57. package/docs/suggestion-buttons.md +0 -34
  58. package/docs/surface-card-list.md +0 -33
  59. package/docs/tab-count-chip.md +0 -26
@@ -0,0 +1,35 @@
1
+ # No raw type size
2
+
3
+ Law module: `no-raw-type-size.ts`. Finding code: `FE_RAW_TYPE_SIZE`. Knowledge: `runtime/knowledge/ui/presentation/grammar-laws.yaml#TYPE-ROLES`.
4
+
5
+ Type is a Grammar role (owner, 2026-11-21). An app draws text with `<Text role="label.item">`, or puts the public class of a role (`starci-type-label-item`, dots as dashes) on an element of its own. The ten roles are figure, title.page, title.section, label.item, body, label.field, label.group, caption, badge and code ([presentation](../../../contexts/ui/presentation.md) "The type roles").
6
+
7
+ ## `starci-grammar/no-raw-type-size`
8
+
9
+ In product source it reports:
10
+
11
+ - a Tailwind text-size utility in a class string: `text-xs`, `text-sm`, `text-base`, `text-lg`, `text-xl`, `text-2xl` and larger, or an arbitrary length (`text-[13px]`), with any variant prefix or `/leading` suffix;
12
+ - a `fontSize` key of an object (a JSX `style`, a style constant, a chart option) and a `fontSize` JSX attribute;
13
+ - a CSS `font-size` declaration written in a string or a template literal.
14
+
15
+ It leaves alone colour utilities (`text-muted`), the role classes, the app's theme layer (`modules/brand/`, the tokens), Grammar's own sources, and Freestyle and Fragment regions. App stylesheets are judged by the CSS canon: `starci/token-only` refuses a `font-size` that is not a token, and `starci/no-grammar-private-token` refuses the Grammar's type tokens.
16
+
17
+ **Invalid**
18
+
19
+ ```tsx
20
+ <span className="text-sm font-medium">{name}</span>
21
+ <div style={{ fontSize: 12 }}>{note}</div>
22
+ ```
23
+
24
+ **Valid**
25
+
26
+ ```tsx
27
+ <Text role="label.item">{name}</Text>
28
+ <span className="starci-type-caption">{note}</span>
29
+ ```
30
+
31
+ ## Warning now, blocking later
32
+
33
+ The rule is the family's counting cohort (`COUNTING` in `src/index.ts`): `coreGrammarConfig` runs it at `warn`, and `starci app check --gate lint` reports and counts its findings without failing. **The switch:** when both apps have migrated, delete its entry from `COUNTING` (a Grammar family minor). The rule then runs at error like every other family rule. An app has no override, because its `eslint.config.mjs` is the managed one-liner (R17).
34
+
35
+ Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
@@ -2,7 +2,7 @@
2
2
 
3
3
  Law module: `rows-in-card.ts`. Finding code: `FE_ROWS_IN_CARD`. Knowledge: `knowledge/ui/presentation/grammar-laws.yaml#ROWS-IN-CARD`.
4
4
 
5
- Key-value rows (`DescriptionList`) and disclosure rows (`DisclosureList`) stand in a `Section` (the facts or the disclosures of a collection, flat on the surface: `<Section title ...><DescriptionList isDivided items={...} /></Section>`) or in the body of an object card (the facts of ONE object beside its name or a control). A plain list of rows is a flat `Section kind="list"` (LIST-ONE-LOOK, `surface-card-list`). A card whose only content is the rows is `card-is-object`.
5
+ Key-value rows (`DescriptionList`) and disclosure rows (`DisclosureList`) stand in a `Section` (the facts or the disclosures of a collection, flat on the surface: `<Section title ...><DescriptionList isDivided items={...} /></Section>`) or in the body of an object card (the facts of ONE object beside its name or a control). A plain list of rows is a flat `Section kind="list"` (LIST-ONE-LOOK). A card whose only content is the rows is `card-is-object`.
6
6
 
7
7
  Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-grammar-core",
3
- "version": "0.52.2",
3
+ "version": "0.54.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": "959a9f9ffbc9ec9de65c9c3bbafe6dbc355cc4ba",
72
- "starciSource": "43f4f5cc69bed8c8ddf956e6df347d318488bdfa8be934d33c6662bea45ae509"
71
+ "gitHead": "212690ec1f9f79a8e6188f449d02684871f5a45b",
72
+ "starciSource": "07180fd6f1e5f5d03589df302253a6380501ee713171b261bcc2b30f82d568e7"
73
73
  }
@@ -73,22 +73,15 @@ rules:
73
73
  - ARCH_GRAMMAR_CONTRACT_INVALID
74
74
  - ARCH_GRAMMAR_EXPORT_BYPASS
75
75
  - FE_STACK_FORBIDDEN
76
- - FE_APP_SHELL_FRAME
77
76
  - FE_NAVBAR_CONTROL_SIZE
78
- - FE_NAVBAR_CLUSTER
79
- - FE_APP_SHELL_BOTTOM_TABS
80
- - FE_NAVBAR_CREATE
81
77
  - FE_NESTED_VARIANT
82
- - FE_LIST_PANEL_PADDING
83
78
  - FE_GRAMMAR_LAYOUT_ONLY
84
- - FE_DIVIDER_FULL_BLEED
85
79
  - FE_BUTTON_INTENT
86
80
  - FE_BUTTON_INTENT_REQUIRED
87
81
  - FE_DESTRUCTIVE_CONFIRM_IN_DIALOG
88
82
  - FE_SINGLE_COMMIT_PER_RENDER
89
83
  - FE_NO_COMMIT_IN_COLLECTION_ITEM
90
84
  - FE_CONTROL_HEIGHT
91
- - FE_GENERATED_ART_OUTSIDE_FRAME
92
85
  - FE_MASCOT_ASSET_SLOT_MISSING
93
86
  - FE_RAW_MEDIA_ELEMENT
94
87
  - FE_RAISED_SURFACE_IN_SURFACE
@@ -41,7 +41,7 @@ rules:
41
41
  The navbar remains at the top of the frame, reads as a continuous surface and has one
42
42
  full-width separator from the content beneath it. The design system supplies its band height.
43
43
  verification:
44
- automated: [FE_APP_SHELL_FRAME]
44
+ automated: []
45
45
  manual: [Inspect fixed viewport, flush regions and independent scroll at desktop and mobile widths.]
46
46
  - id: FE-APP-SHELL-2
47
47
  title: Navbar controls share one height
@@ -99,7 +99,7 @@ rules:
99
99
  and is an app bar. Every control in a site bar still shares the bar-control height
100
100
  (`size="control"`), so FE-APP-SHELL-2 holds there.
101
101
  verification:
102
- automated: [FE_NAVBAR_CLUSTER, FE_VENDOR_BOUNDARY]
102
+ automated: [FE_VENDOR_BOUNDARY]
103
103
  manual: [Inspect menu anatomy, selection indicators, identity fallback, badges and notification regions.]
104
104
  - id: FE-APP-SHELL-4
105
105
  title: Mobile navigation is a drawer below the navbar
@@ -126,7 +126,7 @@ rules:
126
126
  when: The viewport reaches desktop
127
127
  assert: The mobile subnav is hidden.
128
128
  verification:
129
- automated: [FE_APP_SHELL_FRAME, FE_APP_SHELL_BOTTOM_TABS]
129
+ automated: []
130
130
  manual: [Inspect both widths, drawer dismissal, trapped focus and independent scrolling.]
131
131
  - id: FE-APP-SHELL-5
132
132
  title: Create actions belong on their pages
@@ -137,7 +137,7 @@ rules:
137
137
  assert: |-
138
138
  The create action lives on the page whose content it changes and never in the navbar.
139
139
  verification:
140
- automated: [FE_NAVBAR_CREATE]
140
+ automated: []
141
141
  manual: []
142
142
  - id: FE-APP-SHELL-6
143
143
  title: Collapsed navigation is an icon rail
@@ -273,6 +273,17 @@ rules:
273
273
  when: A DataTable is written with a `surface` attribute
274
274
  assert: |-
275
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.
276
+ - id: TYPE-ROLES
277
+ title: Type is a Grammar role
278
+ governs: Type sizes an app sets.
279
+ cases:
280
+ - id: case-1
281
+ when: An app sets the size of text it draws
282
+ assert: |-
283
+ The size is a type role (owner 2026-11-21): `<Text role>` or the public class `starci-type-<role>` (figure, title.page,
284
+ title.section, label.item, body, label.field, label.group, caption, badge, code; dots as dashes in the class). A Tailwind
285
+ text-size utility, a `fontSize` or a CSS `font-size` in app source is reported (`starci-grammar/no-raw-type-size`, a
286
+ counting rule at warn until both apps migrate, then blocking).
276
287
  - id: NO-RAW-SCROLL
277
288
  title: Grammar never shows scrollbars
278
289
  governs: Scroll areas an app draws.
@@ -15,10 +15,6 @@ schema: starci/module-goal-source-phrases@1
15
15
 
16
16
  phrases:
17
17
 
18
- # packages/eslint/grammar-core/lib/app-shell-create.mjs - localized labels of create actions prohibited in the navbar.
19
- appShell:
20
- product: ['Tạo mới', 'tao moi']
21
-
22
18
  # scripts/agent/bias.mjs extractRoutingBias - the routing markers an owner
23
19
  # prompt types before a pool alias. Regex alternatives; syllables join with \s*.
24
20
  bias:
@@ -1,14 +0,0 @@
1
- import type { Rule } from "eslint";
2
- /** The first character of a trimmed label, and its offset in the raw source text, or null when the label is empty. */
3
- export declare const firstCharacter: (text: string) => {
4
- char: string;
5
- offset: number;
6
- } | null;
7
- /** True when a label's first character is a lowercase letter. */
8
- export declare const startsLowercase: (text: string) => boolean;
9
- /** A chip label (`StatusDot` text, `Badge`) starts with an uppercase letter. */
10
- export declare const chipLabelStartsUppercase: Rule.RuleModule;
11
- /** The rules this law contributes to the plugin. */
12
- export declare const rules: Record<string, Rule.RuleModule>;
13
- /** Every rule of this law is an error. */
14
- export declare const recommended: Record<string, "error">;
@@ -1,117 +0,0 @@
1
- import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
2
- import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
- /**
4
- * The rule that holds the chip label law (HFS R322, `FE_CHIP_LABEL_CASE`): a chip label starts with an uppercase
5
- * letter. A status chip (`StatusDot` with text, a `Badge`, dot or not) is a label read at a glance beside the thing it
6
- * qualifies; "running" beside "Failed" in one table reads as two vocabularies.
7
- *
8
- * WHAT IT READS. The children of a `StatusDot` or `Badge` element that the source states literally: JSX text, a string
9
- * literal or a template literal with no expression in a `{...}`, and every branch of a conditional or logical expression
10
- * made of them. The first character of the trimmed text is judged: a lowercase letter is a finding, and the fix
11
- * uppercases it in place.
12
- *
13
- * WHAT IT LEAVES ALONE: text the source cannot show (a translation call, a variable, a template with an expression), a
14
- * label that starts with a digit or a symbol, and an uncased script.
15
- */
16
- /** The components whose children are a chip label. */
17
- const CHIP_COMPONENTS = new Set(["StatusDot", "Badge"]);
18
- /** The first character of a trimmed label, and its offset in the raw source text, or null when the label is empty. */
19
- export const firstCharacter = (text) => {
20
- const offset = text.search(/\S/u);
21
- if (offset < 0)
22
- return null;
23
- const char = String.fromCodePoint(text.codePointAt(offset) ?? 0);
24
- return { char, offset };
25
- };
26
- /** True when a label's first character is a lowercase letter. */
27
- export const startsLowercase = (text) => {
28
- const first = firstCharacter(text);
29
- return first !== null && /^\p{Ll}$/u.test(first.char);
30
- };
31
- /** The literal text nodes a JSX child carries: `{ node, text, quoteOffset }`, the offset of the text inside the node's source. */
32
- function* literalTexts(node) {
33
- if (!node || typeof node.type !== "string")
34
- return;
35
- switch (node.type) {
36
- case "JSXText":
37
- yield { node, text: node.value, quoteOffset: 0 };
38
- return;
39
- case "JSXExpressionContainer":
40
- yield* literalTexts(node.expression);
41
- return;
42
- case "Literal":
43
- if (typeof node.value === "string")
44
- yield { node, text: node.value, quoteOffset: 1 };
45
- return;
46
- case "TemplateLiteral":
47
- if (node.expressions.length === 0)
48
- yield { node, text: node.quasis[0]?.value.cooked ?? "", quoteOffset: 1 };
49
- return;
50
- case "ConditionalExpression":
51
- yield* literalTexts(node.consequent);
52
- yield* literalTexts(node.alternate);
53
- return;
54
- case "LogicalExpression":
55
- yield* literalTexts(node.right);
56
- return;
57
- default:
58
- }
59
- }
60
- /** The element name of a JSX opening element (`Badge`, or `Grammar.Badge` as `Badge`). */
61
- const elementName = (opening) => {
62
- const name = opening.name;
63
- if (name.type === "JSXIdentifier")
64
- return name.name;
65
- if (name.type === "JSXMemberExpression")
66
- return name.property.name;
67
- return null;
68
- };
69
- /** The first non-blank child of an element: the one that starts the visible label. */
70
- const leadingChild = (children) => children.find((child) => child.type !== "JSXText" || child.value.trim() !== "") ?? null;
71
- /** A chip label (`StatusDot` text, `Badge`) starts with an uppercase letter. */
72
- export const chipLabelStartsUppercase = defineRule({
73
- meta: {
74
- type: "problem",
75
- fixable: "code",
76
- docs: { description: "R322: the label of a StatusDot or Badge chip starts with an uppercase letter." },
77
- schema: [],
78
- messages: {
79
- lowercase: "The {{component}} label `{{text}}` starts with a lowercase letter. A chip label is read at a glance beside the thing it qualifies, and every chip of the app starts uppercase, so one table never mixes `running` with `Failed`. Write `{{fixed}}`.",
80
- },
81
- },
82
- create(context) {
83
- if (!isProductSource(context))
84
- return {};
85
- const source = context.sourceCode;
86
- return {
87
- JSXElement(element) {
88
- const component = elementName(element.openingElement);
89
- if (component === null || !CHIP_COMPONENTS.has(component))
90
- return;
91
- const child = leadingChild(element.children);
92
- for (const { node, text, quoteOffset } of literalTexts(child)) {
93
- const first = firstCharacter(text);
94
- if (!startsLowercase(text) || first === null)
95
- continue;
96
- const trimmed = text.trim();
97
- const fixed = first.char.toLocaleUpperCase() + trimmed.slice(first.char.length);
98
- const raw = source.getText(node);
99
- const at = node.range[0] + quoteOffset + raw.slice(quoteOffset).indexOf(first.char);
100
- context.report({
101
- node,
102
- messageId: "lowercase",
103
- data: { component, text: trimmed, fixed },
104
- fix: (fixer) => fixer.replaceTextRange([at, at + first.char.length], first.char.toLocaleUpperCase()),
105
- });
106
- }
107
- },
108
- };
109
- },
110
- });
111
- /** The rules this law contributes to the plugin. */
112
- export const rules = {
113
- "chip-label-starts-uppercase": chipLabelStartsUppercase,
114
- };
115
- defineFamilyRules(rules, "knowledge/hfs/rules.yaml#R322");
116
- /** Every rule of this law is an error. */
117
- export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -1,18 +0,0 @@
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">;
@@ -1,57 +0,0 @@
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"]));
@@ -1,6 +0,0 @@
1
- import type { ReaderContext, Resolved } from "./types.js";
2
- /** Every reachable branch yields its own sequence; shell headers select the narrowest right-hand group. */
3
- export declare const clusterAlternatives: (context: ReaderContext, expression: Resolved | null | undefined, shellHeader: boolean) => {
4
- alternatives: string[][];
5
- ownsBar: boolean;
6
- };
@@ -1,75 +0,0 @@
1
- import { clusterRole, grammarName, isBarControl, propOf, textProp } from "./app-shell.js";
2
- import { visitVisible } from "./app-shell-visible.js";
3
- /** The disclosure component each cluster role's trigger must sit in. */
4
- const EXPECTED_DISCLOSURE = { language: "DropdownMenu", notifications: "Popover", account: "DropdownMenu" };
5
- const controlsOf = (context, expression, choices, shellHeader = false) => {
6
- const controls = [];
7
- const branches = [];
8
- let ownsBar = false;
9
- visitVisible(context, expression, (opening, name, ancestors) => {
10
- if (shellHeader && name !== null && ["TopBar"].includes(name)) {
11
- ownsBar = true;
12
- return false;
13
- }
14
- if (!isBarControl(context, opening, name))
15
- return;
16
- const role = clusterRole(context, opening, name);
17
- controls.push(controlSignature(context, opening, name, role, ancestors));
18
- return false;
19
- }, new Set(), (node) => {
20
- if (!choices.has(node))
21
- branches.push(node);
22
- return choices.get(node) ?? "consequent";
23
- });
24
- return { controls, branches, ownsBar };
25
- };
26
- const controlSignature = (context, opening, name, role, ancestors) => {
27
- const signature = `${role ?? "unknown"}:${name}`;
28
- const expected = role === null ? undefined : EXPECTED_DISCLOSURE[role];
29
- const disclosure = [...ancestors].reverse().map((ancestor) => grammarName(context, ancestor)).find((parent) => parent === "DropdownMenu" || parent === "Popover");
30
- if (expected && disclosure !== expected)
31
- return `${signature}:wrong-disclosure`;
32
- if (role === "language") {
33
- const variant = propOf(context, opening, "variant");
34
- if (!variant.known || variant.value !== null && textProp(context, opening, "variant") !== "tertiary")
35
- return `${signature}:wrong-variant`;
36
- }
37
- return signature;
38
- };
39
- const rightGroup = (context, expression, choices) => {
40
- let group = null;
41
- let count = Number.POSITIVE_INFINITY;
42
- const roles = controlsOf(context, expression, choices).controls.filter((role) => !role.startsWith("unknown:"));
43
- visitVisible(context, expression, (opening, name) => {
44
- if (isBarControl(context, opening, name))
45
- return false;
46
- const result = controlsOf(context, opening.parent, choices);
47
- const known = result.controls.filter((role) => !role.startsWith("unknown:"));
48
- if (roles.length > 0 && known.length === roles.length && roles.every((role) => known.includes(role)) && result.controls.length < count) {
49
- group = opening.parent;
50
- count = result.controls.length;
51
- }
52
- return undefined;
53
- }, new Set(), (node) => choices.get(node) ?? "consequent");
54
- return group ?? expression;
55
- };
56
- /** Every reachable branch yields its own sequence; shell headers select the narrowest right-hand group. */
57
- export const clusterAlternatives = (context, expression, shellHeader) => {
58
- const pending = [new Map()];
59
- const alternatives = [];
60
- for (let choices = pending.pop(); choices; choices = pending.pop()) {
61
- const initial = controlsOf(context, expression, choices, shellHeader);
62
- if (initial.ownsBar)
63
- return { alternatives: [], ownsBar: true };
64
- const group = shellHeader ? rightGroup(context, expression, choices) : expression;
65
- const result = controlsOf(context, group, choices);
66
- const current = choices;
67
- const unknown = [...initial.branches, ...result.branches].find((node) => !current.has(node));
68
- if (unknown) {
69
- pending.push(new Map([...choices, [unknown, "alternate"]]), new Map([...choices, [unknown, "consequent"]]));
70
- }
71
- else
72
- alternatives.push(result.controls);
73
- }
74
- return { alternatives, ownsBar: false };
75
- };
@@ -1,5 +0,0 @@
1
- import type { ReaderContext, Resolved } from "./types.js";
2
- /** Literal create labels and conventional create handlers are executable static evidence. */
3
- export declare const isCreateAction: (text: string) => boolean;
4
- /** Follow static item/section arrays; inspect labels and handlers where a menu action is declared. */
5
- export declare const menuHasCreate: (context: ReaderContext, expression: Resolved | null | undefined, seen?: Set<Resolved>) => boolean;
@@ -1,37 +0,0 @@
1
- /** Static create-action semantics in a bar's controls and its attached menu declarations. */
2
- import { fileURLToPath } from "node:url";
3
- import { phrasesOf } from "@starci/hfs/runtime/scripts/lib/source-phrases.mjs";
4
- import { escapeRegExp } from "@starci/hfs/runtime/scripts/lib/regex.mjs";
5
- import { propertyKeyText, resolveLocal } from "./app-shell.js";
6
- import { isNode } from "./types.js";
7
- const runtimeRoot = fileURLToPath(new URL("../../runtime/", import.meta.url));
8
- const localizedLabels = phrasesOf("appShell.product", runtimeRoot);
9
- if (localizedLabels.length === 0)
10
- throw new Error("The FE canon's app-shell create-action phrase catalog is missing: regenerate the runtime bundle.");
11
- const localizedCreate = localizedLabels.map((label) => escapeRegExp(label).replace(/\s+/g, String.raw `\s*`)).join("|");
12
- const CREATE_WORDS = new RegExp(String.raw `\bcreate\b|\bnew\s+(?:item|record|project|task)|${localizedCreate}`, "i");
13
- /** Literal create labels and conventional create handlers are executable static evidence. */
14
- export const isCreateAction = (text) => CREATE_WORDS.test(text.normalize("NFC")) || /\bcreate[A-Z]|\bnew[A-Z]|\bonCreate|\bhandleCreate/.test(text);
15
- const ACTION_FIELDS = new Set(["id", "key", "label", "title", "textValue", "onAction", "onPress", "onClick", "action"]);
16
- /** Follow static item/section arrays; inspect labels and handlers where a menu action is declared. */
17
- export const menuHasCreate = (context, expression, seen = new Set()) => {
18
- const node = resolveLocal(context, expression);
19
- if (!node || seen.has(node))
20
- return false;
21
- seen.add(node);
22
- if (node.type === "SpreadElement")
23
- return menuHasCreate(context, node.argument, seen);
24
- if (node.type === "ArrayExpression")
25
- return node.elements.some((item) => menuHasCreate(context, item, seen));
26
- if (node.type !== "ObjectExpression")
27
- return false;
28
- return node.properties.some((property) => {
29
- if (property.type === "SpreadElement")
30
- return menuHasCreate(context, property.argument, seen);
31
- const name = propertyKeyText(property.key);
32
- const value = resolveLocal(context, property.value);
33
- if (name !== null && ACTION_FIELDS.has(name) && value && isNode(value) && isCreateAction(context.sourceCode.getText(value)))
34
- return true;
35
- return menuHasCreate(context, property.value, seen);
36
- });
37
- };
@@ -1,7 +0,0 @@
1
- /** Imported shell-band delegation requires its canonical composition in every visible source alternative. */
2
- import type { TSESTree } from "@typescript-eslint/types";
3
- import type { ReaderContext, Resolved } from "./types.js";
4
- /** True only for an imported JSX header whose owned implementation reaches a canonical Grammar bar. */
5
- export declare const provesImportedBar: (context: ReaderContext, opening: TSESTree.JSXOpeningElement) => boolean | null;
6
- /** True only when every visible compact-header alternative reaches a left Drawer with a drawer Sidebar. */
7
- export declare const provesNavigationOpener: (context: ReaderContext, expression: Resolved | null | undefined) => boolean;
@@ -1,97 +0,0 @@
1
- import { functionOf, importOf } from "@starci/eslint-canon-fe/lib/bindings.mjs";
2
- import { isBarControl, propOf, realNode, resolveLocal, textProp } from "./app-shell.js";
3
- import { isNavigationDrawer } from "./app-shell-scope.js";
4
- import { visitFunction, visitVisible } from "./app-shell-visible.js";
5
- import { headerProofs, importedHeader } from "./app-shell-owner-source.js";
6
- const OVERLAYS = new Set(["Dialog", "AlertDialog", "Drawer", "Popover", "DropdownMenu", "Tooltip"]);
7
- const importBinding = (context, opening) => {
8
- const name = opening.name.type === "JSXMemberExpression" ? opening.name.object : opening.name;
9
- return name.type === "JSXIdentifier" ? importOf(context, name) : null;
10
- };
11
- const reactFragment = (context, opening) => {
12
- const imported = importBinding(context, opening);
13
- return imported?.source === "react" && (imported.imported === "Fragment" || opening.name.type === "JSXMemberExpression" && opening.name.property.name === "Fragment");
14
- };
15
- const proveOwner = (owner, seen, kind) => {
16
- if (!owner)
17
- return false;
18
- const { context, value } = owner;
19
- const key = `${kind}:${context.filename}:${value.range.join(":")}`;
20
- const proofs = headerProofs(context);
21
- const known = proofs.get(key);
22
- if (known !== undefined)
23
- return known;
24
- if (seen.has(key))
25
- return false;
26
- const fn = functionOf(context, realNode(resolveLocal(context, value)));
27
- const valid = fn !== null && proveComposition(context, (visit, branch) => visitFunction(context, fn, visit, new Set(), branch, []), new Set(seen).add(key), kind);
28
- proofs.set(key, valid);
29
- return valid;
30
- };
31
- /** Drawer bodies must expose navigation on every branch, outside nested overlay content. */
32
- const proveDrawerBody = (context, opening, seen) => proveComposition(context, (visit, branch) => {
33
- const children = opening.parent.children.filter((child) => child.type !== "JSXText" || child.value.trim());
34
- if (children.length)
35
- for (const child of children)
36
- visitVisible(context, child, visit, new Set(), branch);
37
- else
38
- visitVisible(context, propOf(context, opening, "children").value, visit, new Set(), branch);
39
- }, seen, "sidebar");
40
- const matchesComposition = (context, opening, name, seen, kind) => {
41
- if (kind === "drawer")
42
- return isNavigationDrawer(context, opening) && proveDrawerBody(context, opening, seen);
43
- if (kind === "sidebar")
44
- return name === "Sidebar" && textProp(context, opening, "presentation") === "drawer";
45
- return name !== null && ["TopBar"].includes(name);
46
- };
47
- const proveComposition = (context, render, seen, kind) => {
48
- const pending = [new Map()];
49
- for (let choices = pending.pop(); choices; choices = pending.pop()) {
50
- const current = choices;
51
- const branch = [];
52
- let found = false;
53
- let unknown = false;
54
- render((opening, name) => {
55
- if (reactFragment(context, opening))
56
- return;
57
- if (matchesComposition(context, opening, name, seen, kind)) {
58
- found = true;
59
- return false;
60
- }
61
- if (name !== null && OVERLAYS.has(name))
62
- return false;
63
- if (kind === "bar" && (name !== null && ["header", "nav", "main"].includes(name) || isBarControl(context, opening, name))) {
64
- unknown = true;
65
- return false;
66
- }
67
- if (name === null && importBinding(context, opening)) {
68
- if (proveOwner(importedHeader(context, opening), seen, kind))
69
- found = true;
70
- else
71
- unknown = true;
72
- return false;
73
- }
74
- return undefined;
75
- }, (node) => {
76
- if (!current.has(node))
77
- branch.push(node);
78
- return current.get(node) ?? "consequent";
79
- });
80
- const missing = branch.find((node) => !current.has(node));
81
- if (missing)
82
- pending.push(new Map([...choices, [missing, "alternate"]]), new Map([...choices, [missing, "consequent"]]));
83
- else if (!found || unknown)
84
- return false;
85
- }
86
- return true;
87
- };
88
- /** True only for an imported JSX header whose owned implementation reaches a canonical Grammar bar. */
89
- export const provesImportedBar = (context, opening) => {
90
- if (reactFragment(context, opening))
91
- return null;
92
- if (!importBinding(context, opening))
93
- return null;
94
- return proveOwner(importedHeader(context, opening), new Set(), "bar");
95
- };
96
- /** True only when every visible compact-header alternative reaches a left Drawer with a drawer Sidebar. */
97
- export const provesNavigationOpener = (context, expression) => proveComposition(context, (visit, branch) => visitVisible(context, expression, visit, new Set(), branch), new Set(), "drawer");
@@ -1,2 +0,0 @@
1
- /** The status tones of the grammar: each has a solid pair and a soft pair (`--<tone>-soft`, `--<tone>-soft-foreground`). */
2
- export declare const STATUS_TONES: readonly string[];
@@ -1,8 +0,0 @@
1
- // Generated by packages/stylelint-canon/src/lib/write-vocabulary.ts from packages/grammar/src. Do not edit: run `npm run vocabulary` in packages/stylelint-canon.
2
- /** The status tones of the grammar: each has a solid pair and a soft pair (`--<tone>-soft`, `--<tone>-soft-foreground`). */
3
- export const STATUS_TONES = [
4
- "success",
5
- "warning",
6
- "danger",
7
- "info",
8
- ];
@@ -1,6 +0,0 @@
1
- import type { Rule } from "eslint";
2
- export declare const messageSurfaces: 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">;