@starci/eslint-grammar-core 0.13.0 → 0.15.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 (73) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +4 -1
  3. package/dist/app-shell.d.ts +15 -0
  4. package/dist/app-shell.js +224 -0
  5. package/dist/chip-label.d.ts +14 -0
  6. package/dist/chip-label.js +117 -0
  7. package/dist/drawing.d.ts +8 -0
  8. package/dist/drawing.js +59 -0
  9. package/dist/grammar-boundary.d.ts +12 -0
  10. package/dist/grammar-boundary.js +88 -0
  11. package/dist/icon.d.ts +27 -0
  12. package/dist/icon.js +293 -0
  13. package/dist/index.d.ts +45 -0
  14. package/dist/index.js +73 -0
  15. package/dist/lib/app-shell-cluster.d.ts +6 -0
  16. package/dist/lib/app-shell-cluster.js +75 -0
  17. package/dist/lib/app-shell-create.d.ts +5 -0
  18. package/dist/lib/app-shell-create.js +37 -0
  19. package/dist/lib/app-shell-owner-source.d.ts +11 -0
  20. package/dist/lib/app-shell-owner-source.js +159 -0
  21. package/dist/lib/app-shell-owner.d.ts +7 -0
  22. package/dist/lib/app-shell-owner.js +97 -0
  23. package/dist/lib/app-shell-scope.d.ts +13 -0
  24. package/dist/lib/app-shell-scope.js +93 -0
  25. package/dist/lib/app-shell-visible.d.ts +13 -0
  26. package/dist/lib/app-shell-visible.js +117 -0
  27. package/dist/lib/app-shell.d.ts +27 -0
  28. package/dist/lib/app-shell.js +185 -0
  29. package/dist/lib/rule-contract.d.ts +12 -0
  30. package/dist/lib/rule-contract.js +23 -0
  31. package/dist/lib/status-tones.generated.d.ts +2 -0
  32. package/dist/lib/status-tones.generated.js +8 -0
  33. package/dist/lib/types.d.ts +113 -0
  34. package/dist/lib/types.js +2 -0
  35. package/dist/lib/why.d.ts +8 -0
  36. package/dist/lib/why.js +42 -0
  37. package/dist/menu-entries.d.ts +27 -0
  38. package/dist/menu-entries.js +142 -0
  39. package/dist/status-colors.d.ts +13 -0
  40. package/dist/status-colors.js +143 -0
  41. package/dist/tokens.d.ts +11 -0
  42. package/dist/tokens.js +166 -0
  43. package/dist/typography.d.ts +13 -0
  44. package/dist/typography.js +72 -0
  45. package/dist/vendor-boundary.d.ts +5 -0
  46. package/dist/vendor-boundary.js +25 -0
  47. package/docs/chip-label.md +30 -0
  48. package/docs/grammar-boundary.md +1 -1
  49. package/docs/status-colors.md +2 -2
  50. package/package.json +18 -15
  51. package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
  52. package/runtime/knowledge/hfs/rules.yaml +23 -0
  53. package/app-shell.mjs +0 -208
  54. package/drawing.mjs +0 -60
  55. package/grammar-boundary.mjs +0 -94
  56. package/icon.mjs +0 -313
  57. package/index.d.ts +0 -28
  58. package/index.mjs +0 -78
  59. package/lib/app-shell-cluster.mjs +0 -66
  60. package/lib/app-shell-create.mjs +0 -33
  61. package/lib/app-shell-owner-source.mjs +0 -124
  62. package/lib/app-shell-owner.mjs +0 -83
  63. package/lib/app-shell-scope.mjs +0 -79
  64. package/lib/app-shell-visible.mjs +0 -92
  65. package/lib/app-shell.mjs +0 -148
  66. package/lib/rule-contract.mjs +0 -11
  67. package/lib/status-tones.generated.mjs +0 -9
  68. package/lib/why.mjs +0 -38
  69. package/menu-entries.mjs +0 -146
  70. package/status-colors.mjs +0 -140
  71. package/tokens.mjs +0 -164
  72. package/typography.mjs +0 -81
  73. package/vendor-boundary.mjs +0 -29
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.15.0 - 2026-10-28
4
+
5
+ - Changed: versioned together with Grammar 0.15.0; `@starci/eslint-canon-fe` 9.4.0 is the peer dependency, and the bundled canon pins follow release C (Grammar family 0.15.0, hfs 4.9.1, canon-fe 9.4.0, canon-be 3.6.0, jest-preset 2.4.1, `@starci/ai-router` 0.2.1), so an app installs the released versions without pin drift.
6
+ - Changed: the source is TypeScript in `src/`, built to `dist/` (`npm run build`; `prepack` builds); the package ships `dist/`, `runtime/` and `docs/` and no hand-written JavaScript or `index.d.ts` (the build emits the declarations, with the same public types). No rule or behaviour changed; the exports and specifiers (`.` and the default plugin) are unchanged.
7
+ - Changed: the specs are `src/*.spec.ts`, typechecked first by `npm test`.
8
+ - Fixed: the built declarations name `.js`, not the `.ts` sources (`tsc` keeps a relative `.ts` specifier in a `.d.ts`, which a consumer tsc cannot read).
9
+
10
+ ## 0.14.0 - 2026-10-27
11
+
12
+ - Changed: versioned together with Grammar 0.14.0; the bundled canon pins name the 0.14.0 Grammar family.
13
+ - Added: `starci-grammar/chip-label-starts-uppercase` (R322 `FE_CHIP_LABEL_CASE`): a literal `StatusDot` or `Badge` label starts with an uppercase letter, Vietnamese included; the fix uppercases it in place.
14
+ - Changed: `@starci/eslint-canon-fe` 9.3.0 is the peer dependency; the bundled canon pins name `starci-harness` 1.1.0-alpha.1 (`source: cli/package.json`) in place of the retired `@starci/cli`, the one command line a product installs for `starci app`, and follow hfs 4.9.0, canon-fe 9.3.0 and canon-be 3.5.0. No rule changes.
15
+
3
16
  ## 0.13.0 - 2026-10-27
