eslint-plugin-kerfjs 5.0.0-beta.131 → 5.0.0-beta.132
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
CHANGED
|
@@ -121,7 +121,6 @@ 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` |
|
|
125
124
|
| [`ui-public-boundaries`](docs/rules/ui-public-boundaries.md) | — (cataloged classes/tokens; component anatomy on app elements) | `error` |
|
|
126
125
|
| [`ui-component-ownership`](docs/rules/ui-component-ownership.md) | — (configure components, never override them) | `error` |
|
|
127
126
|
| [`ui-composition`](docs/rules/ui-composition.md) | — (cataloged parents and zones) | `error` |
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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
|
-
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.
|
|
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`. A listed parent may also name one prop of a component (`@kerfjs/ui:surface-scaffold#headerActions`): the child is accepted there only when it is written inside that prop, not in the component's body or another prop. 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
|
|
7
7
|
controls and custom components there. Their own parent contracts still apply,
|
|
8
8
|
including when a direct child is supplied through a zone prop.
|
|
@@ -68,8 +68,7 @@ import { Badge, Button, ListItem } from '@kerfjs/ui';
|
|
|
68
68
|
A `whenProps` rule counts a prop as written when the attribute is present,
|
|
69
69
|
whatever expression supplies it, unless its value is a literal `false` or
|
|
70
70
|
`null`. A component defined elsewhere, or a prop supplied through a spread, is
|
|
71
|
-
not visible to the rule.
|
|
72
|
-
document as `KUI-V014`, from the same rules.
|
|
71
|
+
not visible to the rule.
|
|
73
72
|
|
|
74
73
|
## Application and third-party wrappers
|
|
75
74
|
|
package/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import aiAssistantConfigs from './lib/rules/ai-assistant-configs.js';
|
|
2
|
-
import noGeneratedViewEdits from './lib/rules/no-generated-view-edits.js';
|
|
3
2
|
import noInlineJsxEventHandlers from './lib/rules/no-inline-jsx-event-handlers.js';
|
|
4
3
|
import noNestedMount from './lib/rules/no-nested-mount.js';
|
|
5
4
|
import noRawWithDynamicArg from './lib/rules/no-raw-with-dynamic-arg.js';
|
|
@@ -16,10 +15,9 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
|
16
15
|
import uiWiring from './lib/rules/ui-wiring.js';
|
|
17
16
|
|
|
18
17
|
const plugin = {
|
|
19
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
18
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.132' },
|
|
20
19
|
rules: {
|
|
21
20
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
22
|
-
'no-generated-view-edits': noGeneratedViewEdits,
|
|
23
21
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
|
24
22
|
'require-data-key-in-each': requireDataKeyInEach,
|
|
25
23
|
'require-delegate-disposer': requireDelegateDisposer,
|
|
@@ -46,9 +44,6 @@ const plugin = {
|
|
|
46
44
|
// would block too many legitimate uses without eslint-disable comments.
|
|
47
45
|
// `prefer-attr-selector` is `warn` — the literal-selector form is still
|
|
48
46
|
// 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.
|
|
52
47
|
// `require-delegate-disposer` is `warn` — the discarded-disposer form is
|
|
53
48
|
// still correct at runtime for page-lifetime roots, and downstream code
|
|
54
49
|
// that's been around since before the rule shipped needs a deprecation
|
|
@@ -62,7 +57,6 @@ const recommendedRules = {
|
|
|
62
57
|
'kerfjs/prefer-module-jsx-augmentation': 'error',
|
|
63
58
|
'kerfjs/prefer-attr-selector': 'warn',
|
|
64
59
|
'kerfjs/ai-assistant-configs': 'warn',
|
|
65
|
-
'kerfjs/no-generated-view-edits': 'error',
|
|
66
60
|
};
|
|
67
61
|
|
|
68
62
|
// Flat config (ESLint v9+) — consumers add this object to their config array.
|
|
@@ -112,6 +112,8 @@ function zoneShape(node, registry, contract) {
|
|
|
112
112
|
return { min: 0, max: Number.POSITIVE_INFINITY, items: [] };
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// The element that directly contains `node`, and the prop it arrives through
|
|
116
|
+
// when it is written inside an attribute (`headerActions={<Group />}`).
|
|
115
117
|
function directParentKey(node, registry, contract) {
|
|
116
118
|
let parent = node.parent?.parent;
|
|
117
119
|
while (
|
|
@@ -119,12 +121,23 @@ function directParentKey(node, registry, contract) {
|
|
|
119
121
|
['JSXExpressionContainer', 'JSXFragment'].includes(parent.type)
|
|
120
122
|
)
|
|
121
123
|
parent = parent.parent;
|
|
122
|
-
|
|
124
|
+
let prop;
|
|
125
|
+
if (parent?.type === 'JSXAttribute') {
|
|
126
|
+
prop = parent.name.name;
|
|
127
|
+
parent = parent.parent?.parent;
|
|
128
|
+
}
|
|
123
129
|
return parent?.type === 'JSXElement'
|
|
124
|
-
? { key: jsxKey(parent.openingElement.name, registry, contract) }
|
|
130
|
+
? { key: jsxKey(parent.openingElement.name, registry, contract), prop }
|
|
125
131
|
: undefined;
|
|
126
132
|
}
|
|
127
133
|
|
|
134
|
+
// A listed parent names a catalog key, or a key and one prop
|
|
135
|
+
// (`@kerfjs/ui:surface-scaffold#headerActions`) that accepts the child only
|
|
136
|
+
// through that prop (KF-SMTCPZ).
|
|
137
|
+
const acceptsParent = (entries, root, prop) =>
|
|
138
|
+
entries.includes(root) ||
|
|
139
|
+
(prop !== undefined && entries.includes(`${root}#${prop}`));
|
|
140
|
+
|
|
128
141
|
// A prop's statically written value: `{ known: true, value }`, where a bare
|
|
129
142
|
// boolean prop is `true` and an absent one is `undefined`, or
|
|
130
143
|
// `{ known: false }` when a spread or an expression could supply it.
|
|
@@ -181,8 +194,8 @@ const rootsOf = (key, contract) =>
|
|
|
181
194
|
contract.entries.get(key)?.rendersAs ?? [key];
|
|
182
195
|
|
|
183
196
|
// 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
|
|
185
|
-
//
|
|
197
|
+
// or inside it (`contains`), from its entry's `content` rules (KF-VTFKX8). An
|
|
198
|
+
// export with rules of its own uses
|
|
186
199
|
// them; a `whenProps` rule needs one of its props written, and a literal
|
|
187
200
|
// `false` or `null` does not count.
|
|
188
201
|
function interactiveOf(openingElement, registry, contract) {
|
|
@@ -331,7 +344,7 @@ export default {
|
|
|
331
344
|
const violation = constrained.find(
|
|
332
345
|
({ entry: placedEntry }) =>
|
|
333
346
|
!rootsOf(parent.key, contract).every((root) =>
|
|
334
|
-
placedEntry.parents.entries.
|
|
347
|
+
acceptsParent(placedEntry.parents.entries, root, parent.prop),
|
|
335
348
|
),
|
|
336
349
|
);
|
|
337
350
|
if (violation)
|
package/package.json
CHANGED
|
@@ -1,42 +0,0 @@
|
|
|
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,81 +0,0 @@
|
|
|
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
|
-
};
|