eslint-plugin-kerfjs 5.0.0-beta.95 → 5.0.0-beta.97

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.
@@ -31,7 +31,7 @@ The component a diagnostic names is the export named after the class's block, tr
31
31
 
32
32
  ## Component packages
33
33
 
34
- `KUI-L103` is not limited to `kui-*` classes. Every application or third-party composition catalog your `.kerf-ui-profile.json` declares under `catalogs` contributes its entries' public classes the same way: an `acme-meter` class on your own `<div>` is reported with the package's component to render (`Meter`), its `boundaries.placeableClasses` stay allowed, and its `boundaries.rootElement` reports a placeable class on a plain element of the tag the component renders. Component packages declare these fields in `kerf.components.json`; see the component-packages guide (`docs/13-component-packages.md` §13.7). The first catalog to list a class owns it, so `@kerfjs/ui`'s catalog wins over a declared one. `KUI-L101` (private/unknown class) still applies only to `kui-*` names.
34
+ `KUI-L103` is not limited to `kui-*` classes. Every application or third-party composition catalog your `.kerf-ui-profile.json` declares under `catalogs` contributes its entries' public classes the same way: an `acme-meter` class on your own `<div>` is reported with the package's component to render (`Meter`), its `boundaries.placeableClasses` stay allowed, and its `boundaries.rootElement` reports a placeable class on a plain element of the tag the component renders. Component packages declare these fields in `kerf.components.json`; see the component-packages guide (`docs/13-component-packages.md` §13.7). A catalog entry's `source` file owns its classes: inside that file, where the component writes its own anatomy, its classes are never reported, so a component need not mark its own root class placeable to author itself. Every other file, including another component's source, is still checked. The first catalog to list a class owns it, so `@kerfjs/ui`'s catalog wins over a declared one. `KUI-L101` (private/unknown class) still applies only to `kui-*` names.
35
35
 
36
36
  String class values are inspected in `class` / `className` literals and in a template literal's static, whitespace-delimited names (``class={`kui-content-item ${extra}`}``); a name an interpolation completes (`` `kui-toolbar-${size}` ``) is not known and is skipped.
37
37
 
@@ -30,6 +30,14 @@ Consumer composition catalogs can name an application helper's defining file in
30
30
 
31
31
  The source path is relative to the catalog package root. The rule resolves relative imports, aliases, and re-export barrels to that file, so another function with the same name does not satisfy the obligation.
32
32
 
33
+ Required wiring can instead be the application's own root-delegated handlers. List the `data-action` values in `wiring.actions` (required wiring names at least one helper or action):
34
+
35
+ ```json
36
+ "wiring": { "required": true, "helpers": [], "actions": ["open-card"], "obligations": ["Handle open-card at the page root."] }
37
+ ```
38
+
39
+ `KUI-L401` reports each listed action that no reachable module handles. A module handles an action when it imports `delegate`, `delegateCapture`, or `delegateActions` from `kerfjs` or `kerfjs/actions` and names the action as a quoted string (a `delegateActions` table key, an `action()` value, a `[data-action="open-card"]` selector) or as a bare table key. Comments do not count, and neither does a cataloged component's own source, which renders the attribute. Reachability and `scope` follow the helper rules above.
40
+
33
41
  The selection catalog can declare a public wiring provider in `wiringProviders`, naming its export, import source, and the helpers it installs. A recognized `wireCatalog` call from `@kerfjs/ui/wire-catalog` provides `wireScrollDividers`, so the rule does not ask for a duplicate call on the same application entry. The provider's disposer still needs to be retained.
34
42
 
35
43
  Assign, return, or otherwise retain a disposer when the binding has a shorter lifetime than the page. A `void` call is accepted as an explicit page-lifetime choice. The rule derives valid helper sources from each component-catalog entry's `publicExports` and `wiring[].import` facts, so aliases, root named imports, root namespaces, wiring-subpath named imports, and wiring-subpath namespaces resolve without a second hard-coded export table. It does not attempt flow-sensitive cleanup proof and offers no autofix.
package/index.js CHANGED
@@ -15,7 +15,7 @@ import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
15
15
  import uiWiring from './lib/rules/ui-wiring.js';
16
16
 
