@starci/eslint-grammar-core 0.48.0 → 0.49.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.49.1 - 2026-11-20
4
+
5
+ - Changed: versioned with the Grammar 0.49.1 (ToastStack, no lint change).
6
+
7
+ ## 0.49.0 - 2026-11-19 - Fragment
8
+
9
+ - Added: `starci-grammar/fragment-has-reason` (law `fragment`): a Grammar `<Fragment>` region (followed through an import alias such as `GrammarFragment`; React's Fragment and `<>` are not regions) names a non-empty string literal `reason`.
10
+ - Changed (BREAKING for code that relied on findings inside a region): every other rule of the plugin leaves the subtree of a `<Fragment>` element alone, and an import whose every use is inside one (`fragmentContext` of `@starci/eslint-canon-fe/lib/fragment.mjs`, canon-fe 9.21.0). Code outside a region is judged as before. Needs `@starci/eslint-canon-fe` ~9.21.0.
11
+ - Added: the Fragment inventory, a report that is never a finding: `node node_modules/@starci/eslint-grammar-core/dist/lib/fragment-inventory-cli.js [root] [--json]`, `fragmentInventory`, `fragmentUsesOf` and `formatFragmentInventory`. It lists file, position, reason and libraries of every `<Fragment reason="...">` and always exits 0.
12
+ - Changed: `card-is-object` and `card-content` no longer name `FlowGraph` and `BubbleMap` (removed from Grammar 0.49.0).
13
+
3
14
  ## 0.48.0 - 2026-11-19
4
15
 
5
16
  - Changed: the family version 0.48.0 (label over content, the padded list body, settings rows, ExpandableText and the batch 174 fixes of @starci/grammar). No rule change.
package/README.md CHANGED
@@ -59,3 +59,9 @@ Regression checks live in this ESLint package. The Grammar and consuming app fro
59
59
 
60
60
  The source is TypeScript in `src/` (`src/lib/` holds the shared readers, `src/vendor.d.ts` types the untyped canon and runtime
61
61
  JavaScript it imports); `npm run build` emits `dist/`, which is what the package ships beside `runtime/` and `docs/`.
62
+
63
+ ## Fragment (0.49.0)
64
+
65
+ `<Fragment reason="...">` is the Grammar's escape hatch: inside it no rule of this plugin reports anything, nor an import whose every use is there (`docs/fragment.md`). `starci-grammar/fragment-has-reason` is the one law that judges the element. `node node_modules/@starci/eslint-grammar-core/dist/lib/fragment-inventory-cli.js [root] [--json]` (the package `bin`) lists every use for audit and always exits 0.
66
+
67
+ The region is recognised only when the element is the `Fragment` export of `@starci/grammar`; a file that also needs React's Fragment imports the Grammar's one as `import { Fragment as GrammarFragment } from "@starci/grammar"` and the lint follows the alias. React's Fragment and `<>` open no region.
@@ -16,8 +16,8 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
16
16
  */
17
17
  /** The Grammar components that are one content of a card. */
18
18
  const CONTENT = new Set([
19
- "ListBox", "ItemList", "ListRow", "DescriptionList", "DataTable", "FlowGraph", "BarChart", "ProportionBar", "Sparkline", "Timeline", "DisclosureList",
20
- "Accordion", "BubbleMap", "MermaidDiagram", "Form", "FormGrid", "Fieldset", "Gallery", "ScheduleGrid", "Board", "Stepper",
19
+ "ListBox", "ItemList", "ListRow", "DescriptionList", "DataTable", "BarChart", "ProportionBar", "Sparkline", "Timeline", "DisclosureList",
20
+ "Accordion", "MermaidDiagram", "Form", "FormGrid", "Fieldset", "Gallery", "ScheduleGrid", "Board", "Stepper",
21
21
  ]);
22
22
  /** A Section that is itself one content. */
23
23
  const SECTION_CONTENT = new Set(["list", "figures"]);
@@ -12,7 +12,7 @@ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
12
12
  * - a form or a lone field: `Form`, `Fieldset`, `Input`, `Textarea`, `Select`, `ComboBox`, `SearchField`, `NumberField`, `RadioGroup`, `CheckboxGroup`
13
13
  * - a placeholder: `EmptyNotice`
14
14
  * - markdown: `Markdown`, `MarkdownArticle`
15
- * - a chart: `BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram`
15
+ * - a chart: `BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `MermaidDiagram`
16
16
  * The body is read through fragments, `cond && <x/>`, `cond ? <x/> : <y/>` and `.map`, and through the layout wrappers `Stack`, `Cluster`, `Inline`, `Grid`
17
17
  * and a plain `div` that hold that one content.
18
18
  *
@@ -66,8 +66,6 @@ const CONTENT = new Map([
66
66
  ["LineChart", CHART],
67
67
  ["Sparkline", CHART],
68
68
  ["ProportionBar", CHART],
69
- ["BubbleMap", CHART],
70
- ["FlowGraph", CHART],
71
69
  ["MermaidDiagram", CHART],
72
70
  ]);
73
71
  /** What a `Section` of this kind is and where it stands instead. */
@@ -0,0 +1,7 @@
1
+ import type { Rule } from "eslint";
2
+ /** A Fragment region always says why no Grammar component fits. */
3
+ export declare const fragmentHasReason: Rule.RuleModule;
4
+ /** The rules this law contributes to the plugin. */
5
+ export declare const rules: Record<string, Rule.RuleModule>;
6
+ /** Every rule of this law is an error. */
7
+ export declare const recommended: Record<string, "error">;
@@ -0,0 +1,63 @@
1
+ import { isGrammarFragment } from "@starci/eslint-canon-fe/lib/fragment.mjs";
2
+ import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
3
+ import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
4
+ /**
5
+ * The Fragment law: `<Fragment reason="...">` is the one sanctioned place where anything goes (any markup, any class name, any
6
+ * library) because no Grammar component fits, so it always says why. `reason` is a non-empty string literal such as
7
+ * `"workflow graph editor"`, and it serves the lint and the inventory (a Fragment renders no element, so there is nothing to stamp).
8
+ *
9
+ * WHAT IT READS. A Grammar `Fragment` element (`Fragment`, its import alias such as `GrammarFragment`, or `<ns>.Fragment`; never React's Fragment or `<>`) whose `reason` attribute is missing, is not a string literal (a literal, or an
10
+ * expression container holding a string literal or a template without substitutions), or is blank. An element with a spread
11
+ * attribute is not judged (the spread may carry the reason).
12
+ *
13
+ * THE OTHER HALF. Every other rule of this plugin leaves a Fragment subtree alone (`exemptFragmentRules` in `index.ts`: nothing inside is
14
+ * reported, nor an import whose every use is inside). This law is the one that judges the `<Fragment>` element itself, so it is not
15
+ * wrapped. The inventory of every use is `fragment-inventory.ts`, a report and never an error.
16
+ *
17
+ * WHERE IT APPLIES. Product source (`isProductSource`).
18
+ */
19
+ /** The statically known text of an attribute value; null when it is computed. */
20
+ const literalText = (value) => {
21
+ if (value === null)
22
+ return null;
23
+ const node = value.type === "JSXExpressionContainer" ? value.expression : value;
24
+ if (node.type === "Literal")
25
+ return typeof node.value === "string" ? node.value : null;
26
+ if (node.type === "TemplateLiteral" && node.expressions.length === 0)
27
+ return node.quasis[0]?.value.cooked ?? "";
28
+ return null;
29
+ };
30
+ /** A Fragment region always says why no Grammar component fits. */
31
+ export const fragmentHasReason = defineRule({
32
+ meta: {
33
+ type: "problem",
34
+ docs: { description: "A Fragment region names its reason, a non-empty string literal saying why no Grammar component fits." },
35
+ schema: [],
36
+ messages: {
37
+ reason: "`<Fragment>` needs `reason=\"...\"`, a non-empty string saying why no Grammar component fits (for example \"workflow graph editor\"). Fragment is a last resort and the reason is the audit trail: name it, or compose a Grammar component instead.",
38
+ },
39
+ },
40
+ create(context) {
41
+ if (!isProductSource(context))
42
+ return {};
43
+ return {
44
+ JSXOpeningElement(node) {
45
+ if (node.parent.type !== "JSXElement" || !isGrammarFragment(context, node.parent))
46
+ return;
47
+ if (node.attributes.some((entry) => entry.type === "JSXSpreadAttribute"))
48
+ return;
49
+ const reason = node.attributes.find((entry) => entry.type === "JSXAttribute" && entry.name.type === "JSXIdentifier" && entry.name.name === "reason");
50
+ const text = reason === undefined ? null : literalText(reason.value);
51
+ if (text === null || text.trim() === "")
52
+ context.report({ node, messageId: "reason" });
53
+ },
54
+ };
55
+ },
56
+ });
57
+ /** The rules this law contributes to the plugin. */
58
+ export const rules = {
59
+ "fragment-has-reason": fragmentHasReason,
60
+ };
61
+ defineFamilyRules(rules, "knowledge/patterns/fe/ui.yaml#FE-UI");
62
+ /** Every rule of this law is an error. */
63
+ export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
package/dist/index.d.ts CHANGED
@@ -53,3 +53,5 @@ export declare const coreGrammarConfig: (input: {
53
53
  export declare const coreGrammarPackagesConfig: typeof coreGrammarConfig;
54
54
  export { crossFileInputs } from "./lib/cross-file-inputs.js";
55
55
  export type { CrossFileInput } from "./lib/cross-file-inputs.js";
56
+ export { fragmentInventory, fragmentUsesOf, formatFragmentInventory } from "./lib/fragment-inventory.js";
57
+ export type { FragmentUse } from "./lib/fragment-inventory.js";
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ import { rules as cardIsObjectRules } from "./card-is-object.js";
7
7
  import { rules as chipLabelRules } from "./chip-label.js";
8
8
  import { rules as choiceControlsRules } from "./choice-controls.js";
9
9
  import { rules as dataTableSurfaceRules } from "./data-table-surface.js";
10
+ import { rules as fragmentRules } from "./fragment.js";
10
11
  import { rules as drawingRules } from "./drawing.js";
11
12
  import { rules as fieldLabelRules } from "./field-label.js";
12
13
  import { rules as freestyleRules } from "./freestyle.js";
@@ -43,8 +44,22 @@ import { rules as tableCellTypeRules } from "./table-cell-type.js";
43
44
  import { rules as textRules } from "./text-rules.js";
44
45
  import { rules as tokensRules } from "./tokens.js";
45
46
  import { rules as vendorRules } from "./vendor-boundary.js";
47
+ import { fragmentContext } from "@starci/eslint-canon-fe/lib/fragment.mjs";
46
48
  import { why as familyWhy } from "./lib/why.js";
47
- const CONTRIBUTIONS = [
49
+ /** A rule that leaves the code of a `<Fragment>` region alone (`fragmentContext` of the universal canon). */
50
+ const WRAPPED = new WeakSet();
51
+ const exemptFragment = (rule) => {
52
+ if (WRAPPED.has(rule))
53
+ return rule;
54
+ WRAPPED.add(rule);
55
+ const create = rule.create;
56
+ rule.create = (context) => create.call(rule, fragmentContext(context));
57
+ return rule;
58
+ };
59
+ /** The laws that judge the `<Fragment>` element itself and so are not wrapped: they would otherwise be silenced by the region they guard. */
60
+ const JUDGES_FRAGMENT_ITSELF = new Set(["fragment"]);
61
+ const DECLARED = [
62
+ { law: "fragment", rules: fragmentRules },
48
63
  { law: "app-shell", rules: appShellRules },
49
64
  { law: "button-arrow", rules: buttonArrowRules },
50
65
  { law: "card-content", rules: cardContentRules },
@@ -89,6 +104,14 @@ const CONTRIBUTIONS = [
89
104
  { law: "tokens", rules: tokensRules },
90
105
  { law: "vendor-boundary", rules: vendorRules },
91
106
  ];
107
+ /**
108
+ * Each law's rules as published: every rule but the Fragment law leaves the code of a `<Fragment>` region alone, and an import whose
109
+ * every use is inside one (`fragment.mjs` of the universal canon). Code outside a region is judged as before.
110
+ */
111
+ const CONTRIBUTIONS = DECLARED.map(({ law, rules }) => ({
112
+ law,
113
+ rules: JUDGES_FRAGMENT_ITSELF.has(law) ? rules : Object.fromEntries(Object.entries(rules).map(([name, rule]) => [name, exemptFragment(rule)])),
114
+ }));
92
115
  /** Each concrete Grammar law has one gathered owner. */
93
116
  export const lawOwners = CONTRIBUTIONS.map(({ law }) => law);
94
117
  /** Preserve declarations before gathering so duplicate rule names remain observable. */
@@ -147,3 +170,5 @@ export const coreGrammarConfig = ({ hfs, family = "core" } = {}) => {
147
170
  export const coreGrammarPackagesConfig = (input) => scopeToPackages(coreGrammarConfig(input), input.hfs);
148
171
  // The result cache of `starci app check --gate lint` (contexts/project/check-cache.md) reads the disk inputs the family rules declare.
149
172
  export { crossFileInputs } from "./lib/cross-file-inputs.js";
173
+ // The audit inventory of every `<Fragment reason="...">` region: a report, never a finding (the fragment inventory script prints it).
174
+ export { fragmentInventory, fragmentUsesOf, formatFragmentInventory } from "./lib/fragment-inventory.js";
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * `node node_modules/@starci/eslint-grammar-core/dist/lib/fragment-inventory-cli.js [root] [--json]`: print every `<Fragment reason="...">` region under `root` (default: the working directory).
4
+ * It is an audit report, never a gate: the exit code is 0 whatever it finds.
5
+ */
6
+ import { resolve } from "node:path";
7
+ import { fragmentInventory, formatFragmentInventory } from "./fragment-inventory.js";
8
+ const args = process.argv.slice(2);
9
+ const json = args.includes("--json");
10
+ const root = resolve(args.find((arg) => !arg.startsWith("--")) ?? ".");
11
+ const uses = fragmentInventory(root);
12
+ process.stdout.write(`${json ? JSON.stringify({ root, count: uses.length, uses }, null, 2) : formatFragmentInventory(uses)}\n`);
@@ -0,0 +1,33 @@
1
+ /** One `<Fragment>` region. */
2
+ export interface FragmentUse {
3
+ /** The file, relative to the scanned root, with forward slashes. */
4
+ readonly file: string;
5
+ readonly line: number;
6
+ readonly column: number;
7
+ /** The literal `reason`, or null when it is missing or computed. */
8
+ readonly reason: string | null;
9
+ /** The third-party modules the region's subtree uses. */
10
+ readonly libraries: readonly string[];
11
+ }
12
+ /**
13
+ * The `<Fragment>` regions of one source text.
14
+ *
15
+ * @param source - The text of a `.tsx` or `.jsx` file.
16
+ * @param file - The path to report the uses under.
17
+ * @returns The regions in source order; none when the file does not import `Fragment` from the Grammar.
18
+ */
19
+ export declare const fragmentUsesOf: (source: string, file: string) => FragmentUse[];
20
+ /**
21
+ * Every `<Fragment>` region under a folder.
22
+ *
23
+ * @param root - The folder to scan (an app root, or its `src/`).
24
+ * @returns The regions, by file then position.
25
+ */
26
+ export declare const fragmentInventory: (root: string) => FragmentUse[];
27
+ /**
28
+ * The inventory as text: a header with the counts, then one line per region. Information only.
29
+ *
30
+ * @param uses - The regions.
31
+ * @returns The report.
32
+ */
33
+ export declare const formatFragmentInventory: (uses: readonly FragmentUse[]) => string;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * The Fragment inventory: a report of every `<Fragment reason="...">` region an app holds, so each use can be audited. It is information,
3
+ * never a finding: it lists, it does not fail, and the CLI that prints it always exits 0 (a `<Fragment>` with no reason is listed as
4
+ * such; the `fragment-has-reason` rule is the one that fails it).
5
+ *
6
+ * A use is the file and position of the element, its reason and the third-party
7
+ * libraries its subtree names (the modules the file imports, other than the Grammar and relative paths, whose bindings the region uses).
8
+ */
9
+ import { readdirSync, readFileSync } from "node:fs";
10
+ import { join, relative, sep } from "node:path";
11
+ import { parseForESLint } from "@typescript-eslint/parser";
12
+ /** The Grammar package entries a component can be imported from. */
13
+ const GRAMMAR_SOURCE = /^@starci\/grammar(?:\/(?:common|core|offset-pop))?$/;
14
+ /** The folders no source of the app lives in. */
15
+ const SKIPPED = new Set(["node_modules", "dist", ".next", ".git", ".turbo", "coverage", "storybook-static", ".runtime"]);
16
+ const isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
17
+ /** The text of a string-literal attribute value, or null when it is absent or computed. */
18
+ const literalText = (attribute) => {
19
+ const value = attribute?.value;
20
+ if (value === undefined || value === null)
21
+ return null;
22
+ const node = value.type === "JSXExpressionContainer" ? value.expression : value;
23
+ if (node.type === "Literal")
24
+ return typeof node.value === "string" ? node.value : null;
25
+ if (node.type === "TemplateLiteral" && node.expressions.length === 0)
26
+ return node.quasis[0]?.value.cooked ?? null;
27
+ return null;
28
+ };
29
+ const attributeOf = (opening, name) => opening.attributes.find((entry) => entry.type === "JSXAttribute" && entry.name.type === "JSXIdentifier" && entry.name.name === name);
30
+ /**
31
+ * The `<Fragment>` regions of one source text.
32
+ *
33
+ * @param source - The text of a `.tsx` or `.jsx` file.
34
+ * @param file - The path to report the uses under.
35
+ * @returns The regions in source order; none when the file does not import `Fragment` from the Grammar.
36
+ */
37
+ export const fragmentUsesOf = (source, file) => {
38
+ if (!source.includes("Fragment"))
39
+ return [];
40
+ const { ast, visitorKeys } = parseForESLint(source, { ecmaFeatures: { jsx: true }, sourceType: "module", range: true, loc: true });
41
+ const fragment = new Set();
42
+ const namespaces = new Set();
43
+ const modules = new Map();
44
+ for (const statement of ast.body) {
45
+ if (statement.type !== "ImportDeclaration")
46
+ continue;
47
+ const from = String(statement.source.value);
48
+ const grammar = GRAMMAR_SOURCE.test(from);
49
+ for (const specifier of statement.specifiers) {
50
+ if (grammar && specifier.type === "ImportSpecifier" && (specifier.imported.type === "Identifier" ? specifier.imported.name : String(specifier.imported.value)) === "Fragment")
51
+ fragment.add(specifier.local.name);
52
+ else if (grammar && specifier.type === "ImportNamespaceSpecifier")
53
+ namespaces.add(specifier.local.name);
54
+ else if (!grammar && !from.startsWith(".") && !from.startsWith("/") && !from.startsWith("node:") && statement.importKind !== "type")
55
+ modules.set(specifier.local.name, from);
56
+ }
57
+ }
58
+ if (fragment.size === 0 && namespaces.size === 0)
59
+ return [];
60
+ const found = [];
61
+ const namesIn = (node, into) => {
62
+ if (node.type === "Identifier" || node.type === "JSXIdentifier")
63
+ into.add(node.name);
64
+ for (const key of visitorKeys[node.type] ?? []) {
65
+ const value = Reflect.get(node, key);
66
+ if (Array.isArray(value))
67
+ for (const item of value) {
68
+ if (isNode(item))
69
+ namesIn(item, into);
70
+ }
71
+ else if (isNode(value))
72
+ namesIn(value, into);
73
+ }
74
+ };
75
+ const isFragment = (name) => {
76
+ if (name.type === "JSXIdentifier")
77
+ return fragment.has(name.name);
78
+ return name.type === "JSXMemberExpression" && name.property.name === "Fragment" && name.object.type === "JSXIdentifier" && namespaces.has(name.object.name);
79
+ };
80
+ const visit = (node) => {
81
+ if (node.type === "JSXElement" && isFragment(node.openingElement.name)) {
82
+ const names = new Set();
83
+ namesIn(node, names);
84
+ found.push({
85
+ file,
86
+ line: node.loc.start.line,
87
+ column: node.loc.start.column + 1,
88
+ reason: literalText(attributeOf(node.openingElement, "reason")),
89
+ libraries: [...new Set([...names].flatMap((name) => modules.get(name) ?? []))].sort(),
90
+ });
91
+ }
92
+ for (const key of visitorKeys[node.type] ?? []) {
93
+ const value = Reflect.get(node, key);
94
+ if (Array.isArray(value))
95
+ for (const item of value) {
96
+ if (isNode(item))
97
+ visit(item);
98
+ }
99
+ else if (isNode(value))
100
+ visit(value);
101
+ }
102
+ };
103
+ visit(ast);
104
+ return found;
105
+ };
106
+ /** The `.tsx` and `.jsx` files under a folder, skipping dependency, build, spec and story files. */
107
+ const sourcesUnder = (folder) => readdirSync(folder, { withFileTypes: true }).flatMap((entry) => {
108
+ if (entry.isDirectory())
109
+ return SKIPPED.has(entry.name) ? [] : sourcesUnder(join(folder, entry.name));
110
+ return /\.[jt]sx$/u.test(entry.name) && !/\.(?:spec|test|stories)\.[jt]sx$/u.test(entry.name) ? [join(folder, entry.name)] : [];
111
+ });
112
+ /**
113
+ * Every `<Fragment>` region under a folder.
114
+ *
115
+ * @param root - The folder to scan (an app root, or its `src/`).
116
+ * @returns The regions, by file then position.
117
+ */
118
+ export const fragmentInventory = (root) => sourcesUnder(root)
119
+ .sort()
120
+ .flatMap((path) => fragmentUsesOf(readFileSync(path, "utf8"), relative(root, path).split(sep).join("/")));
121
+ /**
122
+ * The inventory as text: a header with the counts, then one line per region. Information only.
123
+ *
124
+ * @param uses - The regions.
125
+ * @returns The report.
126
+ */
127
+ export const formatFragmentInventory = (uses) => {
128
+ const files = new Set(uses.map((use) => use.file)).size;
129
+ const lines = [`Fragment inventory: ${uses.length} region${uses.length === 1 ? "" : "s"} in ${files} file${files === 1 ? "" : "s"} (information, not findings)`];
130
+ for (const use of uses) {
131
+ const libraries = use.libraries.length > 0 ? ` [${use.libraries.join(", ")}]` : "";
132
+ lines.push(`${use.file}:${use.line}:${use.column} ${use.reason === null ? "(no reason: fragment-has-reason fails it)" : JSON.stringify(use.reason)}${libraries}`);
133
+ }
134
+ return lines.join("\n");
135
+ };
@@ -8,7 +8,7 @@ Every rule below is an error in `coreGrammarConfig`; none can be switched off or
8
8
 
9
9
  ## `starci-grammar/card-one-content`
10
10
 
11
- - A `SurfaceCard` (not `tile`) whose body holds more than one content component (`ListBox`, `ItemList`, `DescriptionList`, `DataTable`, `FlowGraph`, `BarChart`, `Timeline`, `Form`, `FormGrid`, a `Section kind="list"` or `"figures"`, ...), looked through layout wrappers (message `many`).
11
+ - A `SurfaceCard` (not `tile`) whose body holds more than one content component (`ListBox`, `ItemList`, `DescriptionList`, `DataTable`, `BarChart`, `Timeline`, `Form`, `FormGrid`, a `Section kind="list"` or `"figures"`, ...), looked through layout wrappers (message `many`).
12
12
 
13
13
  ## `starci-grammar/no-label-description`
14
14
 
@@ -19,7 +19,7 @@ A Grammar `SurfaceCard` of the body kind (no `kind`, or `kind="body"`) whose ONL
19
19
  | `Form`, `Fieldset`, `Input`, `Textarea`, `Select`, `ComboBox`, `SearchField`, `NumberField`, `RadioGroup`, `CheckboxGroup` | `<Section title ...><Form .../></Section>` |
20
20
  | `EmptyNotice` | the `EmptyNotice` on its own |
21
21
  | `Markdown`, `MarkdownArticle` | `<Section title ...><Markdown .../></Section>` |
22
- | `BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `BubbleMap`, `FlowGraph`, `MermaidDiagram` | `<Section title ...><BarChart .../></Section>` |
22
+ | `BarChart`, `LineChart`, `Sparkline`, `ProportionBar`, `MermaidDiagram` | `<Section title ...><BarChart .../></Section>` |
23
23
 
24
24
  Not flagged: a card with `measure="formCompact"` (the sign-in form with no page around it), a `kind="tile"` card, a body card with more than one content (an object's name or facts beside a control is an object), a card with a JSX spread, a `kind` that is not a literal, a non-Grammar `SurfaceCard`, and non-product source. `Meter`, `Progress`, `Timeline` and `ListBox` are not in the table. There is no autofix: the card's `label` becomes the `Section` title, which the author reads.
25
25
 
@@ -0,0 +1,31 @@
1
+ # Fragment
2
+
3
+ Law module: `fragment.ts` (the rule), `lib/fragment-inventory.ts` (the report), and `fragmentContext` of `@starci/eslint-canon-fe/lib/fragment.mjs` (the exemption every other rule gets).
4
+
5
+ `<Fragment reason="...">` from `@starci/grammar` is the escape hatch: a region where any markup, any class name and any library may be used because no Grammar component fits. See `contexts/ui/components/fragment.md`.
6
+
7
+ Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
8
+
9
+ ## `starci-grammar/fragment-has-reason`
10
+
11
+ A Fragment region names its reason, a non-empty string literal saying why no Grammar component fits. A spread attribute may carry it and is not judged. The rule judges the `<Fragment>` element itself, so it is the one rule the region does not silence.
12
+
13
+ **Invalid** (`src/components/blocks/Runs/component.tsx`)
14
+
15
+ ```ts
16
+ export const A = () => <Fragment />
17
+ ```
18
+
19
+ **Valid** (`src/components/blocks/Runs/component.tsx`)
20
+
21
+ ```ts
22
+ export const A = () => <Fragment reason="workflow graph editor"><Canvas /></Fragment>
23
+ ```
24
+
25
+ ## The exemption (every other rule of this plugin)
26
+
27
+ Inside the subtree of a `<Fragment>` element (its `reason` attribute and everything it renders) no rule of this plugin reports. A finding on an import whose every use is inside a `<Fragment>`, or inside a same-file component that is not exported and that only a `<Fragment>` renders, is dropped too. Outside a region every rule is judged as before. `Fragment` is recognised by its import from `@starci/grammar`, followed through the local alias (`import { Fragment as GrammarFragment }`, the way a file that also needs React's Fragment writes it): React's Fragment, `<>` and an app component of the same name open no region.
28
+
29
+ ## The inventory (not a rule)
30
+
31
+ `node node_modules/@starci/eslint-grammar-core/dist/lib/fragment-inventory-cli.js [root] [--json]` lists every `<Fragment reason="...">` under `root` (file, position, reason, libraries). It is a report for audit and always exits 0; a region with no reason is listed as such and `fragment-has-reason` is what fails it. The same report is `fragmentInventory` and `formatFragmentInventory`, exported from the package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starci/eslint-grammar-core",
3
- "version": "0.48.0",
3
+ "version": "0.49.1",
4
4
  "description": "ESLint rules for the core Grammar's component, token and composition contracts.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -41,7 +41,7 @@
41
41
  "node": ">=22"
42
42
  },
43
43
  "peerDependencies": {
44
- "@starci/eslint-canon-fe": "~9.20.0",
44
+ "@starci/eslint-canon-fe": "~9.21.0",
45
45
  "@starci/hfs": "~6.13.0",
46
46
  "eslint": ">=9",
47
47
  "typescript": ">=5.9"
@@ -68,6 +68,6 @@
68
68
  "eslint-plugin-react-hooks": "^7.1.1",
69
69
  "typescript": "^6.0.3"
70
70
  },
71
- "gitHead": "0900451f0efa18b0b206c9f41681124cbea32350",
72
- "starciSource": "a77e6ea5356ee964b1bc2b5cd1cf529c92d88b8bfc55444da121630c545016cd"
71
+ "gitHead": "b5cc385b805bd5477812db946f8dfb580d13513c",
72
+ "starciSource": "468b4dd213013dca85b5af2b4af9f2769dd92f7afe0c309abcc0fcfa15417a35"
73
73
  }
@@ -181,7 +181,7 @@ topics:
181
181
  rules: "FE-CHART"
182
182
  - path: flow.yaml
183
183
  title: Flow canvas
184
- decides: "@xyflow/react behind the grammar FlowGraph"
184
+ decides: "@xyflow/react drawn by the app inside a Fragment region"
185
185
  rules: "FE-FLOW"
186
186
  - path: markdown.yaml
187
187
  title: Markdown
@@ -236,12 +236,12 @@ rules:
236
236
  assert: |-
237
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
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.
239
+ the description is a caption under the card (Section caption, SurfaceCard note).
240
240
  - id: case-2
241
241
  when: A surface is painted
242
242
  assert: |-
243
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.
244
+ draws it; an app never chooses.
245
245
  - id: ICONS-OUTLINE
246
246
  title: Icons are outline only; a tile marks a standalone icon
247
247
  governs: Every icon Grammar and an app draw.
@@ -258,7 +258,7 @@ rules:
258
258
  governs: A SurfaceCard of the body kind and what it holds.
259
259
  cases:
260
260
  - id: case-1
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)
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, MermaidDiagram)
262
262
  assert: |-
263
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
264
  A table is `<Section title ...><DataTable .../></Section>`, a list `Section kind="list"`, facts `<Section title ...><DescriptionList isDivided items={...} /></Section>`,