4
17
 
5
18
  - Changed: `@starci/eslint-canon-fe` is a peer dependency (9.2.0), installed by the app beside this package, instead of a nested dependency.
package/README.md CHANGED
@@ -19,7 +19,7 @@ Family helpers and the generated runtime closure belong to this package.
19
19
 
20
20
  The rule IDs remain stable when their namespace moves. Laws cover the fixed app shell and navbar,
21
21
  Grammar-owned structural elements, glyphs and icon sizes, destructive menu entries, status inks,
22
- heading and token scales, vendor ownership and slot-status composition. Each rule's metadata cites
22
+ chip labels that start uppercase, heading and token scales, vendor ownership and slot-status composition. 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
 
@@ -49,3 +49,6 @@ Offset Pop inherits the Common component contract through `@starci/eslint-gramma
49
49
  Its own adapter selects that family and reuses these implementations.
50
50
 
51
51
  Regression checks live in this ESLint package. The Grammar and consuming app front ends carry no specs.
52
+
53
+ The source is TypeScript in `src/` (`src/lib/` holds the shared readers, `src/vendor.d.ts` types the untyped canon and runtime
54
+ JavaScript it imports); `npm run build` emits `dist/`, which is what the package ships beside `runtime/` and `docs/`.
@@ -0,0 +1,15 @@
1
+ import type { Rule } from "eslint";
2
+ /** The app frame is the fixed-viewport Grammar shell; hand-written frame landmarks are rejected. */
3
+ export declare const appShellFrame: Rule.RuleModule;
4
+ /** Bottom navigation is not an alternative compact app-shell frame. */
5
+ export declare const noShellBottomTabs: Rule.RuleModule;
6
+ /** Every visible control in a navbar band uses the shared control size. */
7
+ export declare const navbarControlSize: Rule.RuleModule;
8
+ /** The right cluster is checked at the bar's actions composition, in visual source order. */
9
+ export declare const navbarCluster: Rule.RuleModule;
10
+ /** Creation belongs to its page, never to the global app bar. */
11
+ export declare const noNavbarCreate: Rule.RuleModule;
12
+ /** Every app-shell enforcer is gathered into the ordinary FE lint and gate path. */
13
+ export declare const rules: Record<string, Rule.RuleModule>;
14
+ /** Every rule is mandatory. */
15
+ export declare const recommended: Record<string, "error">;
@@ -0,0 +1,224 @@
1
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
2
+ /** FE-APP-SHELL-1..5: static app-frame and visible navbar composition from the UI canon. */
3
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
4
+ import { grammarName, isBarControl, propOf, resolveLocal, semanticText, textProp } from "./lib/app-shell.js";
5
+ import { appBarOpenings, isAppBar, isAppShell, isNavigationDrawer, ownsAppFrame } from "./lib/app-shell-scope.js";
6
+ import { visitVisible } from "./lib/app-shell-visible.js";
7
+ import { clusterAlternatives } from "./lib/app-shell-cluster.js";
8
+ import { isCreateAction, menuHasCreate } from "./lib/app-shell-create.js";
9
+ import { provesImportedBar, provesNavigationOpener } from "./lib/app-shell-owner.js";
10
+ import { variableOf } from "@starci/eslint-canon-fe/lib/bindings.mjs";
11
+ import { walk } from "@starci/eslint-canon-fe/lib/ast.mjs";
12
+ const CANON = "knowledge/ui/composition/app-shell.yaml";
13
+ const BOTTOM_TABS = /^(?:BottomNav|BottomNavigation|BottomTabBar|MobileBottomNav|MobileTabBar)$/;
14
+ const EXPECTED_CLUSTER = ["language:IconButton", "theme:Switch", "notifications:IconButton", "account:AvatarButton"];
15
+ const meta = (code, description, messages) => ({
16
+ type: "problem",
17
+ docs: { description: `${code}: ${description}`, url: CANON },
18
+ schema: [],
19
+ messages,
20
+ });
21
+ /** Whether a slot is present; unknown spreads do not prove either presence or absence. */
22
+ const slotPresence = (context, opening, name) => {
23
+ const prop = propOf(context, opening, name);
24
+ if (!prop.known)
25
+ return null;
26
+ const value = resolveLocal(context, prop.value);
27
+ if (value === null || value === undefined || value.type === "Literal" && (value.value == null || value.value === false))
28
+ return false;
29
+ return !(value.type === "Identifier" && value.name === "undefined" && !variableOf(context, value)?.defs.length);
30
+ };
31
+ /** Resolve constants and require every possible conditional value to prove the slot contract. */
32
+ const everyValue = (context, expression, proves, seen = new Set()) => {
33
+ const node = resolveLocal(context, expression);
34
+ if (!node || seen.has(node))
35
+ return false;
36
+ if (node.type !== "ConditionalExpression")
37
+ return proves(node);
38
+ const visited = new Set(seen).add(node);
39
+ return [node.consequent, node.alternate].every((branch) => everyValue(context, branch, proves, visited));
40
+ };
41
+ const hasMobileNavigation = (context, opening) => {
42
+ const drawerProp = propOf(context, opening, "navigationDrawer");
43
+ const drawer = drawerProp.known && everyValue(context, drawerProp.value, (value) => value.type === "ObjectExpression");
44
+ const opener = drawer || provesNavigationOpener(context, propOf(context, opening, "compactHeader").value);
45
+ const visibility = propOf(context, opening, "navigationVisibility");
46
+ const defaultsWide = opener && visibility.known && slotPresence(context, opening, "navigationVisibility") === false;
47
+ if (!defaultsWide && (!visibility.known || !everyValue(context, visibility.value, (value) => value.type === "Literal" && value.value === "wide")))
48
+ return false;
49
+ return opener;
50
+ };
51
+ /** App-owned tab names count only in a frame owner or a shell's rendered slots. */
52
+ const visibleFromShell = (context, target) => {
53
+ let visible = false;
54
+ walk(context.sourceCode, context.sourceCode.ast, (node) => {
55
+ if (node.type !== "JSXOpeningElement" || !isAppShell(context, node))
56
+ return;
57
+ const inspect = (opening) => { if (opening === target)
58
+ visible = true; };
59
+ for (const slot of ["header", "compactHeader", "navigation", "primary", "floatingLayer", "compactNavigation"])
60
+ visitVisible(context, propOf(context, node, slot).value, inspect);
61
+ for (const child of node.parent.children)
62
+ visitVisible(context, child, inspect);
63
+ });
64
+ return visible;
65
+ };
66
+ /** The app frame is the fixed-viewport Grammar shell; hand-written frame landmarks are rejected. */
67
+ export const appShellFrame = defineRule({
68
+ meta: meta("FE_APP_SHELL_FRAME", "FE-APP-SHELL-1 uses WorkspaceShell viewport=fixed.", {
69
+ frame: "FE_APP_SHELL_FRAME: compose the app frame with WorkspaceShell viewport=\"fixed\"; navigation must resolve to navigationVisibility=\"wide\" and have navigationDrawer or a compactHeader with a left Drawer containing Sidebar presentation=\"drawer\". Grammar owns its header, navigation and independent scroll regions.",
70
+ }),
71
+ create(context) {
72
+ if (!isProductSource(context))
73
+ return {};
74
+ return { JSXOpeningElement(node) {
75
+ const shell = isAppShell(context, node);
76
+ const wrongViewport = shell && textProp(context, node, "viewport") !== "fixed";
77
+ const missingVisibility = shell && slotPresence(context, node, "navigation") !== false && !hasMobileNavigation(context, node);
78
+ const handFrame = ownsAppFrame(context, node) && (node.name.type === "JSXIdentifier" && ["header", "nav", "main"].includes(node.name.name) || isAppBar(context, node) && !appBarOpenings(context).has(node));
79
+ if (wrongViewport || missingVisibility || handFrame) {
80
+ context.report({ node, messageId: "frame" });
81
+ }
82
+ } };
83
+ },
84
+ });
85
+ /** Bottom navigation is not an alternative compact app-shell frame. */
86
+ export const noShellBottomTabs = defineRule({
87
+ meta: meta("FE_APP_SHELL_BOTTOM_TABS", "FE-APP-SHELL-4 keeps mobile navigation in the sidebar drawer.", {
88
+ bottom: "FE_APP_SHELL_BOTTOM_TABS: the app shell uses a mobile subnav opener and Sidebar drawer. Remove bottom tab navigation and WorkspaceShell compactNavigation.",
89
+ }),
90
+ create(context) {
91
+ if (!isProductSource(context))
92
+ return {};
93
+ return { JSXOpeningElement(node) {
94
+ const name = grammarName(context, node);
95
+ const appTab = name === null && node.name.type === "JSXIdentifier" && BOTTOM_TABS.test(node.name.name) && (ownsAppFrame(context, node) || visibleFromShell(context, node));
96
+ const compact = name === "WorkspaceShell" ? propOf(context, node, "compactNavigation") : null;
97
+ const value = compact ? resolveLocal(context, compact.value) : null;
98
+ const absent = value?.type === "Identifier" && value.name === "undefined" && !variableOf(context, value)?.defs.length;
99
+ if (BOTTOM_TABS.test(name ?? "") || appTab || compact && !absent && (!compact.known || compact.value !== null || compact.present))
100
+ context.report({ node, messageId: "bottom" });
101
+ } };
102
+ },
103
+ });
104
+ const visitBar = (context, node, visit) => {
105
+ const name = grammarName(context, node);
106
+ if (name === "WorkspaceShell" && isAppShell(context, node)) {
107
+ for (const slot of ["header", "compactHeader"])
108
+ visitVisible(context, propOf(context, node, slot).value, visit);
109
+ }
110
+ else if (isAppBar(context, node)) {
111
+ visitVisible(context, node.parent, visit);
112
+ }
113
+ else if (isNavigationDrawer(context, node)) {
114
+ visitVisible(context, propOf(context, node, "trigger").value, visit);
115
+ }
116
+ };
117
+ const delegatesImportedBar = (context, expression) => {
118
+ let imported = false;
119
+ let controls = false;
120
+ let unknown = false;
121
+ visitVisible(context, expression, (opening, name) => {
122
+ if (isBarControl(context, opening, name))
123
+ controls = true;
124
+ if (name !== null)
125
+ return;
126
+ const proof = provesImportedBar(context, opening);
127
+ if (proof === true)
128
+ imported = true;
129
+ if (proof === false)
130
+ unknown = true;
131
+ });
132
+ return imported && !controls && !unknown;
133
+ };
134
+ /** Every visible control in a navbar band uses the shared control size. */
135
+ export const navbarControlSize = defineRule({
136
+ meta: meta("FE_NAVBAR_CONTROL_SIZE", "FE-APP-SHELL-2 requires size=control on bar controls.", {
137
+ control: "FE_NAVBAR_CONTROL_SIZE: {{name}} in the navbar band needs size=\"control\" so every bar control shares Grammar's control height.",
138
+ }),
139
+ create(context) {
140
+ if (!isProductSource(context))
141
+ return {};
142
+ const reported = new Set();
143
+ return { JSXOpeningElement(node) {
144
+ visitBar(context, node, (control, name) => {
145
+ if (!isBarControl(context, control, name) || textProp(context, control, "size") === "control" || reported.has(control))
146
+ return;
147
+ reported.add(control);
148
+ context.report({ node: control, messageId: "control", data: { name } });
149
+ });
150
+ } };
151
+ },
152
+ });
153
+ /** The right cluster is checked at the bar's actions composition, in visual source order. */
154
+ export const navbarCluster = defineRule({
155
+ meta: meta("FE_NAVBAR_CLUSTER", "FE-APP-SHELL-3 fixes navbar action kinds and order.", {
156
+ cluster: "FE_NAVBAR_CLUSTER: navbar actions must be a tertiary Language IconButton in DropdownMenu, theme Switch, notification IconButton in Popover, account AvatarButton in DropdownMenu, in that order. Mobile retains notifications then account and moves language/theme into the drawer.",
157
+ }),
158
+ create(context) {
159
+ if (!isProductSource(context))
160
+ return {};
161
+ return { JSXOpeningElement(node) {
162
+ const name = grammarName(context, node);
163
+ if (!isAppShell(context, node) && !isAppBar(context, node))
164
+ return;
165
+ const shellHeader = name === "WorkspaceShell";
166
+ const actions = propOf(context, node, shellHeader ? "header" : "actions");
167
+ const { alternatives, ownsBar } = clusterAlternatives(context, actions.value, shellHeader);
168
+ if (ownsBar)
169
+ return;
170
+ if (shellHeader && delegatesImportedBar(context, actions.value))
171
+ return;
172
+ const desktop = EXPECTED_CLUSTER.join("|");
173
+ const mobile = EXPECTED_CLUSTER.slice(2).join("|");
174
+ const sequences = alternatives.map((sequence) => sequence.join("|"));
175
+ if (!sequences.includes(desktop) || sequences.some((sequence) => sequence !== desktop && sequence !== mobile))
176
+ context.report({ node, messageId: "cluster" });
177
+ } };
178
+ },
179
+ });
180
+ /** Creation belongs to its page, never to the global app bar. */
181
+ export const noNavbarCreate = defineRule({
182
+ meta: meta("FE_NAVBAR_CREATE", "FE-APP-SHELL-5 keeps create actions on pages.", {
183
+ create: "FE_NAVBAR_CREATE: move this create action from the navbar to its page.",
184
+ }),
185
+ create(context) {
186
+ if (!isProductSource(context))
187
+ return {};
188
+ const reported = new Set();
189
+ const report = (node) => {
190
+ if (reported.has(node))
191
+ return;
192
+ reported.add(node);
193
+ context.report({ node, messageId: "create" });
194
+ };
195
+ const inspect = (control, name) => {
196
+ if (name === "DropdownMenu" || name === "Popover") {
197
+ if (["entries", "items", "sections"].some((slot) => menuHasCreate(context, propOf(context, control, slot).value)))
198
+ report(control);
199
+ visitVisible(context, propOf(context, control, "content").value, inspect);
200
+ for (const child of control.parent.children)
201
+ visitVisible(context, child, inspect);
202
+ }
203
+ if (!isBarControl(context, control, name) || reported.has(control))
204
+ return;
205
+ const text = `${semanticText(context, control)} ${control.parent.children.map((child) => context.sourceCode.getText(child)).join(" ")}`;
206
+ if (isCreateAction(text))
207
+ report(control);
208
+ };
209
+ return { JSXOpeningElement(node) {
210
+ visitBar(context, node, inspect);
211
+ } };
212
+ },
213
+ });
214
+ /** Every app-shell enforcer is gathered into the ordinary FE lint and gate path. */
215
+ export const rules = {
216
+ "app-shell-frame": appShellFrame,
217
+ "no-shell-bottom-tabs": noShellBottomTabs,
218
+ "navbar-control-size": navbarControlSize,
219
+ "navbar-cluster": navbarCluster,
220
+ "no-navbar-create": noNavbarCreate,
221
+ };
222
+ defineFamilyRules(rules, "knowledge/ui/composition/app-shell.yaml");
223
+ /** Every rule is mandatory. */
224
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -0,0 +1,14 @@
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">;
@@ -0,0 +1,117 @@
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"]));
@@ -0,0 +1,8 @@
1
+ /** StarCi per-slot status composition, governed by FE-RULE-OWNERSHIP. */
2
+ import type { Rule } from "eslint";
3
+ /** A block's pure half never branches on a data status itself. */
4
+ export declare const slotStatusThroughSlotView: Rule.RuleModule;
5
+ /** The family status recipe retains its published rule ID. */
6
+ export declare const rules: Record<string, Rule.RuleModule>;
7
+ /** Every family composition rule is mandatory. */
8
+ export declare const recommended: Record<string, "error">;
@@ -0,0 +1,59 @@
1
+ import { pureHalf } from "@starci/eslint-canon-fe/lib/drawing-scope.mjs";
2
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
3
+ // -- DRAWING-4 ----------------------------------------------------------------------------------
4
+ /** Flags that are a slot's data status. */
5
+ const STATUS_FLAG = /^(?:isLoading|isError|isForbidden|isPending|isValidating|isEmpty)$/;
6
+ /** The name a test expression reads, if it is a status flag. */
7
+ const statusFlagOf = (node) => {
8
+ if (!node)
9
+ return null;
10
+ if (node.type === "UnaryExpression")
11
+ return statusFlagOf(node.argument);
12
+ if (node.type === "ChainExpression")
13
+ return statusFlagOf(node.expression);
14
+ if (node.type === "Identifier" && STATUS_FLAG.test(node.name))
15
+ return node.name;
16
+ if (node.type === "MemberExpression" && node.property?.type === "Identifier" && STATUS_FLAG.test(node.property.name)) {
17
+ return node.property.name;
18
+ }
19
+ if (node.type === "LogicalExpression" || node.type === "BinaryExpression")
20
+ return statusFlagOf(node.left) ?? statusFlagOf(node.right);
21
+ return null;
22
+ };
23
+ /** A block's pure half never branches on a data status itself. */
24
+ export const slotStatusThroughSlotView = defineRule({
25
+ meta: {
26
+ type: "problem",
27
+ docs: { description: "A block's pure half renders data status through `SlotView`, never its own branch." },
28
+ schema: [],
29
+ messages: {
30
+ branch: "This branches on `{{flag}}` by hand. Every slot renders its status through `SlotView`, the one recipe: a second branch drifts from it and becomes one more variant somebody draws.",
31
+ },
32
+ },
33
+ create(context) {
34
+ if (pureHalf(context) !== "blocks")
35
+ return {};
36
+ const check = (node, test) => {
37
+ const flag = statusFlagOf(test);
38
+ if (flag)
39
+ context.report({ node, messageId: "branch", data: { flag } });
40
+ };
41
+ return {
42
+ ConditionalExpression(node) {
43
+ check(node, node.test);
44
+ },
45
+ IfStatement(node) {
46
+ check(node, node.test);
47
+ },
48
+ LogicalExpression(node) {
49
+ if (node.operator === "&&" && node.parent?.type === "JSXExpressionContainer")
50
+ check(node, node.left);
51
+ },
52
+ };
53
+ },
54
+ });
55
+ /** The family status recipe retains its published rule ID. */
56
+ export const rules = { "slot-status-through-slotview": slotStatusThroughSlotView };
57
+ defineFamilyRules(rules, "knowledge/grammars/core/playbook.yaml#state-recipes");
58
+ /** Every family composition rule is mandatory. */
59
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
@@ -0,0 +1,12 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * The intrinsic elements of page structure and text, each with the grammar components that render it.
4
+ * Read against packages/grammar/src (`export const <Component>`); `grammar-boundary.spec.ts` fails when one is not exported.
5
+ */
6
+ export declare const GRAMMAR_OWNERS: Readonly<Record<string, string>>;
7
+ /** No raw structural or text element in app source or in a package that composes the grammar. */
8
+ export declare const noRawStructuralElement: Rule.RuleModule;
9
+ /** The rules this law contributes to the plugin. */
10
+ export declare const rules: Record<string, Rule.RuleModule>;
11
+ /** Every rule is an error. */
12
+ export declare const recommended: Record<string, "error">;
@@ -0,0 +1,88 @@
1
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
2
+ /**
3
+ * The boundary between product code and `@starci/grammar`.
4
+ *
5
+ * Grammar is a business-neutral HeroUI-backed component package. Product code composes its components with ordinary React
6
+ * children and typed props. A page's structure and text are made of those components, not of raw HTML: a raw `<section>`, `<p>`
7
+ * or `<ul>` carries no density, no focus or landmark contract and no dark value from the design system, and the class names
8
+ * written by hand to compensate are where a second visual language starts.
9
+ *
10
+ * Which tags are refused is decided by the package: a tag is in the list only when `@starci/grammar` exports a component that
11
+ * renders it (`GRAMMAR_OWNERS` below, each entry verified against the package source by the twin test). A tag the grammar has no
12
+ * component for (`div`, `br`, `aside`, `article`) is not refused: there is nothing to compose instead, and refusing it would
13
+ * demand a workaround. When the grammar gains a component for one, the tag joins the list.
14
+ *
15
+ * WHERE IT APPLIES. App source that composes the grammar (slots `fe.feature`, `fe.components`, `fe.route`, `fe.hooks`) and any
16
+ * workspace package except the `<family>-ui` package (`fe.package.ui`), whose components are the renderers and are the one place
17
+ * a raw tag belongs. Spec files render raw HTML as a harness and are not judged. A file no slot owns is not judged either: the
18
+ * rule refuses to guess a scope.
19
+ */
20
+ import { hfsOf } from "@starci/eslint-canon-fe/lib/hfs.mjs";
21
+ /**
22
+ * The intrinsic elements of page structure and text, each with the grammar components that render it.
23
+ * Read against packages/grammar/src (`export const <Component>`); `grammar-boundary.spec.ts` fails when one is not exported.
24
+ */
25
+ export const GRAMMAR_OWNERS = Object.freeze({
26
+ h1: "Heading", h2: "Heading", h3: "Heading", h4: "Heading", h5: "Heading", h6: "Heading",
27
+ p: "Text", span: "Text",
28
+ hr: "Divider",
29
+ label: "Label",
30
+ form: "Form",
31
+ fieldset: "Fieldset",
32
+ dl: "DescriptionList", dt: "DescriptionList", dd: "DescriptionList",
33
+ table: "DataTable", thead: "DataTable", tbody: "DataTable", tr: "DataTable", td: "DataTable", th: "DataTable",
34
+ ul: "List, SurfaceListCard or StaticStateRow", ol: "List, SurfaceListCard or StaticStateRow", li: "ListItem, SurfaceListCard or StaticStateRow",
35
+ header: "SectionHeader or TopBar",
36
+ footer: "Footer",
37
+ nav: "NavLandmark, Subnav, Breadcrumbs or NavigationFeatureNav",
38
+ section: "Region or SurfaceCard",
39
+ main: "WorkspaceShell",
40
+ figure: "MediaFrame", figcaption: "MediaFrame",
41
+ });
42
+ /** The slots of app source that compose the grammar: features, components, routes and hooks. */
43
+ const APP_SLOTS = new Set(["fe.feature", "fe.components", "fe.route", "fe.hooks"]);
44
+ /** The slot of the package whose leaves ARE the renderers: the only place raw structural tags belong. */
45
+ const RENDERER_SLOT = "fe.package.ui";
46
+ /**
47
+ * True for a file that composes the grammar: app source (`fe.feature`, `fe.components`, `fe.route`, `fe.hooks`) and any
48
+ * workspace package but the `<family>-ui` package, whose components are the renderers.
49
+ */
50
+ const composesGrammar = (context, file) => {
51
+ const hfs = hfsOf(context);
52
+ const slot = hfs.slotOf(file);
53
+ if (slot === null || slot === RENDERER_SLOT)
54
+ return false;
55
+ return APP_SLOTS.has(slot) || hfs.tierOf(file) === "package";
56
+ };
57
+ /** No raw structural or text element in app source or in a package that composes the grammar. */
58
+ export const noRawStructuralElement = defineRule({
59
+ meta: {
60
+ type: "problem",
61
+ docs: { description: "Page structure and text are grammar components, not raw `div`-family HTML; only `fe.package.ui` renderers draw raw tags." },
62
+ schema: [],
63
+ messages: {
64
+ raw: "A raw `<{{tag}}>`. Page structure and text are composed from the grammar (`@starci/grammar`, or the repository's `<family>-ui` package): use {{owner}}. A raw tag brings none of the design system's density, landmark and state contract, and the class names written to make up for it start a second visual language. If the grammar cannot express this structure, add the component to the grammar or the ui package rather than drawing it here.",
65
+ },
66
+ },
67
+ create(context) {
68
+ const file = context.filename || context.getFilename();
69
+ if (!composesGrammar(context, file))
70
+ return {};
71
+ return {
72
+ JSXOpeningElement(node) {
73
+ if (node.name.type !== "JSXIdentifier")
74
+ return;
75
+ const owner = Object.hasOwn(GRAMMAR_OWNERS, node.name.name) ? GRAMMAR_OWNERS[node.name.name] ?? null : null;
76
+ if (owner !== null)
77
+ context.report({ node, messageId: "raw", data: { tag: node.name.name, owner: `\`${owner}\`` } });
78
+ },
79
+ };
80
+ },
81
+ });
82
+ /** The rules this law contributes to the plugin. */
83
+ export const rules = {
84
+ "no-raw-structural-element": noRawStructuralElement,
85
+ };
86
+ defineFamilyRules(rules, "knowledge/patterns/fe/ui.yaml#FE-UI");
87
+ /** Every rule is an error. */
88
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
package/dist/icon.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ import type { Rule } from "eslint";
2
+ /** A glyph library is named in one file, and a caller asks for a MEANING instead. */
3
+ export declare const noVendorIconOutsideIconLeaf: Rule.RuleModule;
4
+ /**
5
+ * The icon leaf owns the map, but that ownership does not license a second glyph vocabulary: every glyph comes from the
6
+ * heroicons family on its two cuts. Phosphor, Iconify, Lucide and every other glyph catalogue are refused, including the
7
+ * ones no list can name in advance.
8
+ */
9
+ export declare const heroiconsIsTheGlyphVendor: Rule.RuleModule;
10
+ /** A glyph takes one of the two steps; a fraction or an arbitrary value is a third. */
11
+ export declare const noOffScaleGlyphSize: Rule.RuleModule;
12
+ /** The icon's size is its usage's: the call site passes the glyph and never a size class. */
13
+ export declare const noIconSizeClass: Rule.RuleModule;
14
+ /** A repeated metric cell does not invent a feature glyph absent from the reference. */
15
+ export declare const noDecorativeIconInMetricCell: Rule.RuleModule;
16
+ /** Inline SVG belongs only to an explicitly declared brand mark in a leaf entry. */
17
+ export declare const noInlineSvgOutsideBrandMarkLeaf: Rule.RuleModule;
18
+ /** The rules this law contributes to the plugin. */
19
+ export declare const rules: Record<string, Rule.RuleModule>;
20
+ /**
21
+ * The level this law asks for, as the plugin's own opinion.
22
+ *
23
+ * A consuming repository's `eslint.config.mjs` stays the authority on what is actually switched on.
24
+ * Both rules are exact - a package prefix and a size pattern - so neither carries the false-positive
25
+ * risk that would justify adopting it at `warn`.
26
+ */
27
+ export declare const recommended: Record<string, "error">;