@starci/eslint-grammar-core 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -2
- package/README.md +5 -4
- package/dist/app-shell.js +1 -1
- package/dist/grammar-boundary.js +5 -5
- package/dist/icon.d.ts +0 -4
- package/dist/icon.js +1 -64
- package/dist/index.js +4 -2
- package/dist/lib/app-shell-cluster.js +1 -1
- package/dist/lib/app-shell-owner.js +1 -1
- package/dist/lib/app-shell-scope.js +1 -1
- package/dist/lib/app-shell-visible.js +0 -1
- package/dist/lib/app-shell.js +2 -2
- package/dist/lib/grammar-imports.d.ts +16 -0
- package/dist/lib/grammar-imports.js +37 -0
- package/dist/lib/why.js +33 -8
- package/dist/page-header.d.ts +11 -4
- package/dist/page-header.js +12 -42
- package/dist/page.d.ts +3 -3
- package/dist/page.js +21 -21
- package/dist/pane.js +3 -3
- package/dist/status-colors.d.ts +10 -4
- package/dist/status-colors.js +103 -29
- package/dist/surface-card.d.ts +9 -0
- package/dist/surface-card.js +191 -0
- package/dist/surface-depth.d.ts +1 -1
- package/dist/surface-depth.js +53 -49
- package/dist/text-rules.d.ts +18 -0
- package/dist/text-rules.js +160 -0
- package/dist/tokens.d.ts +0 -2
- package/dist/tokens.js +0 -38
- package/docs/app-shell.md +3 -3
- package/docs/grammar-boundary.md +1 -1
- package/docs/page-header.md +15 -12
- package/docs/page.md +5 -5
- package/docs/status-colors.md +17 -8
- package/docs/surface-card.md +57 -0
- package/docs/surface-depth.md +16 -14
- package/package.json +3 -3
- package/runtime/bundle.json +2 -1
- package/runtime/knowledge/grammars/core/playbook.yaml +41 -51
- package/runtime/knowledge/hfs/canon-pins.yaml +7 -7
- package/runtime/knowledge/hfs/rules.yaml +374 -36
- package/runtime/knowledge/hfs/slots.yaml +5 -5
- package/runtime/knowledge/patterns/fe/ui.yaml +0 -1
- package/runtime/knowledge/ui/proof/anatomy-source.yaml +1 -1
- package/runtime/scripts/hfs/architecture/component-tiers.mjs +161 -0
- package/runtime/scripts/hfs/architecture/config.mjs +1 -1
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +16 -1
- package/dist/typography.d.ts +0 -13
- package/dist/typography.js +0 -72
package/dist/surface-depth.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
+
import { importOf } from "@starci/eslint-canon-fe/lib/bindings.mjs";
|
|
1
2
|
import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
|
|
2
3
|
import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
|
|
3
4
|
/**
|
|
4
|
-
* The surface
|
|
5
|
-
* `
|
|
6
|
-
* raised (
|
|
5
|
+
* The surface nesting law (HFS R340 `FE_RAISED_SURFACE_IN_SURFACE`): a surface never stands inside another surface. A
|
|
6
|
+
* `SurfaceCard` inside another `SurfaceCard`, inside a `Pane surface`, or inside a `Dialog`, `Drawer`, `AlertDialog` or
|
|
7
|
+
* `Popover` is refused; the Grammar has one depth, raised, and draws no nested edge (owner decision: surface in surface is
|
|
8
|
+
* banned totally, dialogs and drawers included). The Grammar throws the same refusal in development; this is its
|
|
9
|
+
* same-file half, and R356 closes it across files.
|
|
7
10
|
*
|
|
8
|
-
*
|
|
9
|
-
* `
|
|
10
|
-
* `
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* WHAT IT READS. A `depth` attribute whose value is the string `"top"` (a literal, or an expression container holding one)
|
|
14
|
-
* on a depth-accepting surface element (`SurfaceListCard` or `<ns>.SurfaceListCard`), when a `SurfaceCard`,
|
|
15
|
-
* `SurfaceListCard` or `SurfaceAccordionCard` element of the same file encloses it. A depth computed at run time is not
|
|
16
|
-
* judged, and neither is a surface nobody encloses in this file (its parent may nest it; Grammar resolves that).
|
|
11
|
+
* WHAT IT READS. A `SurfaceCard` element (or `<ns>.SurfaceCard`) imported from `@starci/grammar` that a `SurfaceCard`,
|
|
12
|
+
* `Dialog`, `Drawer`, `AlertDialog`, `Popover` or `Pane` with a `surface` prop of the same file encloses. An overlay's
|
|
13
|
+
* `trigger` is not its content, so a card written in a trigger is not enclosed by it. A surface nobody encloses in this file
|
|
14
|
+
* (its parent may nest it) is judged where the parent is written.
|
|
17
15
|
*
|
|
18
16
|
* WHERE IT APPLIES. Product source (`isProductSource`).
|
|
19
17
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const DEPTH_PROP = new Set(["SurfaceListCard"]);
|
|
18
|
+
const GRAMMAR_SOURCE = /^@starci\/grammar(?:\/(?:common|core|offset-pop))?$/;
|
|
19
|
+
/** Surfaces and overlays whose content is a surface. */
|
|
20
|
+
const HOSTS = new Set(["SurfaceCard", "Dialog", "Drawer", "AlertDialog", "Popover", "Pane"]);
|
|
24
21
|
/** The element name of a JSX name: `SurfaceCard`, or `G.SurfaceCard` as `SurfaceCard`. */
|
|
25
22
|
const nameOf = (name) => {
|
|
26
23
|
if (name.type === "JSXIdentifier")
|
|
@@ -29,56 +26,63 @@ const nameOf = (name) => {
|
|
|
29
26
|
return name.property.name;
|
|
30
27
|
return null;
|
|
31
28
|
};
|
|
32
|
-
/**
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
/** The leftmost identifier of a JSX name. */
|
|
30
|
+
const rootOf = (name) => {
|
|
31
|
+
if (name.type === "JSXIdentifier")
|
|
32
|
+
return name;
|
|
33
|
+
if (name.type === "JSXMemberExpression")
|
|
34
|
+
return rootOf(name.object);
|
|
35
|
+
return null;
|
|
36
|
+
};
|
|
37
|
+
/** True when an opening element names the Grammar component `wanted`, or one of a set. */
|
|
38
|
+
const isGrammar = (context, opening, wanted) => {
|
|
39
|
+
const root = rootOf(opening.name);
|
|
40
|
+
const name = nameOf(opening.name);
|
|
41
|
+
if (root === null || name === null || !wanted.has(name))
|
|
42
|
+
return null;
|
|
43
|
+
const imported = importOf(context, root);
|
|
44
|
+
return imported !== null && imported !== undefined && GRAMMAR_SOURCE.test(imported.source) ? name : null;
|
|
45
|
+
};
|
|
46
|
+
/** The host that encloses this card's content in the same file, or null. A host's attributes (a `trigger`) do not enclose. */
|
|
47
|
+
const enclosingHost = (context, opening) => {
|
|
48
|
+
let previous = opening;
|
|
49
|
+
for (let current = opening.parent?.parent; current !== undefined && current !== null; previous = current, current = current.parent) {
|
|
37
50
|
if (current.type !== "JSXElement")
|
|
38
51
|
continue;
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
|
|
52
|
+
// `previous` is a child of the element, or its opening tag when the walk came up through an attribute.
|
|
53
|
+
if (previous === current.openingElement)
|
|
54
|
+
continue;
|
|
55
|
+
const name = isGrammar(context, current.openingElement, HOSTS);
|
|
56
|
+
if (name === null)
|
|
57
|
+
continue;
|
|
58
|
+
if (name === "Pane" && !current.openingElement.attributes.some((entry) => entry.type === "JSXAttribute" && entry.name.type === "JSXIdentifier" && entry.name.name === "surface"))
|
|
59
|
+
continue;
|
|
60
|
+
return name;
|
|
42
61
|
}
|
|
43
|
-
return
|
|
44
|
-
};
|
|
45
|
-
/** True when an attribute value is statically the string `"top"`. */
|
|
46
|
-
const isTop = (value) => {
|
|
47
|
-
if (value === null)
|
|
48
|
-
return false;
|
|
49
|
-
if (value.type === "Literal")
|
|
50
|
-
return value.value === "top";
|
|
51
|
-
if (value.type !== "JSXExpressionContainer")
|
|
52
|
-
return false;
|
|
53
|
-
const expression = value.expression;
|
|
54
|
-
if (expression.type === "Literal")
|
|
55
|
-
return expression.value === "top";
|
|
56
|
-
return expression.type === "TemplateLiteral" && expression.expressions.length === 0 && expression.quasis.length === 1 && expression.quasis[0]?.value.cooked === "top";
|
|
62
|
+
return null;
|
|
57
63
|
};
|
|
58
|
-
/** A surface inside another surface
|
|
64
|
+
/** A surface inside another surface is refused. */
|
|
59
65
|
export const noRaisedSurfaceInSurface = defineRule({
|
|
60
66
|
meta: {
|
|
61
67
|
type: "problem",
|
|
62
|
-
docs: { description: "R340: a
|
|
68
|
+
docs: { description: "R340: a SurfaceCard never stands inside another SurfaceCard, a Pane surface, or a Dialog, Drawer, AlertDialog or Popover." },
|
|
63
69
|
schema: [],
|
|
64
70
|
messages: {
|
|
65
|
-
|
|
71
|
+
nested: "This `SurfaceCard` stands inside {{host}}: a surface never stands inside a surface (the Grammar has one depth and draws no nested edge). Give the content to the host's own body, or use a kind of the outer card (`bands`, `list`, `figures`) for what needs its own faces.",
|
|
66
72
|
},
|
|
67
73
|
},
|
|
68
74
|
create(context) {
|
|
69
75
|
if (!isProductSource(context))
|
|
70
76
|
return {};
|
|
71
77
|
return {
|
|
72
|
-
|
|
73
|
-
if (
|
|
74
|
-
return;
|
|
75
|
-
const opening = attribute.parent;
|
|
76
|
-
if (opening.type !== "JSXOpeningElement")
|
|
78
|
+
JSXOpeningElement(opening) {
|
|
79
|
+
if (isGrammar(context, opening, new Set(["SurfaceCard"])) === null)
|
|
77
80
|
return;
|
|
78
|
-
const
|
|
79
|
-
if (
|
|
81
|
+
const host = enclosingHost(context, opening);
|
|
82
|
+
if (host === null)
|
|
80
83
|
return;
|
|
81
|
-
|
|
84
|
+
const label = host === "SurfaceCard" ? "another `SurfaceCard`" : host === "Pane" ? "a `Pane surface`" : `a \`${host}\``;
|
|
85
|
+
context.report({ node: opening, messageId: "nested", data: { host: label } });
|
|
82
86
|
},
|
|
83
87
|
};
|
|
84
88
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
/**
|
|
3
|
+
* The laws of text and emphasis (HFS R357, R358, R359).
|
|
4
|
+
*
|
|
5
|
+
* text-inline-only (R357) `Text` is a run of words: a block component inside it is a layout drawn in a paragraph.
|
|
6
|
+
* no-text-heading (R358) a strong `Text` that only heads a group of blocks is a hand heading: use `Section`, a card
|
|
7
|
+
* `label` or `Heading`, which own the level, the spacing and the outline.
|
|
8
|
+
* one-highlight-per-render (R359) a render states one highlighted thing (G-9): a second `isHighlight` dilutes the first.
|
|
9
|
+
*
|
|
10
|
+
* WHAT THEY READ. Grammar names are resolved through the file's own imports from `@starci/grammar`, so an alias or a local
|
|
11
|
+
* component of the same name is not judged. A spread attribute or a computed value is not judged.
|
|
12
|
+
*/
|
|
13
|
+
/** Components that lay content out as blocks: none of them belongs inside a run of text. */
|
|
14
|
+
export declare const BLOCK_COMPONENTS: ReadonlySet<string>;
|
|
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">;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { isProductSource } from "@starci/eslint-canon-fe/lib/scope.mjs";
|
|
2
|
+
import { defineFamilyRules, defineRule } from "./lib/rule-contract.js";
|
|
3
|
+
/**
|
|
4
|
+
* The laws of text and emphasis (HFS R357, R358, R359).
|
|
5
|
+
*
|
|
6
|
+
* text-inline-only (R357) `Text` is a run of words: a block component inside it is a layout drawn in a paragraph.
|
|
7
|
+
* no-text-heading (R358) a strong `Text` that only heads a group of blocks is a hand heading: use `Section`, a card
|
|
8
|
+
* `label` or `Heading`, which own the level, the spacing and the outline.
|
|
9
|
+
* one-highlight-per-render (R359) a render states one highlighted thing (G-9): a second `isHighlight` dilutes the first.
|
|
10
|
+
*
|
|
11
|
+
* WHAT THEY READ. Grammar names are resolved through the file's own imports from `@starci/grammar`, so an alias or a local
|
|
12
|
+
* component of the same name is not judged. A spread attribute or a computed value is not judged.
|
|
13
|
+
*/
|
|
14
|
+
/** Components that lay content out as blocks: none of them belongs inside a run of text. */
|
|
15
|
+
export const BLOCK_COMPONENTS = new Set([
|
|
16
|
+
"Stack", "Cluster", "Grid", "Section", "SurfaceCard", "DataTable", "Heading", "DescriptionList",
|
|
17
|
+
"Divider", "Page", "Pane", "PaneGrid", "PaneSection", "Form", "Fieldset", "Quote", "Alert", "Stepper", "Timeline", "MarkdownArticle", "EmptyNotice",
|
|
18
|
+
"ListRow", "StaticStateRow", "SegmentedControl", "FilterButtonGroup", "Tabs",
|
|
19
|
+
]);
|
|
20
|
+
/** Plain elements that are blocks. */
|
|
21
|
+
const BLOCK_TAGS = new Set(["div", "p", "ul", "ol", "li", "section", "article", "table", "form", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "blockquote"]);
|
|
22
|
+
/** The Grammar export a file's import binds to a local name. */
|
|
23
|
+
const grammarImports = (program) => {
|
|
24
|
+
const bound = new Map();
|
|
25
|
+
for (const statement of program.body) {
|
|
26
|
+
if (statement.type !== "ImportDeclaration" || typeof statement.source.value !== "string" || !/^@starci\/grammar(?:\/|$)/.test(statement.source.value))
|
|
27
|
+
continue;
|
|
28
|
+
for (const specifier of statement.specifiers) {
|
|
29
|
+
if (specifier.type === "ImportSpecifier")
|
|
30
|
+
bound.set(specifier.local.name, specifier.imported.type === "Identifier" ? specifier.imported.name : String(specifier.imported.value));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return bound;
|
|
34
|
+
};
|
|
35
|
+
const nameOf = (opening, bound) => {
|
|
36
|
+
const name = opening.name;
|
|
37
|
+
if (name.type !== "JSXIdentifier")
|
|
38
|
+
return { grammar: null, tag: null };
|
|
39
|
+
const grammar = bound.get(name.name);
|
|
40
|
+
if (grammar !== undefined)
|
|
41
|
+
return { grammar, tag: null };
|
|
42
|
+
return { grammar: null, tag: name.name === name.name.toLowerCase() ? name.name : null };
|
|
43
|
+
};
|
|
44
|
+
const isBlock = (element, bound) => {
|
|
45
|
+
const { grammar, tag } = nameOf(element.openingElement, bound);
|
|
46
|
+
return (grammar !== null && BLOCK_COMPONENTS.has(grammar)) || (tag !== null && BLOCK_TAGS.has(tag));
|
|
47
|
+
};
|
|
48
|
+
/** Whether an attribute is present and not statically false; a spread or a computed value counts as unknown (false). */
|
|
49
|
+
const isOn = (opening, attribute) => opening.attributes.some((entry) => {
|
|
50
|
+
if (entry.type !== "JSXAttribute" || entry.name.type !== "JSXIdentifier" || entry.name.name !== attribute)
|
|
51
|
+
return false;
|
|
52
|
+
const value = entry.value;
|
|
53
|
+
if (value === null)
|
|
54
|
+
return true;
|
|
55
|
+
if (value.type === "JSXExpressionContainer")
|
|
56
|
+
return value.expression.type === "Literal" && value.expression.value === true;
|
|
57
|
+
return false;
|
|
58
|
+
});
|
|
59
|
+
const meaningful = (children) => children.filter((child) => !(child.type === "JSXText" && child.value.trim() === "") && !(child.type === "JSXExpressionContainer" && child.expression.type === "JSXEmptyExpression"));
|
|
60
|
+
const textInlineOnly = defineRule({
|
|
61
|
+
meta: {
|
|
62
|
+
type: "problem",
|
|
63
|
+
docs: { description: "R357: Text holds a run of words; a block component inside it is refused.", url: "knowledge/hfs/rules.yaml#R357" },
|
|
64
|
+
schema: [],
|
|
65
|
+
messages: { block: "`{{name}}` is a block, and `Text` is a run of words: a block inside it is a layout drawn in a paragraph. Close the `Text` and place the block beside it, or use the component that owns that layout." },
|
|
66
|
+
},
|
|
67
|
+
create(context) {
|
|
68
|
+
if (!isProductSource(context))
|
|
69
|
+
return {};
|
|
70
|
+
let bound = new Map();
|
|
71
|
+
return {
|
|
72
|
+
Program(node) { bound = grammarImports(node); },
|
|
73
|
+
JSXElement(node) {
|
|
74
|
+
if (nameOf(node.openingElement, bound).grammar !== "Text")
|
|
75
|
+
return;
|
|
76
|
+
for (const child of node.children) {
|
|
77
|
+
if (child.type !== "JSXElement" || !isBlock(child, bound))
|
|
78
|
+
continue;
|
|
79
|
+
const { grammar, tag } = nameOf(child.openingElement, bound);
|
|
80
|
+
context.report({ node: child.openingElement, messageId: "block", data: { name: grammar ?? tag ?? "element" } });
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
const noTextHeading = defineRule({
|
|
87
|
+
meta: {
|
|
88
|
+
type: "problem",
|
|
89
|
+
docs: { description: "R358: a strong Text alone heading a group of blocks is a hand heading.", url: "knowledge/hfs/rules.yaml#R358" },
|
|
90
|
+
schema: [],
|
|
91
|
+
messages: { heading: "This strong `Text` only titles the blocks that follow it, which is a heading written by hand: it has no level in the outline and each page spaces it differently. Give the group a `Section` title, a card `label`, or `Heading`." },
|
|
92
|
+
},
|
|
93
|
+
create(context) {
|
|
94
|
+
if (!isProductSource(context))
|
|
95
|
+
return {};
|
|
96
|
+
let bound = new Map();
|
|
97
|
+
const check = (parent) => {
|
|
98
|
+
const children = meaningful(parent.children);
|
|
99
|
+
const [first, ...rest] = children;
|
|
100
|
+
if (first === undefined || first.type !== "JSXElement" || rest.length === 0)
|
|
101
|
+
return;
|
|
102
|
+
if (nameOf(first.openingElement, bound).grammar !== "Text" || !isOn(first.openingElement, "isStrong"))
|
|
103
|
+
return;
|
|
104
|
+
if (first.children.some((child) => child.type === "JSXElement" && isBlock(child, bound)))
|
|
105
|
+
return;
|
|
106
|
+
if (rest.every((child) => child.type === "JSXElement" && isBlock(child, bound)))
|
|
107
|
+
context.report({ node: first.openingElement, messageId: "heading" });
|
|
108
|
+
};
|
|
109
|
+
return { Program(node) { bound = grammarImports(node); }, JSXElement: check, JSXFragment: check };
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const oneHighlightPerRender = defineRule({
|
|
113
|
+
meta: {
|
|
114
|
+
type: "problem",
|
|
115
|
+
docs: { description: "R359: a render states one highlighted thing; a second isHighlight is refused.", url: "knowledge/hfs/rules.yaml#R359" },
|
|
116
|
+
schema: [],
|
|
117
|
+
messages: { second: "A second `isHighlight` in one render: when two things are highlighted neither is, and the eye has no first place to land. Keep the one that matters now and give the other its plain state." },
|
|
118
|
+
},
|
|
119
|
+
create(context) {
|
|
120
|
+
if (!isProductSource(context))
|
|
121
|
+
return {};
|
|
122
|
+
let bound = new Map();
|
|
123
|
+
const seen = new WeakMap();
|
|
124
|
+
const enclosing = (node) => {
|
|
125
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
126
|
+
if (current.type === "ArrowFunctionExpression" || current.type === "FunctionDeclaration" || current.type === "FunctionExpression") {
|
|
127
|
+
// a callback of a map/filter is one render of many rows, not a second thing in the same render
|
|
128
|
+
const parent = current.parent;
|
|
129
|
+
if (current.type !== "FunctionDeclaration" && parent?.type === "CallExpression" && parent.callee.type === "MemberExpression")
|
|
130
|
+
continue;
|
|
131
|
+
return current;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
Program(node) { bound = grammarImports(node); },
|
|
138
|
+
JSXOpeningElement(node) {
|
|
139
|
+
if (nameOf(node, bound).grammar === null || !isOn(node, "isHighlight"))
|
|
140
|
+
return;
|
|
141
|
+
const fn = enclosing(node);
|
|
142
|
+
if (fn === null)
|
|
143
|
+
return;
|
|
144
|
+
const count = (seen.get(fn) ?? 0) + 1;
|
|
145
|
+
seen.set(fn, count);
|
|
146
|
+
if (count > 1)
|
|
147
|
+
context.report({ node, messageId: "second" });
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
/** The rules this law contributes to the plugin. */
|
|
153
|
+
export const rules = {
|
|
154
|
+
"text-inline-only": textInlineOnly,
|
|
155
|
+
"no-text-heading": noTextHeading,
|
|
156
|
+
"one-highlight-per-render": oneHighlightPerRender,
|
|
157
|
+
};
|
|
158
|
+
defineFamilyRules(rules, "knowledge/hfs/rules.yaml#R357");
|
|
159
|
+
/** Every rule of this law is an error. */
|
|
160
|
+
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
|
package/dist/tokens.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
2
|
/** A fractional step is off the ladder, not between two rungs. */
|
|
3
3
|
export declare const noFractionalStep: Rule.RuleModule;
|
|
4
|
-
/** Large text plus a heavy weight is a heading, and headings come from the component that owns both. */
|
|
5
|
-
export declare const noHandRolledHeading: Rule.RuleModule;
|
|
6
4
|
/** A class naming a token the theme never defines is a class that draws nothing. */
|
|
7
5
|
export declare const noUnresolvedTokenClass: Rule.RuleModule;
|
|
8
6
|
/** StarCi scale rules, bound to their knowledge owner. */
|
package/dist/tokens.js
CHANGED
|
@@ -12,10 +12,6 @@ import { defineFamilyRules, defineRule, exemptFreestyle } from "./lib/rule-contr
|
|
|
12
12
|
* the ladder, and it will match nothing else on any screen.
|
|
13
13
|
*/
|
|
14
14
|
const FRACTIONAL = /\b(?:gap|gap-x|gap-y|p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|space-x|space-y|inset|top|bottom|left|right|size|w|h)-\d+\.\d+\b/;
|
|
15
|
-
/** Large text. Paired with a heavy weight it is a heading, whatever element carries it. */
|
|
16
|
-
const LARGE_TEXT = /\btext-(?:xl|2xl|3xl|4xl|5xl)\b/;
|
|
17
|
-
/** A heavy weight. */
|
|
18
|
-
const HEAVY_WEIGHT = /\bfont-(?:bold|extrabold|black)\b/;
|
|
19
15
|
/** A fractional step is off the ladder, not between two rungs. */
|
|
20
16
|
export const noFractionalStep = exemptFreestyle(defineRule({
|
|
21
17
|
meta: {
|
|
@@ -36,39 +32,6 @@ export const noFractionalStep = exemptFreestyle(defineRule({
|
|
|
36
32
|
});
|
|
37
33
|
},
|
|
38
34
|
}));
|
|
39
|
-
/** Large text plus a heavy weight is a heading, and headings come from the component that owns both. */
|
|
40
|
-
export const noHandRolledHeading = defineRule({
|
|
41
|
-
meta: {
|
|
42
|
-
type: "problem",
|
|
43
|
-
docs: { description: "A heading comes from the heading component, not from raw type classes." },
|
|
44
|
-
schema: [],
|
|
45
|
-
messages: {
|
|
46
|
-
heading: "Large text and a heavy weight together are a heading, whatever element carries them - and assembled here it is a heading nothing else knows about: the outline a screen reader builds does not contain it, and it stays behind the day the type scale changes. Render the heading component, which owns the tag and the size as one decision.",
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
create(context) {
|
|
50
|
-
return classTextVisitors(context, (node, text) => {
|
|
51
|
-
if (!text)
|
|
52
|
-
return;
|
|
53
|
-
if (LARGE_TEXT.test(text) && HEAVY_WEIGHT.test(text)) {
|
|
54
|
-
context.report({ node, messageId: "heading" });
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
/**
|
|
60
|
-
* The class families whose names are PROMISES about a theme token, and the variable each needs.
|
|
61
|
-
*
|
|
62
|
-
* Tailwind resolves `max-w-app-lg` by looking for `--container-app-lg`. Nothing warns when that
|
|
63
|
-
* variable does not exist: the class is emitted, the element gets no width, and the type system
|
|
64
|
-
* is satisfied because the name IS in the union. That is the failure this rule exists for - a
|
|
65
|
-
* class can be typesafe and mean nothing at the same time, and the union is exactly what makes
|
|
66
|
-
* it look settled.
|
|
67
|
-
*
|
|
68
|
-
* Only families whose token name is DERIVABLE from the class name are listed. A colour or a
|
|
69
|
-
* spacing step resolves through Tailwind's own scale as well as the theme, so a rule guessing at
|
|
70
|
-
* those would report classes that work.
|
|
71
|
-
*/
|
|
72
35
|
/**
|
|
73
36
|
* Names Tailwind resolves ITSELF, which therefore promise nothing about this theme.
|
|
74
37
|
*
|
|
@@ -158,7 +121,6 @@ export const noUnresolvedTokenClass = defineRule({
|
|
|
158
121
|
/** StarCi scale rules, bound to their knowledge owner. */
|
|
159
122
|
export const rules = {
|
|
160
123
|
"no-fractional-step": noFractionalStep,
|
|
161
|
-
"no-hand-rolled-heading": noHandRolledHeading,
|
|
162
124
|
"no-unresolved-token-class": noUnresolvedTokenClass,
|
|
163
125
|
};
|
|
164
126
|
defineFamilyRules(rules, "knowledge/hfs/rules.yaml#R61");
|
package/docs/app-shell.md
CHANGED
|
@@ -8,16 +8,16 @@ or a shell owner combining a bar and sidebar. It rejects hand-written app-frame
|
|
|
8
8
|
workspace shells without the fixed viewport. Generic flow-based site chrome stays in its own scope.
|
|
9
9
|
`no-shell-bottom-tabs` rejects bottom navigation components and the shell's `compactNavigation` slot.
|
|
10
10
|
|
|
11
|
-
The `navbar-cluster` rule reads the visible `TopBar`
|
|
11
|
+
The `navbar-cluster` rule reads the visible `TopBar` actions in source order:
|
|
12
12
|
tertiary Language `IconButton` triggering `DropdownMenu`, theme `Switch`, notification `IconButton`
|
|
13
13
|
triggering `Popover`, account `AvatarButton` triggering `DropdownMenu`. It follows
|
|
14
14
|
local JSX constants and components, constant object members, imported Grammar aliases, and namespace imports. Translated
|
|
15
15
|
labels may be dynamic; icon sources identify language and notifications. Menu contents and popover
|
|
16
16
|
content belong to their overlays and are outside the bar's control sequence. Conditional render
|
|
17
|
-
branches are checked separately. Grammar `TopBar`
|
|
17
|
+
branches are checked separately. Grammar `TopBar` compositions are app
|
|
18
18
|
bars by default. A proven `WorkspaceShell viewport="flow"` with no workspace/sidebar evidence owns
|
|
19
19
|
generic site chrome. A shell hosting an imported navbar delegates only after its owned public
|
|
20
|
-
export and rendered Base chain prove a `TopBar`
|
|
20
|
+
export and rendered Base chain prove a `TopBar` in every alternative.
|
|
21
21
|
Workspace exports resolve back to source. Raw or unknown imported headers are red; the actual
|
|
22
22
|
bar's own actions are checked where composed. Each lint source snapshot has fresh dependency proofs.
|
|
23
23
|
|
package/docs/grammar-boundary.md
CHANGED
|
@@ -12,7 +12,7 @@ Page structure and text are grammar components, not raw `div`-family HTML; only
|
|
|
12
12
|
|
|
13
13
|
Applies to app source that composes the grammar (slots `fe.feature`, `fe.components`, `fe.route`, `fe.hooks`) and to every workspace package except the `<family>-ui` package (`fe.package.ui`), whose components are the renderers. Spec files render raw HTML as a harness and are not judged; a file no slot owns is not judged.
|
|
14
14
|
|
|
15
|
-
The refused tags are exactly those `@starci/grammar` has a component for (the twin test reads the package source): `h1-h6` (`Heading`), `p` and `span` (`Text`), `hr` (`Divider`), `label` (`
|
|
15
|
+
The refused tags are exactly those `@starci/grammar` has a component for (the twin test reads the package source): `h1-h6` (`Heading`), `p` and `span` (`Text`), `hr` (`Divider`), `label` (`Input`, `Select`, `Textarea`), `form` (`Form`), `fieldset` (`Fieldset`), `dl` `dt` `dd` (`DescriptionList`), `table` `thead` `tbody` `tr` `td` `th` (`DataTable`), `ul` `ol` `li` (`Section` for a long list, `SurfaceListCard`, `StaticStateRow`), `header` (`Section`, `TopBar`), `footer` (`Footer`), `nav` (`NavLandmark` for a named row of links, `Page` for the breadcrumb trail, `TopBar` for the app bar), `section` (`Section` for a named non-card section, `SurfaceCard`), `main` (`WorkspaceShell`), `figure` and `figcaption` (`MediaFrame`). `div`, `br`, `aside` and `article` are not refused: the grammar has no component for them.
|
|
16
16
|
|
|
17
17
|
Native `<time>` remains available for an absolute timestamp. Live relative time and countdown labels use `RelativeTime` (the universal canon's `starci-fe/no-app-relative-clock`).
|
|
18
18
|
|
package/docs/page-header.md
CHANGED
|
@@ -1,32 +1,35 @@
|
|
|
1
|
-
# Page heads are
|
|
1
|
+
# Page heads are Page header
|
|
2
2
|
|
|
3
3
|
Law module: `page-header.ts`. Catalogue: R323 FE_PAGE_HEADER_HAND_ROLLED.
|
|
4
4
|
|
|
5
|
-
A page is headed by Grammar's `
|
|
5
|
+
A page is headed by Grammar's `Page`, whose `header` is the band: the trail, the page heading with its mark, status and summary, the page's commands and the page tabs, on a surface band whose content shares the page content's edges and which ends in its own full-width separator. `PageHeader` and `Breadcrumbs` are Page's parts and are not exported; a head composed from them has no band, no top inset and no separator, and every page re-decides its spacing. The law reduces to imports.
|
|
6
6
|
|
|
7
7
|
Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
|
|
8
8
|
|
|
9
9
|
## `starci-grammar/no-hand-rolled-page-header`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
A `PageHeader` or `Breadcrumbs` imported from `@starci/grammar` (by name, through an alias, or as a member of a namespace import) is a finding, reported on the import or the member. The types of the header's slots (`PageHeaderBreadcrumbs`, `PageHeaderTabs`) stay public and are not judged; the same names from another module are not the Grammar's.
|
|
12
12
|
|
|
13
13
|
**Invalid** (`src/components/blocks/ConnectionPage/component.tsx`)
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
</div>
|
|
16
|
+
import { PageHeader } from "@starci/grammar/core"
|
|
17
|
+
|
|
18
|
+
<PageHeader title="Main account" actions={<Button intent="neutral">Disconnect</Button>} />
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
**Valid** (`src/components/blocks/ConnectionPage/component.tsx`)
|
|
23
22
|
|
|
24
23
|
```tsx
|
|
25
|
-
<
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
<Page
|
|
25
|
+
header={{
|
|
26
|
+
breadcrumbs: { label: "Breadcrumb", items: trail },
|
|
27
|
+
title: "Main account",
|
|
28
|
+
actions: <Button intent="neutral">Disconnect</Button>,
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
<WebhookCard />
|
|
32
|
+
</Page>
|
|
30
33
|
```
|
|
31
34
|
|
|
32
35
|
**Finding code:** `FE_PAGE_HEADER_HAND_ROLLED`
|
package/docs/page.md
CHANGED
|
@@ -8,7 +8,7 @@ Every rule below is an error in `coreGrammarConfig`; none can be switched off or
|
|
|
8
8
|
|
|
9
9
|
## `starci-grammar/page-tabs-in-header`
|
|
10
10
|
|
|
11
|
-
A `Tabs` element that is the first element child of a `Page
|
|
11
|
+
A `Tabs` element that is the first element child of a `Page` is a finding, reported on the `Tabs`. Whitespace text and JSX comments are not children. A `Tabs` lower in the body, or inside a body section, is region tabs and is not judged.
|
|
12
12
|
|
|
13
13
|
**Invalid** (`src/features/pages/ConnectionPage/component.tsx`)
|
|
14
14
|
|
|
@@ -39,7 +39,7 @@ Findings, each reported on the element:
|
|
|
39
39
|
|
|
40
40
|
- `sibling`: an element that draws the `Page` has an element sibling in its parent, in a page owner or a layout owner.
|
|
41
41
|
- `twice`: an element that draws a `Page` sits inside another one (a `Page` in a `Page`, or a block that draws one inside a `Page` or inside the root block), or sits in a page owner mounted by a route under a segment layout that draws the `Page`; the finding names that layout.
|
|
42
|
-
- `part`:
|
|
42
|
+
- `part`: a `PageHeader` or `PageContainer` imported from `@starci/grammar` (by name or through a namespace) in a page or layout owner: both are Page's own parts and are not exported, so this finding is the import.
|
|
43
43
|
- `missing`: a page owner file draws JSX but nothing that draws the `Page`, and draws no element imported from its own pure half, reported on its first element: the page has no frame at all.
|
|
44
44
|
|
|
45
45
|
A `Page` (or the root block) alone in a fragment or a provider, and one per branch of a conditional, are legal; the root block's children are the page body. Not judged for `missing`:
|
|
@@ -54,6 +54,8 @@ A workbench page is an ordinary page: it draws its `Page` like any other, usuall
|
|
|
54
54
|
**Invalid** (`src/features/pages/ConnectionPage/component.tsx`)
|
|
55
55
|
|
|
56
56
|
```tsx
|
|
57
|
+
import { PageHeader, PageContainer } from "@starci/grammar/core"
|
|
58
|
+
|
|
57
59
|
<>
|
|
58
60
|
<PageHeader title="Main account" />
|
|
59
61
|
<PageContainer><WebhookCard /></PageContainer>
|
|
@@ -99,9 +101,7 @@ A workbench page is an ordinary page: it draws its `Page` like any other, usuall
|
|
|
99
101
|
|
|
100
102
|
```tsx
|
|
101
103
|
<Page chrome="bleed" header={{ breadcrumbs }}>
|
|
102
|
-
<
|
|
103
|
-
<SurfaceCard ariaLabel={label} composition="joined" height="fill">{rail}{thread}</SurfaceCard>
|
|
104
|
-
</FillViewport>
|
|
104
|
+
<SurfaceCard ariaLabel={label} composition="joined" height="fill">{rail}{thread}</SurfaceCard>
|
|
105
105
|
</Page>
|
|
106
106
|
```
|
|
107
107
|
|
package/docs/status-colors.md
CHANGED
|
@@ -1,34 +1,43 @@
|
|
|
1
|
-
# Status
|
|
1
|
+
# Status colors: content on a tone background takes the soft pair, a lone mark takes the tone
|
|
2
2
|
|
|
3
|
-
Law module: `status-colors.ts`. Catalogue: R61 FE_STYLE_TOKEN_ONLY (the
|
|
3
|
+
Law module: `status-colors.ts`. Catalogue: R61 FE_STYLE_TOKEN_ONLY (the status-pair rule for class names; no gate judges the colours an app's theme gives the pair).
|
|
4
4
|
|
|
5
|
-
A status tone
|
|
5
|
+
A status tone `x` (`success`, `warning`, `danger`, `info`, read from `lib/status-tones.generated.ts`, which is generated from the grammar with the stylelint vocabulary) paints in two ways. Content that sits on a background of the tone uses the pair `x-soft` and `x-soft-foreground`, the way a HeroUI flat Chip does. A mark that stands alone, with no background of the tone behind it, uses `x` itself. A solid fill takes `x-foreground`. The owner's words: "TEXT TRÊN BG THÌ X-SOFT VÀ X-SOFT-FOREGROUND, CÒN NẾU X ĐỘC LẬP THÌ ĐỂ X LUN" (ruling `status-soft-pair-on-background`).
|
|
6
6
|
|
|
7
7
|
Every rule below is an error in `coreGrammarConfig`; none can be switched off or suppressed inline.
|
|
8
8
|
|
|
9
9
|
## `starci-grammar/status-text-uses-soft-foreground`
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Two findings, both read from `className`/`class`, from `cn()`/`clsx()` arguments, conditionals, arrays, constants and `classes` entries, with any variant, opacity or `!`:
|
|
12
|
+
|
|
13
|
+
- **on a tint** (message `onTint`): a class string that sets `bg-<tone>-soft` and also paints text, an icon or a text decoration with the solid tone of the same tone: `text-<tone>`, `fill-<tone>`, `stroke-<tone>`, `decoration-<tone>`. The content on the tint takes `text-<tone>-soft-foreground`.
|
|
14
|
+
- **alone** (message `alone`): `text-<tone>-soft-foreground` (or `fill-`, `stroke-`, `decoration-`) in the `className` of an element when neither that element nor an element that encloses it in the same file sets `bg-<tone>-soft`. A mark with no tint behind it takes `text-<tone>`. A constant, an array in a constant or a `classes` entry is not judged for this finding, since the element that wears it is not in view; a component that receives its tint from another file is judged where the tint is written.
|
|
15
|
+
|
|
16
|
+
On Offset Pop (`settings.starci.hfs.grammar` is `offset-pop`) the **alone** finding is not reported: the family's light-theme tones are pastel fills and a bare mark wears the soft foreground there (owner choice "1. Pastel"); its dark theme keeps bare x, which the rule does not refuse either.
|
|
17
|
+
|
|
18
|
+
A bare solid tone (`text-success` with no `bg-success-soft` on the element), the pair on its tint, a solid fill with its own ink, a solid border, ring or outline, and a tone beside a tint of another tone are not findings.
|
|
12
19
|
|
|
13
20
|
**Invalid** (`src/components/leaves/StatusText/index.tsx`)
|
|
14
21
|
|
|
15
22
|
```tsx
|
|
16
|
-
<span className="text-success" />
|
|
17
|
-
<
|
|
23
|
+
<span className="bg-success-soft text-success" />
|
|
24
|
+
<span className="text-danger-soft-foreground" />
|
|
18
25
|
```
|
|
19
26
|
|
|
20
27
|
**Valid** (`src/components/leaves/StatusText/index.tsx`)
|
|
21
28
|
|
|
22
29
|
```tsx
|
|
23
30
|
<span className="bg-success-soft text-success-soft-foreground" />
|
|
31
|
+
<span className="text-success" />
|
|
32
|
+
<div className="bg-danger-soft"><span className="text-danger-soft-foreground" /></div>
|
|
24
33
|
<button className="bg-success text-success-foreground" />
|
|
25
34
|
<div className="border-danger ring-2 ring-warning" />
|
|
26
35
|
```
|
|
27
36
|
|
|
28
37
|
**Finding code:** `FE_STYLE_TOKEN_ONLY`
|
|
29
38
|
|
|
30
|
-
**Why:** `<file>` colours
|
|
39
|
+
**Why:** `<file>` colours status content against the owner's pair rule (`<what>`): content on a `bg-<tone>-soft` tint paints with the solid tone, or a mark with no tint behind it paints with the soft foreground.
|
|
31
40
|
|
|
32
|
-
**Fix:**
|
|
41
|
+
**Fix:** Content on a background of the tone takes the pair: `bg-<tone>-soft` with `text-<tone>-soft-foreground`. A mark that stands alone, with no background of the tone, takes the tone itself: `text-<tone>`. A solid fill takes `bg-<tone>` with `text-<tone>-foreground`.
|
|
33
42
|
|
|
34
43
|
Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
|