eslint-plugin-kerfjs 5.0.0-beta.138 → 5.0.0-beta.139
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/docs/rules/ui-wiring.md +6 -0
- package/index.js +1 -1
- package/lib/rules/ai-assistant-configs.js +25 -10
- package/lib/rules/ui-wiring.js +39 -11
- package/package.json +1 -1
package/docs/rules/ui-wiring.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Checks wiring obligations published by the versioned composition catalog. `KUI-L401` reports a used component whose required helper or side-effect registration import is absent. `KUI-L402` reports a disposer-returning helper call whose disposer is discarded.
|
|
4
4
|
|
|
5
|
+
For surface scaffolds, `PinnablePopoverSurface` in its default overlay
|
|
6
|
+
presentation requires `wirePinnablePopover`. Embedded pinnable previews,
|
|
7
|
+
`DialogSurface` (including its built-in resizable bottom sheet), and the
|
|
8
|
+
other scaffold exports have no required helper. Use `wireOverlaySheets` when
|
|
9
|
+
opting into resizing for bottom sheets opened through `kerfjs/overlay`.
|
|
10
|
+
|
|
5
11
|
Declare application entry modules in the application UI profile to check root wiring once per entry:
|
|
6
12
|
|
|
7
13
|
```json
|
package/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
|
16
16
|
import uiWiring from './lib/rules/ui-wiring.js';
|
|
17
17
|
|
|
18
18
|
const plugin = {
|
|
19
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
19
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.139' },
|
|
20
20
|
rules: {
|
|
21
21
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
22
22
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
writeFileSync,
|
|
23
23
|
} from 'node:fs';
|
|
24
24
|
import { createRequire } from 'node:module';
|
|
25
|
-
import { dirname, join, resolve, relative } from 'node:path';
|
|
25
|
+
import { dirname, isAbsolute, join, resolve, relative, sep } from 'node:path';
|
|
26
26
|
|
|
27
27
|
const MARKER = '<!-- KERF-APP-CANONICAL-END · your customizations below -->';
|
|
28
28
|
const VERSION_RE = /kerf-skill-version:\s*(\d+\.\d+\.\d+(?:-[\w.]+)?)/;
|
|
@@ -60,6 +60,21 @@ function guidanceRoot(cwd) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
function repositoryBoundary(root) {
|
|
64
|
+
let current = root;
|
|
65
|
+
while (true) {
|
|
66
|
+
if (existsSync(join(current, '.git'))) return current;
|
|
67
|
+
const parent = dirname(current);
|
|
68
|
+
if (parent === current) return root;
|
|
69
|
+
current = parent;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function escapes(root, path) {
|
|
74
|
+
const offset = relative(root, path);
|
|
75
|
+
return offset === '..' || offset.startsWith(`..${sep}`) || isAbsolute(offset);
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
function sharedSkill(file, cwd, source) {
|
|
64
79
|
const importPath = relative(
|
|
65
80
|
dirname(join(cwd, file.dest)),
|
|
@@ -166,7 +181,7 @@ function canonicalEndOffset(text) {
|
|
|
166
181
|
*
|
|
167
182
|
* Exported for tests.
|
|
168
183
|
*/
|
|
169
|
-
export function classifyFile(file, bundleDir, cwd) {
|
|
184
|
+
export function classifyFile(file, bundleDir, cwd, sharedSource) {
|
|
170
185
|
const destAbs = join(cwd, file.dest);
|
|
171
186
|
let consumer;
|
|
172
187
|
try {
|
|
@@ -190,19 +205,19 @@ export function classifyFile(file, bundleDir, cwd) {
|
|
|
190
205
|
if (!match)
|
|
191
206
|
return { state: 'forked', reason: 'malformed shared guidance import' };
|
|
192
207
|
const sourcePath = resolve(dirname(destAbs), match[1]);
|
|
193
|
-
|
|
194
|
-
|
|
208
|
+
// Setup permits a configured source elsewhere in the same repository.
|
|
209
|
+
const boundary =
|
|
210
|
+
sharedSource && sourcePath === resolve(cwd, sharedSource)
|
|
211
|
+
? repositoryBoundary(cwd)
|
|
212
|
+
: cwd;
|
|
213
|
+
if (escapes(boundary, sourcePath))
|
|
195
214
|
return {
|
|
196
215
|
state: 'forked',
|
|
197
216
|
reason: 'shared guidance import escapes the workspace',
|
|
198
217
|
};
|
|
199
218
|
let source;
|
|
200
219
|
try {
|
|
201
|
-
|
|
202
|
-
realpathSync(cwd),
|
|
203
|
-
realpathSync(sourcePath),
|
|
204
|
-
);
|
|
205
|
-
if (actualRelative === '..' || actualRelative.startsWith('../'))
|
|
220
|
+
if (escapes(realpathSync(boundary), realpathSync(sourcePath)))
|
|
206
221
|
return {
|
|
207
222
|
state: 'forked',
|
|
208
223
|
reason: 'shared guidance import escapes the workspace',
|
|
@@ -308,7 +323,7 @@ export function runCheck(cwd) {
|
|
|
308
323
|
const sharedSource = sharedGuidanceSource(root);
|
|
309
324
|
for (const file of bundle.manifest.files) {
|
|
310
325
|
if (!isTriggered(file.name, root)) continue;
|
|
311
|
-
let result = classifyFile(file, bundle.bundleDir, root);
|
|
326
|
+
let result = classifyFile(file, bundle.bundleDir, root, sharedSource);
|
|
312
327
|
if (
|
|
313
328
|
(file.name === 'skill' || file.name === 'ui-skill') &&
|
|
314
329
|
sharedSource &&
|
package/lib/rules/ui-wiring.js
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
helperCall,
|
|
6
6
|
importRegistry,
|
|
7
7
|
isExcepted,
|
|
8
|
+
jsxExportName,
|
|
8
9
|
jsxKey,
|
|
9
10
|
loadUiContract,
|
|
10
11
|
relativeImportCandidates,
|
|
@@ -14,6 +15,8 @@ import {
|
|
|
14
15
|
|
|
15
16
|
const MISSING_CODE = 'KUI-L401';
|
|
16
17
|
const CLEANUP_CODE = 'KUI-L402';
|
|
18
|
+
const SURFACE_SCAFFOLD = '@kerfjs/ui:surface-scaffold';
|
|
19
|
+
const PINNABLE_POPOVER = 'PinnablePopoverSurface';
|
|
17
20
|
|
|
18
21
|
const retained = (call) => call.parent?.type !== 'ExpressionStatement';
|
|
19
22
|
|
|
@@ -130,6 +133,26 @@ function literalAttributes(attributes) {
|
|
|
130
133
|
});
|
|
131
134
|
}
|
|
132
135
|
|
|
136
|
+
function needsPopoverWiring(attributes) {
|
|
137
|
+
let presentation;
|
|
138
|
+
for (const [name, value] of attributes)
|
|
139
|
+
if (name === 'presentation' || name === '...') presentation = value;
|
|
140
|
+
return presentation !== 'embedded';
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function importedTagUses(source, tag, key, exported, contract) {
|
|
144
|
+
if (!key || !new RegExp(`<${escapeRegExp(tag)}(?=[\\s/>])`).test(source))
|
|
145
|
+
return false;
|
|
146
|
+
if (key === '@kerfjs/ui:choice-chips')
|
|
147
|
+
return contract.choiceWiring.choiceUses(source, tag);
|
|
148
|
+
if (key === SURFACE_SCAFFOLD)
|
|
149
|
+
return (
|
|
150
|
+
exported === PINNABLE_POPOVER &&
|
|
151
|
+
(contract.choiceWiring.jsxUses?.(source, tag, needsPopoverWiring) ?? true)
|
|
152
|
+
);
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
133
156
|
// The entry graph is read from disk because ESLint visits one source file at a
|
|
134
157
|
// time. Match only imported JSX names; an unrelated local tag cannot satisfy a
|
|
135
158
|
// catalog obligation. The current entry's in-memory text covers editor linting.
|
|
@@ -156,12 +179,7 @@ function moduleUses(source, file, contract) {
|
|
|
156
179
|
if (!match) continue;
|
|
157
180
|
const [, imported, local = imported] = match;
|
|
158
181
|
const key = keyFor(imported);
|
|
159
|
-
if (
|
|
160
|
-
key &&
|
|
161
|
-
new RegExp(`<${local}(?=[\\s/>])`).test(source) &&
|
|
162
|
-
(key !== '@kerfjs/ui:choice-chips' ||
|
|
163
|
-
contract.choiceWiring.choiceUses(source, local))
|
|
164
|
-
)
|
|
182
|
+
if (importedTagUses(source, local, key, imported, contract))
|
|
165
183
|
uses.add(key);
|
|
166
184
|
}
|
|
167
185
|
const namespace = bindings.match(/\*\s+as\s+(\w+)/)?.[1];
|
|
@@ -173,10 +191,7 @@ function moduleUses(source, file, contract) {
|
|
|
173
191
|
for (const name of names) {
|
|
174
192
|
const key = keyFor(name);
|
|
175
193
|
if (
|
|
176
|
-
key
|
|
177
|
-
new RegExp(`<${namespace}\\.${name}(?=[\\s/>])`).test(source) &&
|
|
178
|
-
(key !== '@kerfjs/ui:choice-chips' ||
|
|
179
|
-
contract.choiceWiring.choiceUses(source, `${namespace}.${name}`))
|
|
194
|
+
importedTagUses(source, `${namespace}.${name}`, key, name, contract)
|
|
180
195
|
)
|
|
181
196
|
uses.add(key);
|
|
182
197
|
}
|
|
@@ -185,7 +200,7 @@ function moduleUses(source, file, contract) {
|
|
|
185
200
|
if (
|
|
186
201
|
direct &&
|
|
187
202
|
defaultName &&
|
|
188
|
-
|
|
203
|
+
importedTagUses(source, defaultName, direct, 'default', contract)
|
|
189
204
|
)
|
|
190
205
|
uses.add(direct);
|
|
191
206
|
}
|
|
@@ -332,6 +347,12 @@ export default {
|
|
|
332
347
|
JSXOpeningElement(node) {
|
|
333
348
|
if (!registry) return;
|
|
334
349
|
const key = jsxKey(node.name, registry, contract);
|
|
350
|
+
if (
|
|
351
|
+
key === SURFACE_SCAFFOLD &&
|
|
352
|
+
(jsxExportName(node.name, registry) !== PINNABLE_POPOVER ||
|
|
353
|
+
!needsPopoverWiring(literalAttributes(node.attributes)))
|
|
354
|
+
)
|
|
355
|
+
return;
|
|
335
356
|
if (
|
|
336
357
|
key &&
|
|
337
358
|
!used.has(key) &&
|
|
@@ -412,6 +433,10 @@ export default {
|
|
|
412
433
|
data: { component: key, action },
|
|
413
434
|
});
|
|
414
435
|
for (const helper of entry.wiring.helpers) {
|
|
436
|
+
// Older surface catalogs group the optional core sheet helper
|
|
437
|
+
// with the pinnable popover requirement.
|
|
438
|
+
if (key === SURFACE_SCAFFOLD && helper === 'wireOverlaySheets')
|
|
439
|
+
continue;
|
|
415
440
|
if (helper.startsWith('@')) {
|
|
416
441
|
if (
|
|
417
442
|
!(
|
|
@@ -447,6 +472,9 @@ export default {
|
|
|
447
472
|
.flatMap((entry) => entry.wiring.helpers)
|
|
448
473
|
.filter((helper) => !helper.startsWith('@')),
|
|
449
474
|
);
|
|
475
|
+
// Opt-in core sheet wiring still returns a disposer.
|
|
476
|
+
if (contract.entries.has(SURFACE_SCAFFOLD))
|
|
477
|
+
disposerHelpers.add('wireOverlaySheets');
|
|
450
478
|
for (const [helper, helperCalls] of calls)
|
|
451
479
|
if (disposerHelpers.has(helper))
|
|
452
480
|
for (const { node: call, returnsDisposer } of helperCalls)
|
package/package.json
CHANGED