17
17
  const plugin = {
18
- meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.95' },
18
+ meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.97' },
19
19
  rules: {
20
20
  'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
21
21
  'no-raw-with-dynamic-arg': noRawWithDynamicArg,
@@ -1,3 +1,5 @@
1
+ import { resolve } from 'node:path';
2
+
1
3
  import {
2
4
  importRegistry,
3
5
  isExcepted,
@@ -82,6 +84,8 @@ export default {
82
84
  for (const name of names) {
83
85
  const owner = contract.componentClasses?.get(name);
84
86
  if (!owner || owner.key === renderedKey) continue;
87
+ // A component's own source file is where its anatomy is written.
88
+ if (owner.source && owner.source === resolve(filename)) continue;
85
89
  if (owner.element && owner.element !== intrinsicTag) continue;
86
90
  context.report({
87
91
  node,
@@ -164,6 +164,36 @@ function moduleCalls(source, file, contract) {
164
164
  return calls;
165
165
  }
166
166
 
167
+ // A module that can delegate: it imports delegate, delegateCapture, or
168
+ // delegateActions from kerfjs or kerfjs/actions.
169
+ const delegationImport =
170
+ /\bimport\s*\{[^}]*\b(?:delegate|delegateCapture|delegateActions)\b[^}]*\}\s*from\s*['"]kerfjs(?:\/actions)?['"]/;
171
+
172
+ const escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
173
+
174
+ // A required root-delegated action is handled when a module that imports a
175
+ // Kerf delegation API names it: as a quoted string (a delegateActions table
176
+ // key, an action() value, a selector such as `[data-action="name"]`) or as a
177
+ // bare table key. Cataloged component sources render their own data-action
178
+ // attributes, so they never count as the handler.
179
+ function handlesAction(modules, action, contract) {
180
+ const quoted = new RegExp(
181
+ `(['"\`])${escapeRegExp(action)}\\1|data-action=\\?["']${escapeRegExp(action)}\\?["']`,
182
+ );
183
+ const bareKey = /^[A-Za-z_$][\w$]*$/.test(action)
184
+ ? new RegExp(`[{,]\\s*${action}\\s*:`)
185
+ : undefined;
186
+ for (const [file, source] of modules) {
187
+ if (contract.componentSources?.has(file)) continue;
188
+ const code = source.replace(/\/\*[\s\S]*?\*\/|\/\/[^\n]*/g, (comment) =>
189
+ comment.replace(/[^\n]/g, ' '),
190
+ );
191
+ if (!delegationImport.test(code)) continue;
192
+ if (quoted.test(code) || bareKey?.test(code)) return true;
193
+ }
194
+ return false;
195
+ }
196
+
167
197
  function applicationEntries(contract, filename, source) {
168
198
  const root = resolve(contract.cwd);
169
199
  const entries = [];
@@ -188,6 +218,8 @@ export default {
188
218
  config: `${UI_CONTRACT_LOAD_CODE}: Kerf UI catalog/profile could not be loaded: {{error}}`,
189
219
  missing:
190
220
  'KUI-L401: `{{component}}` requires `{{helper}}`; import and invoke the documented wiring contract.',
221
+ action:
222
+ 'KUI-L401: `{{component}}` requires the application to handle `data-action="{{action}}"` with a root `delegate()` or `delegateActions()` listener.',
191
223
  cleanup:
192
224
  'KUI-L402: Retain or return the disposer from `{{helper}}`; use `void` only for an intentional page-lifetime binding.',
193
225
  },
@@ -253,6 +285,20 @@ export default {
253
285
  if (entry.wiring.scope === 'module' && !used.has(key)) continue;
254
286
  if (entry.wiring.scope !== 'module' && reachable.length && !ownEntry)
255
287
  continue;
288
+ const actionModules =
289
+ entry.wiring.scope !== 'module' && ownEntry
290
+ ? ownEntry.modules
291
+ : new Map([[filename, context.sourceCode.text]]);
292
+ for (const action of entry.wiring.actions ?? [])
293
+ if (
294
+ !handlesAction(actionModules, action, contract) &&
295
+ !isExcepted(contract, MISSING_CODE, filename)
296
+ )
297
+ context.report({
298
+ node: usage,
299
+ messageId: 'action',
300
+ data: { component: key, action },
301
+ });
256
302
  for (const helper of entry.wiring.helpers) {
257
303
  if (helper.startsWith('@')) {
258
304
  if (
@@ -235,6 +235,9 @@ export function loadUiContract(context) {
235
235
  name: entry.name,
236
236
  boundaries: entry.boundaries,
237
237
  exports: (entry.publicExports ?? []).map(exportName),
238
+ // The component's own source renders its anatomy classes; L103
239
+ // applies only outside it.
240
+ ...(entry.source ? { source: resolve(root, entry.source) } : {}),
238
241
  });
239
242
  for (const item of entry.publicExports ?? []) {
240
243
  const name = exportName(item);
@@ -351,6 +354,7 @@ function componentClassOwners(classOwnerEntries, componentClassOwnership) {
351
354
  key: entry.key,
352
355
  render,
353
356
  ...(element ? { element } : {}),
357
+ ...(entry.source ? { source: entry.source } : {}),
354
358
  });
355
359
  return owners;
356
360
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-kerfjs",
3
- "version": "5.0.0-beta.95",
3
+ "version": "5.0.0-beta.97",
4
4
  "description": "ESLint rules that enforce kerf's hard rules — catches AI-shaped bugs at edit time.",
5
5
  "type": "module",
6
6
  "license": "MIT",