@starci/eslint-grammar-core 0.45.1 → 0.46.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 +10 -0
- package/dist/app-shell.d.ts +4 -1
- package/dist/app-shell.js +28 -7
- package/dist/grammar-boundary.d.ts +6 -0
- package/dist/grammar-boundary.js +1 -1
- package/dist/index.js +2 -0
- package/dist/lib/why.js +7 -2
- package/dist/mascot.d.ts +1 -1
- package/dist/mascot.js +4 -3
- package/dist/media.d.ts +25 -0
- package/dist/media.js +56 -0
- package/docs/media.md +44 -0
- package/package.json +3 -3
- package/runtime/knowledge/patterns/fe/ui.yaml +1 -0
- package/runtime/knowledge/ui/composition/app-shell.yaml +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.46.1 - 2026-11-18
|
|
4
|
+
|
|
5
|
+
- Changed: the family version 0.46.1 (IntervalChart and FunnelChart in @starci/grammar). No rule change.
|
|
6
|
+
|
|
7
|
+
## 0.46.0 - 2026-11-18
|
|
8
|
+
|
|
9
|
+
- New rule `starci-grammar/no-raw-media` (R442 `FE_RAW_MEDIA_ELEMENT`): a raw `<img>`, `<video>` or `<picture>` in app source is refused with the component to use (`Image`, `Illustration`, `Video`). It applies where `no-raw-structural-element` does (app source and workspace packages except the `<family>-ui` package, the Grammar's own implementation) and leaves Freestyle regions alone. It overlaps the canon `no-native-img` (R62 `FE_NATIVE_IMAGE`, which still points at `next/image`): see the report.
|
|
10
|
+
- Changed: `generated-art-in-mascot-or-media-frame` (R338) admits `Illustration` beside `Mascot` and `MediaFrame`.
|
|
11
|
+
- Changed (`eslint-grammar-core`, a MINOR with the media lane; `no-shell-bottom-tabs`, R316 `FE_APP_SHELL_BOTTOM_TABS`, `src/app-shell.ts`): a Grammar `BottomNav` passes only as the `compactNavigation` of a `WorkspaceShell` (inline, through a `const`, or through an import alias); a hand-made bottom tab bar (now also a local component named `BottomNav`), any other `compactNavigation` and a `BottomNav` anywhere else are refused. Spec: six valid and five invalid cases added. FE-APP-SHELL-4 (`contexts/ui/composition.md`, the `app-shell.yaml` and `rules.yaml` R316 copies in `eslint-grammar-core` and `hfs`, both playbooks, `contract.md`, `contexts/hfs`, the lint `why` text and the failure-code title) is amended the same way (owner decision 2026-11-18).
|
|
12
|
+
|
|
3
13
|
## 0.45.1 - 2026-11-18
|
|
4
14
|
|
|
5
15
|
- Version: moves with the Grammar family (@starci/grammar 0.45.1: a content-sized Popover, `edgeTone` on rows). No rule changed.
|
package/dist/app-shell.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
2
|
/** The app frame is the fixed-viewport Grammar shell; hand-written frame landmarks are rejected. */
|
|
3
3
|
export declare const appShellFrame: Rule.RuleModule;
|
|
4
|
-
/**
|
|
4
|
+
/**
|
|
5
|
+
* FE-APP-SHELL-4: the one bottom bar is the Grammar `BottomNav`, and only as the `compactNavigation` of a `WorkspaceShell` (the phone slot). A hand-rolled bottom
|
|
6
|
+
* tab bar, any other `compactNavigation` and a `BottomNav` anywhere else are refused.
|
|
7
|
+
*/
|
|
5
8
|
export declare const noShellBottomTabs: Rule.RuleModule;
|
|
6
9
|
/** Every visible control in a navbar band uses the shared control height through its published size API. */
|
|
7
10
|
export declare const navbarControlSize: Rule.RuleModule;
|
package/dist/app-shell.js
CHANGED
|
@@ -10,7 +10,7 @@ import { provesImportedBar, provesNavigationOpener } from "./lib/app-shell-owner
|
|
|
10
10
|
import { variableOf } from "@starci/eslint-canon-fe/lib/bindings.mjs";
|
|
11
11
|
import { walk } from "@starci/eslint-canon-fe/lib/ast.mjs";
|
|
12
12
|
const CANON = "knowledge/ui/composition/app-shell.yaml";
|
|
13
|
-
const BOTTOM_TABS = /^(?:BottomNavigation|BottomTabBar|MobileBottomNav|MobileTabBar)$/;
|
|
13
|
+
const BOTTOM_TABS = /^(?:BottomNavigation|BottomTabBar|MobileBottomNav|MobileTabBar|BottomNav)$/;
|
|
14
14
|
const EXPECTED_CLUSTER = ["language:IconButton", "theme:Switch", "notifications:IconButton", "account:AvatarButton"];
|
|
15
15
|
/** The cluster of a shell with no notification source (a platform-admin shell with no workspace): notifications are required only where a read feeds them, so a shell without one may omit them. */
|
|
16
16
|
const NO_SOURCE_CLUSTER = EXPECTED_CLUSTER.filter((kind) => !kind.startsWith("notifications:"));
|
|
@@ -86,23 +86,44 @@ export const appShellFrame = defineRule({
|
|
|
86
86
|
} };
|
|
87
87
|
},
|
|
88
88
|
});
|
|
89
|
-
/**
|
|
89
|
+
/**
|
|
90
|
+
* FE-APP-SHELL-4: the one bottom bar is the Grammar `BottomNav`, and only as the `compactNavigation` of a `WorkspaceShell` (the phone slot). A hand-rolled bottom
|
|
91
|
+
* tab bar, any other `compactNavigation` and a `BottomNav` anywhere else are refused.
|
|
92
|
+
*/
|
|
90
93
|
export const noShellBottomTabs = defineRule({
|
|
91
|
-
meta: meta("FE_APP_SHELL_BOTTOM_TABS", "FE-APP-SHELL-4 keeps mobile navigation in the sidebar drawer.", {
|
|
92
|
-
bottom: "FE_APP_SHELL_BOTTOM_TABS: the app shell uses a mobile subnav opener and Sidebar drawer. Remove bottom tab
|
|
94
|
+
meta: meta("FE_APP_SHELL_BOTTOM_TABS", "FE-APP-SHELL-4 keeps mobile navigation in the sidebar drawer; the Grammar BottomNav stands only as the compactNavigation of a WorkspaceShell.", {
|
|
95
|
+
bottom: "FE_APP_SHELL_BOTTOM_TABS: the app shell uses a mobile subnav opener and Sidebar drawer. Remove the hand-made bottom tab bar; a BottomNav stands only as the compactNavigation of a WorkspaceShell, and compactNavigation holds nothing else.",
|
|
93
96
|
}),
|
|
94
97
|
create(context) {
|
|
95
98
|
if (!isProductSource(context))
|
|
96
99
|
return {};
|
|
97
|
-
|
|
100
|
+
/** The Grammar `BottomNav` openings seen, and those a shell holds as its `compactNavigation`. */
|
|
101
|
+
const bottomNavs = [];
|
|
102
|
+
const inShellSlot = new Set();
|
|
103
|
+
const keyOf = (opening) => `${opening.range[0]}:${opening.range[1]}`;
|
|
104
|
+
const isBottomNav = (value) => value?.type === "JSXElement" && grammarName(context, value.openingElement) === "BottomNav";
|
|
105
|
+
return {
|
|
106
|
+
JSXOpeningElement(node) {
|
|
98
107
|
const name = grammarName(context, node);
|
|
108
|
+
if (name === "BottomNav")
|
|
109
|
+
bottomNavs.push(node);
|
|
99
110
|
const appTab = name === null && node.name.type === "JSXIdentifier" && BOTTOM_TABS.test(node.name.name) && (ownsAppFrame(context, node) || visibleFromShell(context, node));
|
|
100
111
|
const compact = name === "WorkspaceShell" ? propOf(context, node, "compactNavigation") : null;
|
|
101
112
|
const value = compact ? resolveLocal(context, compact.value) : null;
|
|
102
113
|
const absent = value?.type === "Identifier" && value.name === "undefined" && !variableOf(context, value)?.defs.length;
|
|
103
|
-
if (
|
|
114
|
+
if (compact && compact.known && isBottomNav(value)) {
|
|
115
|
+
inShellSlot.add(keyOf(value.openingElement));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (name !== "BottomNav" && BOTTOM_TABS.test(name ?? "") || appTab || compact && !absent && (!compact.known || compact.value !== null || compact.present))
|
|
104
119
|
context.report({ node, messageId: "bottom" });
|
|
105
|
-
}
|
|
120
|
+
},
|
|
121
|
+
"Program:exit"() {
|
|
122
|
+
for (const opening of bottomNavs)
|
|
123
|
+
if (!inShellSlot.has(keyOf(opening)))
|
|
124
|
+
context.report({ node: opening, messageId: "bottom" });
|
|
125
|
+
},
|
|
126
|
+
};
|
|
106
127
|
},
|
|
107
128
|
});
|
|
108
129
|
const visitBar = (context, node, visit) => {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { Rule } from "eslint";
|
|
2
|
+
import type { ReaderContext } from "./lib/types.js";
|
|
2
3
|
/**
|
|
3
4
|
* The intrinsic elements of page structure and text, each with the grammar components that render it.
|
|
4
5
|
* Read against packages/grammar/src (`export const <Component>`); `grammar-boundary.spec.ts` fails when one is not exported.
|
|
5
6
|
*/
|
|
6
7
|
export declare const GRAMMAR_OWNERS: Readonly<Record<string, string>>;
|
|
8
|
+
/**
|
|
9
|
+
* True for a file that composes the grammar: app source (`fe.feature`, `fe.components`, `fe.route`, `fe.hooks`) and any
|
|
10
|
+
* workspace package but the `<family>-ui` package, whose components are the renderers.
|
|
11
|
+
*/
|
|
12
|
+
export declare const composesGrammar: (context: ReaderContext, file: string) => boolean;
|
|
7
13
|
/** No raw structural or text element in app source or in a package that composes the grammar. */
|
|
8
14
|
export declare const noRawStructuralElement: Rule.RuleModule;
|
|
9
15
|
/** The rules this law contributes to the plugin. */
|
package/dist/grammar-boundary.js
CHANGED
|
@@ -47,7 +47,7 @@ const RENDERER_SLOT = "fe.package.ui";
|
|
|
47
47
|
* True for a file that composes the grammar: app source (`fe.feature`, `fe.components`, `fe.route`, `fe.hooks`) and any
|
|
48
48
|
* workspace package but the `<family>-ui` package, whose components are the renderers.
|
|
49
49
|
*/
|
|
50
|
-
const composesGrammar = (context, file) => {
|
|
50
|
+
export const composesGrammar = (context, file) => {
|
|
51
51
|
const hfs = hfsOf(context);
|
|
52
52
|
const slot = hfs.slotOf(file);
|
|
53
53
|
if (slot === null || slot === RENDERER_SLOT)
|
package/dist/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import { rules as iconRules } from "./icon.js";
|
|
|
16
16
|
import { rules as layoutTwoAxisRules } from "./layout-two-axis.js";
|
|
17
17
|
import { rules as linkLookRules } from "./link-look.js";
|
|
18
18
|
import { rules as mascotRules } from "./mascot.js";
|
|
19
|
+
import { rules as mediaRules } from "./media.js";
|
|
19
20
|
import { rules as menuEntriesRules } from "./menu-entries.js";
|
|
20
21
|
import { rules as messageSurfacesRules } from "./message-surfaces.js";
|
|
21
22
|
import { rules as noRawScrollRules } from "./no-raw-scroll.js";
|
|
@@ -60,6 +61,7 @@ const CONTRIBUTIONS = [
|
|
|
60
61
|
{ law: "layout-two-axis", rules: layoutTwoAxisRules },
|
|
61
62
|
{ law: "link-look", rules: linkLookRules },
|
|
62
63
|
{ law: "mascot", rules: mascotRules },
|
|
64
|
+
{ law: "media", rules: mediaRules },
|
|
63
65
|
{ law: "menu-entries", rules: menuEntriesRules },
|
|
64
66
|
{ law: "message-surfaces", rules: messageSurfacesRules },
|
|
65
67
|
{ law: "no-raw-scroll", rules: noRawScrollRules },
|
package/dist/lib/why.js
CHANGED
|
@@ -109,6 +109,11 @@ export const why = {
|
|
|
109
109
|
en: "A `Mascot` in `<file>` names no `assetSlot`, so nothing ties the art it draws to the asset workflow's request.",
|
|
110
110
|
fix: "Pass `assetSlot` (the slot id of the request) and `assetSha256` once the file is delivered.",
|
|
111
111
|
},
|
|
112
|
+
"no-raw-media": {
|
|
113
|
+
code: "FE_RAW_MEDIA_ELEMENT",
|
|
114
|
+
en: "A raw `<img>`, `<video>` or `<picture>` in `<file>`: it reserves no ratio, loads at once and carries none of the Grammar's alt, rendition, caption, track or stream contract.",
|
|
115
|
+
fix: "Use `Image` (a picture with content: `alt` is required, `ratio`, `renditions` and `sizes`, `caption`, `zoom`), `Illustration` (decorative art: `compact` for art direction) or `Video` (`sources` of MP4, WebM, HLS or DASH, `poster`, `tracks`); a `staticsKey` names an asset of the app's statics.",
|
|
116
|
+
},
|
|
112
117
|
"navbar-cluster": {
|
|
113
118
|
code: "FE_NAVBAR_CLUSTER",
|
|
114
119
|
en: "Navbar action component kinds or order differ from the app-shell canon.",
|
|
@@ -201,8 +206,8 @@ export const why = {
|
|
|
201
206
|
},
|
|
202
207
|
"no-shell-bottom-tabs": {
|
|
203
208
|
code: "FE_APP_SHELL_BOTTOM_TABS",
|
|
204
|
-
en: "
|
|
205
|
-
fix: "Use WorkspaceShell navigationDrawer and Sidebar presentation=\"drawer\".",
|
|
209
|
+
en: "A hand-made bottom tab bar, or a BottomNav outside WorkspaceShell compactNavigation, replaces the required mobile sidebar drawer.",
|
|
210
|
+
fix: "Use WorkspaceShell navigationDrawer and Sidebar presentation=\"drawer\", or the Grammar BottomNav as the compactNavigation of the WorkspaceShell.",
|
|
206
211
|
},
|
|
207
212
|
"surface-in-surface": {
|
|
208
213
|
code: "FE_SURFACE_IN_SURFACE",
|
package/dist/mascot.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Rule } from "eslint";
|
|
|
6
6
|
* Generated art is a raster the asset workflow delivers under the public `/images/` tree, as `.webp` or `.png`. Drawn
|
|
7
7
|
* through a bare `Image` or `<img>` it takes whatever box its page gives it, so one mascot comes out at a different size on
|
|
8
8
|
* every screen and nothing ties the bytes to the slot that requested them. Grammar's `Mascot` owns the character scale
|
|
9
|
-
* (sm, md, lg, hero), and `MediaFrame` frames a scene
|
|
9
|
+
* (sm, md, lg, hero), `Illustration` owns decorative art (a ratio and an art-directed crop) and `MediaFrame` frames a scene; those three are its renderers.
|
|
10
10
|
*
|
|
11
11
|
* WHAT IT READS. A JSX `src` attribute whose value is statically a string (a literal, an expression container holding one,
|
|
12
12
|
* a template literal without expressions, or a `const` of the file initialised with one). A source computed at run time is
|
package/dist/mascot.js
CHANGED
|
@@ -7,7 +7,7 @@ import { defineFamilyRules, defineRule, exemptFreestyle } from "./lib/rule-contr
|
|
|
7
7
|
* Generated art is a raster the asset workflow delivers under the public `/images/` tree, as `.webp` or `.png`. Drawn
|
|
8
8
|
* through a bare `Image` or `<img>` it takes whatever box its page gives it, so one mascot comes out at a different size on
|
|
9
9
|
* every screen and nothing ties the bytes to the slot that requested them. Grammar's `Mascot` owns the character scale
|
|
10
|
-
* (sm, md, lg, hero), and `MediaFrame` frames a scene
|
|
10
|
+
* (sm, md, lg, hero), `Illustration` owns decorative art (a ratio and an art-directed crop) and `MediaFrame` frames a scene; those three are its renderers.
|
|
11
11
|
*
|
|
12
12
|
* WHAT IT READS. A JSX `src` attribute whose value is statically a string (a literal, an expression container holding one,
|
|
13
13
|
* a template literal without expressions, or a `const` of the file initialised with one). A source computed at run time is
|
|
@@ -21,6 +21,7 @@ import { defineFamilyRules, defineRule, exemptFreestyle } from "./lib/rule-contr
|
|
|
21
21
|
export const GENERATED_ART = /^\/images\/.+\.(?:webp|png)(?:[?#].*)?$/i;
|
|
22
22
|
/** The components that render generated art: the element itself, or an ancestor that frames it. */
|
|
23
23
|
const RENDERER = "Mascot";
|
|
24
|
+
const ART_RENDERERS = new Set([RENDERER, "Illustration"]);
|
|
24
25
|
const FRAME = "MediaFrame";
|
|
25
26
|
/** The element name of a JSX name: `Mascot`, or `G.Mascot` as `Mascot`. */
|
|
26
27
|
const nameOf = (name) => {
|
|
@@ -84,7 +85,7 @@ export const generatedArtInMascotOrMediaFrame = exemptFreestyle(defineRule({
|
|
|
84
85
|
docs: { description: "R338: generated art (a .webp or .png under /images/) renders only through Grammar's Mascot or inside a MediaFrame." },
|
|
85
86
|
schema: [],
|
|
86
87
|
messages: {
|
|
87
|
-
outside: "`{{src}}` is generated art drawn by `<{{element}}>`, outside Grammar's `Mascot` and `MediaFrame`: it takes whatever box this page gives it, so the same art comes out at a different size on every screen. Render a character with `<Mascot src size assetSlot />` (sm, md, lg or hero) or frame a scene
|
|
88
|
+
outside: "`{{src}}` is generated art drawn by `<{{element}}>`, outside Grammar's `Mascot`, `Illustration` and `MediaFrame`: it takes whatever box this page gives it, so the same art comes out at a different size on every screen. Render a character with `<Mascot src size assetSlot />` (sm, md, lg or hero), decorative art with `<Illustration src ratio />`, or frame a scene in `<MediaFrame assetSlot>`.",
|
|
88
89
|
},
|
|
89
90
|
},
|
|
90
91
|
create(context) {
|
|
@@ -102,7 +103,7 @@ export const generatedArtInMascotOrMediaFrame = exemptFreestyle(defineRule({
|
|
|
102
103
|
if (opening.type !== "JSXOpeningElement")
|
|
103
104
|
return;
|
|
104
105
|
const element = nameOf(opening.name);
|
|
105
|
-
if (element
|
|
106
|
+
if ((element !== null && ART_RENDERERS.has(element)) || insideFrame(opening))
|
|
106
107
|
return;
|
|
107
108
|
context.report({ node: attribute, messageId: "outside", data: { src, element: element ?? "element" } });
|
|
108
109
|
},
|
package/dist/media.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
/**
|
|
3
|
+
* The media law (HFS R442 `FE_RAW_MEDIA_ELEMENT`): pictures, video and decorative art are drawn by the Grammar's `Image`,
|
|
4
|
+
* `Video` and `Illustration`, never by a raw `<img>`, `<video>` or `<picture>`.
|
|
5
|
+
*
|
|
6
|
+
* A raw element holds no ratio before its bytes arrive (the page jumps), loads at once whatever the viewport, draws no
|
|
7
|
+
* loading or failure state, picks no rendition for the screen, carries no required `alt`, no WebVTT track contract and no
|
|
8
|
+
* stream player, and wears no corner radius of the theme. The Grammar's three components own all of that, once.
|
|
9
|
+
*
|
|
10
|
+
* WHAT IT READS. The JSX elements `img`, `video` and `picture`. `audio`, `source` and `track` are not refused: the Grammar
|
|
11
|
+
* has no component for them (`source` and `track` only ever live inside the refused elements).
|
|
12
|
+
*
|
|
13
|
+
* WHERE IT APPLIES. The files `no-raw-structural-element` judges (app source that composes the Grammar and any workspace
|
|
14
|
+
* package but the `<family>-ui` package, whose components are the renderers: the Grammar's own implementation is the one
|
|
15
|
+
* place a raw media element belongs). A Freestyle region's raw elements are exempt, and an element with a spread attribute is
|
|
16
|
+
* judged like any other.
|
|
17
|
+
*/
|
|
18
|
+
/** The raw media elements and the Grammar component that draws what each one stands for. */
|
|
19
|
+
export declare const MEDIA_OWNERS: Readonly<Record<string, string>>;
|
|
20
|
+
/** No raw `<img>`, `<video>` or `<picture>` in app source: the Grammar's media components draw them. */
|
|
21
|
+
export declare const noRawMedia: Rule.RuleModule;
|
|
22
|
+
/** The rules this law contributes to the plugin. */
|
|
23
|
+
export declare const rules: Record<string, Rule.RuleModule>;
|
|
24
|
+
/** Every rule of this law is an error. */
|
|
25
|
+
export declare const recommended: Record<string, "error">;
|
package/dist/media.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defineFamilyRules, defineRule, exemptFreestyle } from "./lib/rule-contract.js";
|
|
2
|
+
import { composesGrammar } from "./grammar-boundary.js";
|
|
3
|
+
/**
|
|
4
|
+
* The media law (HFS R442 `FE_RAW_MEDIA_ELEMENT`): pictures, video and decorative art are drawn by the Grammar's `Image`,
|
|
5
|
+
* `Video` and `Illustration`, never by a raw `<img>`, `<video>` or `<picture>`.
|
|
6
|
+
*
|
|
7
|
+
* A raw element holds no ratio before its bytes arrive (the page jumps), loads at once whatever the viewport, draws no
|
|
8
|
+
* loading or failure state, picks no rendition for the screen, carries no required `alt`, no WebVTT track contract and no
|
|
9
|
+
* stream player, and wears no corner radius of the theme. The Grammar's three components own all of that, once.
|
|
10
|
+
*
|
|
11
|
+
* WHAT IT READS. The JSX elements `img`, `video` and `picture`. `audio`, `source` and `track` are not refused: the Grammar
|
|
12
|
+
* has no component for them (`source` and `track` only ever live inside the refused elements).
|
|
13
|
+
*
|
|
14
|
+
* WHERE IT APPLIES. The files `no-raw-structural-element` judges (app source that composes the Grammar and any workspace
|
|
15
|
+
* package but the `<family>-ui` package, whose components are the renderers: the Grammar's own implementation is the one
|
|
16
|
+
* place a raw media element belongs). A Freestyle region's raw elements are exempt, and an element with a spread attribute is
|
|
17
|
+
* judged like any other.
|
|
18
|
+
*/
|
|
19
|
+
/** The raw media elements and the Grammar component that draws what each one stands for. */
|
|
20
|
+
export const MEDIA_OWNERS = Object.freeze({
|
|
21
|
+
img: "`Image` (a picture with content) or `Illustration` (decorative art, with `alt` left empty)",
|
|
22
|
+
picture: "`Illustration` with `compact` for art direction, or `Image` with `renditions` and `sizes` for resolution switching",
|
|
23
|
+
video: "`Video` with `sources`, `poster` and `tracks`",
|
|
24
|
+
});
|
|
25
|
+
/** No raw `<img>`, `<video>` or `<picture>` in app source: the Grammar's media components draw them. */
|
|
26
|
+
export const noRawMedia = exemptFreestyle(defineRule({
|
|
27
|
+
meta: {
|
|
28
|
+
type: "problem",
|
|
29
|
+
docs: { description: "R442: a picture, a video or decorative art is a Grammar Image, Video or Illustration, never a raw <img>, <video> or <picture>." },
|
|
30
|
+
schema: [],
|
|
31
|
+
messages: {
|
|
32
|
+
raw: "A raw `<{{tag}}>`. It reserves no ratio (the page jumps when it loads), loads at once, draws no loading or failure state and carries none of the Grammar's alt, rendition, caption, track or stream contract. Use {{owner}}. If the Grammar cannot express this media, add the component or prop to the Grammar rather than drawing it here.",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
create(context) {
|
|
36
|
+
const file = context.filename || context.getFilename();
|
|
37
|
+
if (!composesGrammar(context, file))
|
|
38
|
+
return {};
|
|
39
|
+
return {
|
|
40
|
+
JSXOpeningElement(node) {
|
|
41
|
+
if (node.name.type !== "JSXIdentifier")
|
|
42
|
+
return;
|
|
43
|
+
const owner = Object.hasOwn(MEDIA_OWNERS, node.name.name) ? MEDIA_OWNERS[node.name.name] ?? null : null;
|
|
44
|
+
if (owner !== null)
|
|
45
|
+
context.report({ node, messageId: "raw", data: { tag: node.name.name, owner } });
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
/** The rules this law contributes to the plugin. */
|
|
51
|
+
export const rules = {
|
|
52
|
+
"no-raw-media": noRawMedia,
|
|
53
|
+
};
|
|
54
|
+
defineFamilyRules(rules, "knowledge/hfs/rules.yaml#R442");
|
|
55
|
+
/** Every rule of this law is an error. */
|
|
56
|
+
export const recommended = Object.fromEntries(Object.keys(rules).map((name) => [`starci-grammar/${name}`, "error"]));
|
package/docs/media.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Media renders through Image, Video and Illustration
|
|
2
|
+
|
|
3
|
+
Law module: `media.ts`. Catalogue: R442 FE_RAW_MEDIA_ELEMENT.
|
|
4
|
+
|
|
5
|
+
A picture, a video or decorative art is drawn by the Grammar's `Image`, `Video` or `Illustration`. A raw `<img>`,
|
|
6
|
+
`<video>` or `<picture>` reserves no ratio before its bytes arrive (the page jumps), loads at once whatever the viewport,
|
|
7
|
+
draws no loading or failure state, picks no rendition for the screen and carries none of the Grammar's contract: a required
|
|
8
|
+
`alt`, a caption, a zoom, WebVTT tracks, a stream player, the theme's one corner radius. The three components own that once.
|
|
9
|
+
|
|
10
|
+
The rule is an error in `coreGrammarConfig`; it cannot be switched off or suppressed inline. It applies to the files
|
|
11
|
+
`no-raw-structural-element` judges: app source that composes the Grammar and any workspace package except the
|
|
12
|
+
`<family>-ui` package, whose components are the renderers (the Grammar's own implementation is the one place a raw media
|
|
13
|
+
element belongs). The raw elements of a `Freestyle` region are exempt. `audio` is not refused: the Grammar has no component
|
|
14
|
+
for it.
|
|
15
|
+
|
|
16
|
+
## `starci-grammar/no-raw-media`
|
|
17
|
+
|
|
18
|
+
Every JSX `img`, `picture` and `video` element is a finding, and each finding names the component that draws what the tag
|
|
19
|
+
stands for:
|
|
20
|
+
|
|
21
|
+
| Raw element | Use |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `img` | `Image` (a picture with content), or `Illustration` (decorative art, `alt` empty) |
|
|
24
|
+
| `picture` | `Illustration` with `compact` (art direction), or `Image` with `renditions` and `sizes` (resolution switching) |
|
|
25
|
+
| `video` | `Video` with `sources`, `poster` and `tracks` |
|
|
26
|
+
|
|
27
|
+
**Invalid** (`src/components/blocks/Feed/component.tsx`)
|
|
28
|
+
|
|
29
|
+
```tsx
|
|
30
|
+
<img src="/team.webp" alt="The team" />
|
|
31
|
+
<video src="/intro.mp4" controls />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Valid**
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
<Image staticsKey="photos/team.webp" alt="The team" ratio="4:3" renditions={[{ staticsKey: "photos/team-640.webp", width: 640 }]} sizes="100vw" />
|
|
38
|
+
<Video title="Introduction" sources={[{ src: "/intro.webm", type: "video/webm" }, { src: "/intro.mp4", type: "video/mp4" }]} poster={{ src: "/intro.jpg" }} />
|
|
39
|
+
<Illustration staticsKey="illustrations/hero/landing.webp" ratio="1:1" compact={{ staticsKey: "illustrations/hero/landing-narrow.webp", ratio: "4:3" }} />
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Finding code:** `FE_RAW_MEDIA_ELEMENT`
|
|
43
|
+
|
|
44
|
+
Rule ownership: [FE-RULE-OWNERSHIP](../../../contexts/code/fe/README.md#the-placement-test-fe-rule-ownership).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@starci/eslint-grammar-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
4
4
|
"description": "ESLint rules for the core Grammar's component, token and composition contracts.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -68,6 +68,6 @@
|
|
|
68
68
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
69
69
|
"typescript": "^6.0.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
72
|
-
"starciSource": "
|
|
71
|
+
"gitHead": "2686938269df276a2bdf4018f10596cd2390fdff",
|
|
72
|
+
"starciSource": "24f7a105e8236f20f99c537e0eb7c1a2cb64ac25ae76262759f0f95aece1ee01"
|
|
73
73
|
}
|
|
@@ -114,7 +114,9 @@ rules:
|
|
|
114
114
|
with the design system's target clearance; it opens the sidebar drawer.
|
|
115
115
|
Inline navigation is hidden at compact widths; the shell's navigation-drawer contract or a
|
|
116
116
|
compact header containing a leading drawer supplies the opener and the drawer's sidebar.
|
|
117
|
-
The shell has no tabs in that row
|
|
117
|
+
The shell has no tabs in that row. The one bottom bar is the Grammar BottomNav as the
|
|
118
|
+
compactNavigation of the WorkspaceShell (two to five places, its more place a bottom sheet,
|
|
119
|
+
drawn below 48rem); a hand-made bottom tab bar and a BottomNav anywhere else are refused.
|
|
118
120
|
- id: case-2
|
|
119
121
|
when: The mobile sidebar opens
|
|
120
122
|
assert: |-
|