eslint-plugin-kerfjs 5.0.0-beta.122 → 5.0.0-beta.124
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/README.md +1 -0
- package/docs/rules/no-generated-view-edits.md +42 -0
- package/docs/rules/ui-composition.md +28 -1
- package/docs/rules/ui-preferences.md +23 -0
- package/docs/rules/ui-wiring.md +2 -0
- package/index.js +7 -1
- package/lib/rules/no-generated-view-edits.js +81 -0
- package/lib/rules/ui-composition.js +59 -0
- package/lib/rules/ui-preferences.js +46 -1
- package/lib/rules/ui-wiring.js +17 -4
- package/lib/ui-contract.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -121,6 +121,7 @@ Use flat config (`eslint.config.js`), shown above. The `legacy-recommended` expo
|
|
|
121
121
|
| [`prefer-attr-selector`](docs/rules/prefer-attr-selector.md) | — (rename-safety nudge for `delegate()` selectors) | `warn` |
|
|
122
122
|
| [`no-raw-with-dynamic-arg`](docs/rules/no-raw-with-dynamic-arg.md) | — (XSS audit trail) | `warn` |
|
|
123
123
|
| [`ai-assistant-configs`](docs/rules/ai-assistant-configs.md) | — (project hygiene) | `warn` |
|
|
124
|
+
| [`no-generated-view-edits`](docs/rules/no-generated-view-edits.md) | — (generated Kerf UI view modules are read-only) | `error` |
|
|
124
125
|
| [`ui-public-boundaries`](docs/rules/ui-public-boundaries.md) | — (cataloged classes/tokens; component anatomy on app elements) | `error` |
|
|
125
126
|
| [`ui-component-ownership`](docs/rules/ui-component-ownership.md) | — (configure components, never override them) | `error` |
|
|
126
127
|
| [`ui-composition`](docs/rules/ui-composition.md) | — (cataloged parents and zones) | `error` |
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# `kerfjs/no-generated-view-edits`
|
|
2
|
+
|
|
3
|
+
Disallow hand edits to generated Kerf UI view modules (`*.view.ts`, `*.view.js`, `*.view.d.ts`).
|
|
4
|
+
|
|
5
|
+
A Kerf UI view document (`*.kui.json`) is the source of truth for a screen's composition. `kerf-ui-view generate` turns it into a read-only module that your application imports. You put state, handlers, slots, and wiring in **your own** files; editing the generated module would be lost on the next regeneration and would hide the contract changes the TypeScript compiler is meant to report.
|
|
6
|
+
|
|
7
|
+
The generator records a digest of the module body in its header. This rule recomputes it, so it needs no access to the document:
|
|
8
|
+
|
|
9
|
+
- **`edited`**: the body no longer matches the header's body digest, or the
|
|
10
|
+
recorded `kui-contract` line no longer matches the contract digest.
|
|
11
|
+
- **`header`**: the `kui-view` / `kui-contract` header lines are damaged.
|
|
12
|
+
- **`missing`**: a `*.view.ts` sits beside a `.kui.json` document but is not a generated module.
|
|
13
|
+
|
|
14
|
+
Line-ending conversion (CRLF checkouts) is ignored. A `*.view.ts` with no document beside it is not checked, so unrelated files that happen to use the suffix stay unaffected.
|
|
15
|
+
|
|
16
|
+
## ❌ Incorrect
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
// inbox.view.ts — GENERATED by kerf-ui-view from inbox.kui.json — do not edit.
|
|
20
|
+
// …
|
|
21
|
+
export function renderInbox(inputs: InboxInputs, slots: InboxSlots): SafeHtml {
|
|
22
|
+
return Pane({ background: myOverride /* ← reported: hand edit */ });
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## ✅ Correct
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// inbox.ts — application-owned
|
|
30
|
+
import { renderInbox, wireInbox } from './inbox.view.js';
|
|
31
|
+
|
|
32
|
+
mount(root, () =>
|
|
33
|
+
renderInbox({ title: 'Inbox', items: items.value }, { detail }),
|
|
34
|
+
);
|
|
35
|
+
wireInbox(root, { compose: openComposer, 'open-item': ({ key }) => select(key) });
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
To change the layout, edit `inbox.kui.json` (in the editor or by hand) and run `kerf-ui-view generate`. To make a value configurable, promote the prop to a document param; the generated module then exposes it as an input.
|
|
39
|
+
|
|
40
|
+
Generated modules are formatted by the generator, so add `**/*.view.ts` (and `.view.js` / `.view.d.ts`) to `.prettierignore` as well.
|
|
41
|
+
|
|
42
|
+
See [`docs/26-ui-editor.md`](../../../docs/26-ui-editor.md) in the kerf repository.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `ui-composition`
|
|
2
2
|
|
|
3
|
-
Enforces composition facts published by the versioned UI catalog. `KUI-L201` reports a catalog component under a known, disallowed direct parent. `KUI-L202` reports a statically visible zone child—including an intrinsic or unknown JSX element—that is not one of the zone's cataloged `accepts` entries. `KUI-L203` reports a statically provable zone cardinality violation. `KUI-L204` reports a direct child that brings its own content-item inset into a parent configured to expect inset-free content. A zone participates only when it declares an explicit `jsx.prop` binding, including `children`; the rule never guesses that a zone id is a JSX prop. Toolbar, Pane, TabBar, TabBarItem, feedback, search, and layout validation is therefore catalog-driven rather than duplicated in rule-local component cases.
|
|
3
|
+
Enforces composition facts published by the versioned UI catalog. `KUI-L201` reports a catalog component under a known, disallowed direct parent. `KUI-L202` reports a statically visible zone child—including an intrinsic or unknown JSX element—that is not one of the zone's cataloged `accepts` entries. `KUI-L203` reports a statically provable zone cardinality violation. `KUI-L204` reports a direct child that brings its own content-item inset into a parent configured to expect inset-free content. `KUI-L205` reports a control or link written inside a component whose root is one. A zone participates only when it declares an explicit `jsx.prop` binding, including `children`; the rule never guesses that a zone id is a JSX prop. Toolbar, Pane, TabBar, TabBarItem, feedback, search, and layout validation is therefore catalog-driven rather than duplicated in rule-local component cases.
|
|
4
4
|
|
|
5
5
|
The parent check is intentionally conservative about the child: it runs only for a child that resolves to a cataloged entry (or a declared wrapper's roots) whose parents are `listed`. Its direct JSX parent may be any element the rule can see: a cataloged component, a declared wrapper (which counts as each of its roots), an intrinsic element such as `<div>`, or an unresolved component, and any parent that is not a listed parent reports `KUI-L201`. Bound zone checks understand aliases, namespace imports, fragments, arrays, and conditional/logical branches, but expressions whose content cannot be resolved statically remain runtime and accessibility work. Accepted concepts that do not identify a catalog entry remain machine-readable guidance while the rule enforces their statically provable cardinality only. No autofix is offered because wrapping or moving UI changes structure and behavior.
|
|
6
6
|
Toolbar zones accept `KerfUiContent`, so the zone rule allows direct JSX
|
|
@@ -44,6 +44,33 @@ child prop supplied by an expression or a spread is not reported. Uncataloged
|
|
|
44
44
|
children (intrinsic elements, text) and entries whose geometry is not owned on
|
|
45
45
|
all three sides, such as `List`, are not checked.
|
|
46
46
|
|
|
47
|
+
## Controls inside controls (`KUI-L205`)
|
|
48
|
+
|
|
49
|
+
HTML forbids interactive content inside interactive content, and the browser
|
|
50
|
+
splits such markup, which breaks the component at render time. An entry may
|
|
51
|
+
declare `content.interactive` rules: `root` when the component's own root is a
|
|
52
|
+
native control or link (`Button`, `ListItem`, `ListItemLink`), `contains` when
|
|
53
|
+
it renders one inside (`Select`, `ListActionRow`), optionally only when one of
|
|
54
|
+
its `whenProps` is written (a `Chip` is a `<button>` only with `action`).
|
|
55
|
+
`content.exports` gives another JSX export of the entry its own rules. A
|
|
56
|
+
`root` or `contains` element anywhere inside a `root` element, through its
|
|
57
|
+
children, any of its props, fragments, conditional branches, and callbacks
|
|
58
|
+
such as `.map()`, reports `KUI-L205`. Raw Web Awesome tags with catalog rules,
|
|
59
|
+
such as `<wa-button>`, count too.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { Badge, Button, ListItem } from '@kerfjs/ui';
|
|
63
|
+
|
|
64
|
+
<ListItem action="open" label="Inbox" trailing={<Button>Go</Button>} />; // KUI-L205
|
|
65
|
+
<ListItem action="open" label="Inbox" trailing={<Badge>3</Badge>} />; // valid
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
A `whenProps` rule counts a prop as written when the attribute is present,
|
|
69
|
+
whatever expression supplies it, unless its value is a literal `false` or
|
|
70
|
+
`null`. A component defined elsewhere, or a prop supplied through a spread, is
|
|
71
|
+
not visible to the rule. `validateView` reports the same placement in a view
|
|
72
|
+
document as `KUI-V014`, from the same rules.
|
|
73
|
+
|
|
47
74
|
## Application and third-party wrappers
|
|
48
75
|
|
|
49
76
|
Beyond `@kerfjs/ui`'s own catalog, the rule loads every composition catalog the
|
|
@@ -15,4 +15,27 @@ A component matches whether it is rendered through an imported export (`<WaButto
|
|
|
15
15
|
|
|
16
16
|
Web Awesome elements no Kerf component replaces (`<wa-card>`, `<wa-carousel>`, the encouraged `<wa-popup>`) and unknown custom elements are not reported. The source file of a component declared in a profile catalog is exempt: that wrapper owns the element it renders, and the preference applies to its callers.
|
|
17
17
|
|
|
18
|
+
## Web Awesome appearance-scope classes (`KUI-L302`)
|
|
19
|
+
|
|
20
|
+
The rule also reports a JSX `class` or `className` whose static text (a string literal, or the literal parts of a template) contains `wa-light`, `wa-dark`, `wa-invert`, or `wa-theme-default`. Those classes need the Web Awesome theme and do nothing in a Kerf-only app; Kerf's own scope works everywhere:
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
<ContentItem className="wa-dark">…</ContentItem> // KUI-L302
|
|
24
|
+
<ContentItem scheme="dark">…</ContentItem> // the scheme prop
|
|
25
|
+
<div className="kui-dark">…</div> // or Kerf's scope class
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
An app that also loads `@kerfjs/ui/webawesome.css` keeps working either way (the bridge honors both), so this is a preference: record a narrow `KUI-L302` profile exception for code that must keep a Web Awesome scope.
|
|
29
|
+
|
|
30
|
+
## Raw forms (`KUI-L303`)
|
|
31
|
+
|
|
32
|
+
The rule also reports a native `<form>` element. A native form navigates the page when it is submitted, by a submit button or by Enter in a field, unless something cancels it. Render Kerf UI's `Form` from `@kerfjs/ui/form` instead and install `wireForms` from `@kerfjs/ui/wire-forms` once: the submission still reaches the application's `submit` handler, and the page never navigates.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<form onsubmit="save()">…</form> // KUI-L303
|
|
36
|
+
<Form action="save">…</Form> // with wireForms(root) installed
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`ui-wiring` reports a `Form` rendered without `wireForms` reachable (`KUI-L401`), so the two findings together cover both halves of the contract. The source file of a component declared in a profile catalog is exempt, as for `KUI-L301`; record a narrow `KUI-L303` profile exception for a form that must stay native.
|
|
40
|
+
|
|
18
41
|
`recommended-ui` treats the rule as a warning; `strict-ui` treats it as an error. Use a narrowly targeted `KUI-L301` profile exception when a documented application boundary cannot follow the preference. Component substitutions are not autofixed because their props and interaction contracts can differ.
|
package/docs/rules/ui-wiring.md
CHANGED
|
@@ -10,6 +10,8 @@ Declare application entry modules in the application UI profile to check root wi
|
|
|
10
10
|
|
|
11
11
|
Entry paths are relative to the workspace root. The rule follows relative imports, re-exports, and literal dynamic imports from each entry. An application-scoped obligation is checked at the entry if any reachable module renders its component; a recognized helper call or required registration import in any reachable module satisfies it. Reachable leaf modules need no duplicate wiring. A module outside every declared entry keeps the per-file check. A composition entry can set `wiring.scope` to `"module"` for wiring that must be installed beside its rendering code; omitted scope means `"application"`. Computed import paths and unresolved modules stay outside the static graph, so put them in a declared entry or check them separately. `KUI-L402` still checks the helper's call site.
|
|
12
12
|
|
|
13
|
+
An entry-level `KUI-L401` finding is reported at the entry, but exceptions are matched against the modules that render the component. A narrow exception on a view suppresses its missing-wiring obligation; if another reachable view uses the same component without an exception, the entry still reports it. Module-scoped wiring keeps its per-file exception behavior.
|
|
14
|
+
|
|
13
15
|
For server-rendered pages whose document loads a separate browser entry, pair the roots in one item:
|
|
14
16
|
|
|
15
17
|
```json
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import aiAssistantConfigs from './lib/rules/ai-assistant-configs.js';
|
|
2
|
+
import noGeneratedViewEdits from './lib/rules/no-generated-view-edits.js';
|
|
2
3
|
import noInlineJsxEventHandlers from './lib/rules/no-inline-jsx-event-handlers.js';
|
|
3
4
|
import noNestedMount from './lib/rules/no-nested-mount.js';
|
|
4
5
|
import noRawWithDynamicArg from './lib/rules/no-raw-with-dynamic-arg.js';
|
|
@@ -15,9 +16,10 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
|
15
16
|
import uiWiring from './lib/rules/ui-wiring.js';
|
|
16
17
|
|
|
17
18
|
const plugin = {
|
|
18
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
19
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.124' },
|
|
19
20
|
rules: {
|
|
20
21
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
22
|
+
'no-generated-view-edits': noGeneratedViewEdits,
|
|
21
23
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
|
22
24
|
'require-data-key-in-each': requireDataKeyInEach,
|
|
23
25
|
'require-delegate-disposer': requireDelegateDisposer,
|
|
@@ -44,6 +46,9 @@ const plugin = {
|
|
|
44
46
|
// would block too many legitimate uses without eslint-disable comments.
|
|
45
47
|
// `prefer-attr-selector` is `warn` — the literal-selector form is still
|
|
46
48
|
// correct at runtime; this rule nudges toward the rename-safe pattern.
|
|
49
|
+
// `no-generated-view-edits` is `error` — it only inspects files carrying a
|
|
50
|
+
// kerf-ui-view header (or sitting beside a `.kui.json`), and an edited
|
|
51
|
+
// generated module is always a defect: regeneration silently discards it.
|
|
47
52
|
// `require-delegate-disposer` is `warn` — the discarded-disposer form is
|
|
48
53
|
// still correct at runtime for page-lifetime roots, and downstream code
|
|
49
54
|
// that's been around since before the rule shipped needs a deprecation
|
|
@@ -57,6 +62,7 @@ const recommendedRules = {
|
|
|
57
62
|
'kerfjs/prefer-module-jsx-augmentation': 'error',
|
|
58
63
|
'kerfjs/prefer-attr-selector': 'warn',
|
|
59
64
|
'kerfjs/ai-assistant-configs': 'warn',
|
|
65
|
+
'kerfjs/no-generated-view-edits': 'error',
|
|
60
66
|
};
|
|
61
67
|
|
|
62
68
|
// Flat config (ESLint v9+) — consumers add this object to their config array.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
|
|
3
|
+
// Generated Kerf UI view modules (docs/26-ui-editor.md §5.2) are read-only:
|
|
4
|
+
// application code integrates through their exports and never edits them.
|
|
5
|
+
// The generator records a digest of the module body in its header; this rule
|
|
6
|
+
// recomputes it, so a hand edit (or a half-applied regeneration) is reported
|
|
7
|
+
// without access to the source document.
|
|
8
|
+
|
|
9
|
+
const STAMP =
|
|
10
|
+
/^\/\/ kui-view: \d+ contract (kui1:[0-9a-f]{16}) source kui1:[0-9a-f]{16} body (kui1:[0-9a-f]{16})$/;
|
|
11
|
+
const GENERATED = '// GENERATED by kerf-ui-view';
|
|
12
|
+
const HEADER_LINES = 3;
|
|
13
|
+
const VIEW_FILE = /\.view\.(?:d\.ts|ts|js)$/;
|
|
14
|
+
const MASK = 0xffffffffffffffffn;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* `kui1:` + 16 hex digits of the 64-bit FNV-1a hash of `text`'s UTF-8 bytes —
|
|
18
|
+
* the same digest `@kerfjs/ui/view`'s `viewDigest` computes (pinned by a
|
|
19
|
+
* parity test), duplicated so the plugin needs no runtime dependency on it.
|
|
20
|
+
*/
|
|
21
|
+
export function viewDigest(text) {
|
|
22
|
+
let hash = 0xcbf29ce484222325n;
|
|
23
|
+
for (const byte of new TextEncoder().encode(text)) {
|
|
24
|
+
hash ^= BigInt(byte);
|
|
25
|
+
hash = (hash * 0x100000001b3n) & MASK;
|
|
26
|
+
}
|
|
27
|
+
return `kui1:${hash.toString(16).padStart(16, '0')}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The `.kui.json` document a generated module's path would come from. */
|
|
31
|
+
const documentFor = (filename) => filename.replace(VIEW_FILE, '.kui.json');
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
meta: {
|
|
35
|
+
type: 'problem',
|
|
36
|
+
docs: {
|
|
37
|
+
description:
|
|
38
|
+
'Disallow hand edits to generated Kerf UI view modules (*.view.ts).',
|
|
39
|
+
url: 'https://github.com/brianwestphal/kerf/blob/main/eslint-plugin/docs/rules/no-generated-view-edits.md',
|
|
40
|
+
},
|
|
41
|
+
schema: [],
|
|
42
|
+
messages: {
|
|
43
|
+
edited:
|
|
44
|
+
'This generated view module was edited by hand (its body no longer matches its kerf-ui-view header). Regenerate it with `kerf-ui-view generate`; put behavior, overrides, and wiring in your own files that import it.',
|
|
45
|
+
header:
|
|
46
|
+
'This generated view module has a damaged kerf-ui-view header. Regenerate it with `kerf-ui-view generate` instead of editing it.',
|
|
47
|
+
missing:
|
|
48
|
+
'A module beside a `.kui.json` view document must be the generated one. Run `kerf-ui-view generate` rather than writing it by hand.',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
create(context) {
|
|
52
|
+
const filename = context.filename ?? context.getFilename();
|
|
53
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
54
|
+
return {
|
|
55
|
+
Program(node) {
|
|
56
|
+
// Git checkouts may convert line endings; the digest covers LF text.
|
|
57
|
+
const lines = sourceCode.text.replace(/\r\n/g, '\n').split('\n');
|
|
58
|
+
if (!lines[0]?.startsWith(GENERATED)) {
|
|
59
|
+
if (VIEW_FILE.test(filename) && existsSync(documentFor(filename))) {
|
|
60
|
+
context.report({ node, messageId: 'missing' });
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const stamp = STAMP.exec(lines[1] ?? '');
|
|
65
|
+
const contract = /^\/\/ kui-contract: (.*)$/.exec(lines[2] ?? '');
|
|
66
|
+
if (!stamp || !contract) {
|
|
67
|
+
context.report({ node, messageId: 'header' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// The body digest covers the code; the contract digest covers the
|
|
71
|
+
// recorded contract line (its canonical JSON).
|
|
72
|
+
if (
|
|
73
|
+
viewDigest(lines.slice(HEADER_LINES).join('\n')) !== stamp[2] ||
|
|
74
|
+
viewDigest(contract[1]) !== stamp[1]
|
|
75
|
+
) {
|
|
76
|
+
context.report({ node, messageId: 'edited' });
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
};
|
|
@@ -13,6 +13,7 @@ const PARENT_CODE = 'KUI-L201';
|
|
|
13
13
|
const ZONE_CODE = 'KUI-L202';
|
|
14
14
|
const CARDINALITY_CODE = 'KUI-L203';
|
|
15
15
|
const INSET_CODE = 'KUI-L204';
|
|
16
|
+
const INTERACTIVE_CODE = 'KUI-L205';
|
|
16
17
|
|
|
17
18
|
const emptyShape = () => ({ min: 0, max: 0, items: [] });
|
|
18
19
|
|
|
@@ -179,6 +180,51 @@ function bringsInset(entry, element) {
|
|
|
179
180
|
const rootsOf = (key, contract) =>
|
|
180
181
|
contract.entries.get(key)?.rendersAs ?? [key];
|
|
181
182
|
|
|
183
|
+
// Whether an element renders a native control or link as its root (`root`)
|
|
184
|
+
// or inside it (`contains`), from its entry's `content` rules (KF-VTFKX8, the
|
|
185
|
+
// JSX side of validateView's KUI-V014). An export with rules of its own uses
|
|
186
|
+
// them; a `whenProps` rule needs one of its props written, and a literal
|
|
187
|
+
// `false` or `null` does not count.
|
|
188
|
+
function interactiveOf(openingElement, registry, contract) {
|
|
189
|
+
const key =
|
|
190
|
+
jsxKey(openingElement.name, registry, contract) ??
|
|
191
|
+
customElementKey(openingElement.name, contract);
|
|
192
|
+
const content = contract.entries.get(key)?.content;
|
|
193
|
+
if (!content) return undefined;
|
|
194
|
+
const exportName = jsxExportName(openingElement.name, registry);
|
|
195
|
+
const rules =
|
|
196
|
+
content.exports?.[exportName]?.interactive ?? content.interactive ?? [];
|
|
197
|
+
const written = (prop) => {
|
|
198
|
+
const value = staticProp(openingElement, prop);
|
|
199
|
+
return (
|
|
200
|
+
openingElement.attributes.some(
|
|
201
|
+
(attribute) =>
|
|
202
|
+
attribute.type === 'JSXAttribute' && attribute.name.name === prop,
|
|
203
|
+
) && !(value.known && (value.value === false || value.value === null))
|
|
204
|
+
);
|
|
205
|
+
};
|
|
206
|
+
const kinds = rules
|
|
207
|
+
.filter((rule) => !rule.whenProps || rule.whenProps.some(written))
|
|
208
|
+
.map((rule) => rule.kind);
|
|
209
|
+
const kind = kinds.includes('root') ? 'root' : kinds[0];
|
|
210
|
+
return kind ? { key, kind } : undefined;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// The nearest enclosing element whose root is a control or link, through
|
|
214
|
+
// children, zone props, and callbacks written inside them.
|
|
215
|
+
function interactiveHost(openingElement, registry, contract) {
|
|
216
|
+
for (
|
|
217
|
+
let ancestor = openingElement.parent.parent;
|
|
218
|
+
ancestor;
|
|
219
|
+
ancestor = ancestor.parent
|
|
220
|
+
) {
|
|
221
|
+
if (ancestor.type !== 'JSXElement') continue;
|
|
222
|
+
const host = interactiveOf(ancestor.openingElement, registry, contract);
|
|
223
|
+
if (host?.kind === 'root') return host;
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
182
228
|
function boundZone(openingElement, zone, registry, contract) {
|
|
183
229
|
const prop = zone.jsx?.prop;
|
|
184
230
|
if (!prop) return undefined;
|
|
@@ -219,6 +265,8 @@ export default {
|
|
|
219
265
|
'KUI-L203: `{{component}}` zone `{{zone}}` requires {{cardinality}} direct children; statically found {{count}}.',
|
|
220
266
|
inset:
|
|
221
267
|
'KUI-L204: `{{child}}` brings its own content-item inset (1px border + 8px padding) into `{{component}}` with {{condition}}, which expects inset-free content and double-insets it; {{fix}}.',
|
|
268
|
+
interactive:
|
|
269
|
+
'KUI-L205: `{{child}}` renders a control or link, so it cannot sit inside `{{host}}`, which renders one itself; the browser splits the nested markup. Place it beside the host instead.',
|
|
222
270
|
},
|
|
223
271
|
},
|
|
224
272
|
create(context) {
|
|
@@ -237,6 +285,17 @@ export default {
|
|
|
237
285
|
},
|
|
238
286
|
JSXOpeningElement(node) {
|
|
239
287
|
if (!registry) return;
|
|
288
|
+
const inner = interactiveOf(node, registry, contract);
|
|
289
|
+
const host =
|
|
290
|
+
inner &&
|
|
291
|
+
!isExcepted(contract, INTERACTIVE_CODE, filename) &&
|
|
292
|
+
interactiveHost(node, registry, contract);
|
|
293
|
+
if (host)
|
|
294
|
+
context.report({
|
|
295
|
+
node: node.name,
|
|
296
|
+
messageId: 'interactive',
|
|
297
|
+
data: { child: inner.key, host: host.key },
|
|
298
|
+
});
|
|
240
299
|
const key = jsxKey(node.name, registry, contract);
|
|
241
300
|
const entry = contract.entries.get(key);
|
|
242
301
|
if (!entry) return;
|
|
@@ -11,6 +11,25 @@ import {
|
|
|
11
11
|
} from '../ui-contract.js';
|
|
12
12
|
|
|
13
13
|
const CODE = 'KUI-L301';
|
|
14
|
+
const SCOPE_CODE = 'KUI-L302';
|
|
15
|
+
const FORM_CODE = 'KUI-L303';
|
|
16
|
+
/** Web Awesome appearance-scope classes, which need its theme to do anything. */
|
|
17
|
+
const WA_SCOPE_CLASS =
|
|
18
|
+
/(?:^|\s)(wa-(?:light|dark|invert|theme-default))(?=\s|$)/g;
|
|
19
|
+
|
|
20
|
+
/** The static class text of a `class` / `className` attribute value. */
|
|
21
|
+
function classText(value) {
|
|
22
|
+
if (!value) return [];
|
|
23
|
+
if (value.type === 'Literal' && typeof value.value === 'string')
|
|
24
|
+
return [value.value];
|
|
25
|
+
if (value.type !== 'JSXExpressionContainer') return [];
|
|
26
|
+
const expression = value.expression;
|
|
27
|
+
if (expression.type === 'Literal' && typeof expression.value === 'string')
|
|
28
|
+
return [expression.value];
|
|
29
|
+
if (expression.type === 'TemplateLiteral')
|
|
30
|
+
return expression.quasis.map((quasi) => quasi.value.cooked ?? '');
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
14
33
|
|
|
15
34
|
export default {
|
|
16
35
|
meta: {
|
|
@@ -24,6 +43,10 @@ export default {
|
|
|
24
43
|
config: `${UI_CONTRACT_LOAD_CODE}: Kerf UI catalog/profile could not be loaded: {{error}}`,
|
|
25
44
|
preferred:
|
|
26
45
|
'KUI-L301: `{{actual}}` is discouraged for `{{concept}}`; this profile prefers `{{preferred}}`. {{rationale}}',
|
|
46
|
+
rawForm:
|
|
47
|
+
'KUI-L303: a raw `<form>` has no Kerf UI form contract. Render `Form` from `@kerfjs/ui/form` (with `wireForms` installed) so a submission reaches your `submit` handler without navigating the page.',
|
|
48
|
+
scope:
|
|
49
|
+
'KUI-L302: `{{name}}` is a Web Awesome appearance scope that does nothing without its theme. Use the `scheme` prop on ContentItem, Pane, NavStack, or TabNavigator, or the `.kui-light` / `.kui-dark` / `.kui-invert` scope class.',
|
|
27
50
|
},
|
|
28
51
|
},
|
|
29
52
|
create(context) {
|
|
@@ -31,6 +54,19 @@ export default {
|
|
|
31
54
|
const filename = context.filename ?? context.getFilename();
|
|
32
55
|
let registry;
|
|
33
56
|
return {
|
|
57
|
+
JSXAttribute(node) {
|
|
58
|
+
if (contract.error || isExcepted(contract, SCOPE_CODE, filename))
|
|
59
|
+
return;
|
|
60
|
+
const name = node.name.type === 'JSXIdentifier' ? node.name.name : '';
|
|
61
|
+
if (name !== 'class' && name !== 'className') return;
|
|
62
|
+
for (const text of classText(node.value))
|
|
63
|
+
for (const match of text.matchAll(WA_SCOPE_CLASS))
|
|
64
|
+
context.report({
|
|
65
|
+
node: node.value,
|
|
66
|
+
messageId: 'scope',
|
|
67
|
+
data: { name: match[1] },
|
|
68
|
+
});
|
|
69
|
+
},
|
|
34
70
|
Program(node) {
|
|
35
71
|
if (contract.error)
|
|
36
72
|
context.report({
|
|
@@ -41,10 +77,19 @@ export default {
|
|
|
41
77
|
else registry = importRegistry(node, contract, filename);
|
|
42
78
|
},
|
|
43
79
|
JSXOpeningElement(node) {
|
|
44
|
-
if (!registry
|
|
80
|
+
if (!registry) return;
|
|
45
81
|
// A declared component's own source is the wrapper that owns the
|
|
46
82
|
// element it renders; the preference governs its callers.
|
|
47
83
|
if (contract.componentSources.has(resolve(filename))) return;
|
|
84
|
+
// KF-JPE38T: a native form navigates on submit unless something
|
|
85
|
+
// cancels it; Kerf UI's Form plus wireForms is that contract.
|
|
86
|
+
if (
|
|
87
|
+
node.name.type === 'JSXIdentifier' &&
|
|
88
|
+
node.name.name === 'form' &&
|
|
89
|
+
!isExcepted(contract, FORM_CODE, filename)
|
|
90
|
+
)
|
|
91
|
+
context.report({ node: node.name, messageId: 'rawForm' });
|
|
92
|
+
if (isExcepted(contract, CODE, filename)) return;
|
|
48
93
|
const actual =
|
|
49
94
|
jsxKey(node.name, registry, contract) ??
|
|
50
95
|
customElementKey(node.name, contract);
|
package/lib/rules/ui-wiring.js
CHANGED
|
@@ -351,16 +351,29 @@ export default {
|
|
|
351
351
|
reachableCalls.add(helper);
|
|
352
352
|
}
|
|
353
353
|
const required = new Map(used);
|
|
354
|
+
const requiredSources = new Map(
|
|
355
|
+
[...used.keys()].map((key) => [key, new Set([filename])]),
|
|
356
|
+
);
|
|
354
357
|
if (ownEntry)
|
|
355
358
|
for (const [file, source] of ownEntry.modules)
|
|
356
|
-
for (const key of moduleUses(source, file, contract))
|
|
359
|
+
for (const key of moduleUses(source, file, contract)) {
|
|
357
360
|
if (!required.has(key)) required.set(key, node);
|
|
361
|
+
const sources = requiredSources.get(key) ?? new Set();
|
|
362
|
+
sources.add(file);
|
|
363
|
+
requiredSources.set(key, sources);
|
|
364
|
+
}
|
|
358
365
|
for (const [key, usage] of required) {
|
|
359
366
|
const entry = contract.entries.get(key);
|
|
360
367
|
if (!entry?.wiring.required) continue;
|
|
361
368
|
if (entry.wiring.scope === 'module' && !used.has(key)) continue;
|
|
362
369
|
if (entry.wiring.scope !== 'module' && reachable.length && !ownEntry)
|
|
363
370
|
continue;
|
|
371
|
+
const missingIsExcepted =
|
|
372
|
+
entry.wiring.scope === 'module'
|
|
373
|
+
? isExcepted(contract, MISSING_CODE, filename)
|
|
374
|
+
: [...requiredSources.get(key)].every((file) =>
|
|
375
|
+
isExcepted(contract, MISSING_CODE, file),
|
|
376
|
+
);
|
|
364
377
|
const actionModules =
|
|
365
378
|
entry.wiring.scope !== 'module' && ownEntry
|
|
366
379
|
? ownEntry.wiringModules
|
|
@@ -368,7 +381,7 @@ export default {
|
|
|
368
381
|
for (const action of entry.wiring.actions ?? [])
|
|
369
382
|
if (
|
|
370
383
|
!handlesAction(actionModules, action, contract) &&
|
|
371
|
-
!
|
|
384
|
+
!missingIsExcepted
|
|
372
385
|
)
|
|
373
386
|
context.report({
|
|
374
387
|
node: usage,
|
|
@@ -383,7 +396,7 @@ export default {
|
|
|
383
396
|
? registry.sources
|
|
384
397
|
: reachableImports
|
|
385
398
|
).has(helper) &&
|
|
386
|
-
!
|
|
399
|
+
!missingIsExcepted
|
|
387
400
|
)
|
|
388
401
|
context.report({
|
|
389
402
|
node: usage,
|
|
@@ -396,7 +409,7 @@ export default {
|
|
|
396
409
|
const provided = [helper, ...providers].some((name) =>
|
|
397
410
|
ownEntry ? reachableCalls.has(name) : calls.has(name),
|
|
398
411
|
);
|
|
399
|
-
if (!provided && !
|
|
412
|
+
if (!provided && !missingIsExcepted)
|
|
400
413
|
context.report({
|
|
401
414
|
node: usage,
|
|
402
415
|
messageId: 'missing',
|
package/lib/ui-contract.js
CHANGED
|
@@ -212,7 +212,7 @@ export function loadUiContract(context) {
|
|
|
212
212
|
const sourceExports = new Map();
|
|
213
213
|
const helperSourceFiles = new Map();
|
|
214
214
|
// Source files of declared components: a wrapper's own source may render
|
|
215
|
-
// the element it wraps (
|
|
215
|
+
// the element it wraps (an application wrapper around a `wa-dropdown`).
|
|
216
216
|
const componentSources = new Set();
|
|
217
217
|
// Every cataloged entry whose public classes may be a component's rendered
|
|
218
218
|
// anatomy: the base catalog's (exports from the selection catalog) and each
|
package/package.json
CHANGED