eslint-plugin-kerfjs 5.0.0-beta.14 → 5.0.0-beta.141

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.
Files changed (37) hide show
  1. package/README.md +85 -21
  2. package/docs/rules/ai-assistant-configs.md +17 -6
  3. package/docs/rules/no-inline-jsx-event-handlers.md +2 -2
  4. package/docs/rules/no-nested-mount.md +6 -1
  5. package/docs/rules/no-raw-with-dynamic-arg.md +7 -7
  6. package/docs/rules/prefer-attr-selector.md +7 -7
  7. package/docs/rules/prefer-module-jsx-augmentation.md +8 -4
  8. package/docs/rules/prefer-signal-leaf.md +43 -0
  9. package/docs/rules/require-data-key-in-each.md +16 -6
  10. package/docs/rules/require-delegate-disposer.md +10 -5
  11. package/docs/rules/ui-component-ownership.md +43 -0
  12. package/docs/rules/ui-composition.md +115 -0
  13. package/docs/rules/ui-css-values.md +51 -0
  14. package/docs/rules/ui-exceptional-shorthands.md +22 -0
  15. package/docs/rules/ui-preferences.md +41 -0
  16. package/docs/rules/ui-public-boundaries.md +48 -0
  17. package/docs/rules/ui-wiring.md +63 -0
  18. package/index.js +47 -1
  19. package/lib/html-template-classes.js +104 -0
  20. package/lib/rules/ai-assistant-configs.js +200 -24
  21. package/lib/rules/no-inline-jsx-event-handlers.js +1 -1
  22. package/lib/rules/no-nested-mount.js +2 -1
  23. package/lib/rules/no-raw-with-dynamic-arg.js +7 -6
  24. package/lib/rules/prefer-module-jsx-augmentation.js +3 -2
  25. package/lib/rules/prefer-signal-leaf.js +206 -0
  26. package/lib/rules/require-data-key-in-each.js +38 -3
  27. package/lib/rules/require-delegate-disposer.js +2 -1
  28. package/lib/rules/ui-component-ownership.js +211 -0
  29. package/lib/rules/ui-composition.js +438 -0
  30. package/lib/rules/ui-css-values.js +3 -0
  31. package/lib/rules/ui-exceptional-shorthands.js +3 -0
  32. package/lib/rules/ui-preferences.js +116 -0
  33. package/lib/rules/ui-public-boundaries.js +196 -0
  34. package/lib/rules/ui-wiring.js +491 -0
  35. package/lib/ui-contract.js +646 -0
  36. package/lib/ui-css-value-contracts.js +317 -0
  37. package/package.json +8 -2
package/README.md CHANGED
@@ -7,13 +7,13 @@ ESLint rules that enforce kerf's hard rules. Catches AI-shaped bugs at edit time
7
7
 
8
8
  This plugin sits alongside two other defense layers shipped by [`kerfjs`](https://brianwestphal.github.io/kerf/):
9
9
 
10
- | Layer | Catches | When |
11
- |---|---|---|
12
- | `tsc --noEmit` with strict typings | Hard Rules 8 (partial-set), most type errors | Build time |
13
- | Opt-in dev-warns (`KERF_DEV_WARN_*`) | Hard Rules 4 (rebuilt listeners), 7 (untracked signals), 8 (narrow set) | Runtime |
14
- | **This plugin** | Hard Rules 2, 5, 6, 10, 12 — AST-shaped antipatterns; plus rename-safety / `raw()`-audit nudges and a project-hygiene check for the bundled AI-assistant configs | **Edit time** |
10
+ | Layer | Catches | When |
11
+ | ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
12
+ | `tsc --noEmit` with strict typings | Hard Rules 8 (partial-set), most type errors | Build time |
13
+ | Opt-in dev-warns (`KERF_DEV_WARN_*`) | Hard Rules 4 (rebuilt listeners), 7 (untracked signals), 8 (narrow set) | Runtime |
14
+ | **This plugin** | Hard Rules 2, 5, 6, 10, 12 — AST-shaped antipatterns; plus rename-safety / `raw()`-audit nudges and a project-hygiene check for the bundled AI-assistant configs | **Edit time** |
15
15
 
16
- All but one rule are AST-only — no `@typescript-eslint/parser` *service* dependency is required by the plugin (consumers configure their own parser). The exception, `ai-assistant-configs`, reads the filesystem instead of the AST and runs once per lint pass.
16
+ The core syntax rules analyze the AST without TypeScript parser services. `ai-assistant-configs` reads the filesystem, and the optional UI rules also resolve catalog and profile artifacts. Consumers configure their own parser. The optional `prefer-signal-leaf` suggestion uses an existing TypeScript parser service.
17
17
 
18
18
  ## Install
19
19
 
@@ -21,6 +21,9 @@ All but one rule are AST-only — no `@typescript-eslint/parser` *service* depen
21
21
  npm install --save-dev eslint-plugin-kerfjs
22
22
  ```
23
23
 
24
+ Install `@kerfjs/ui` as well when using `recommended-ui` or `strict-ui`; the
25
+ core `recommended` preset does not require it.
26
+
24
27
  ### Supported ESLint versions
25
28
 
26
29
  `peerDependencies` declares `^9.0.0 || ^10.0.0`, and that is a **tested** range rather than an optimistic one: the rule suite runs against the latest release of each of those majors in CI on every push. A major is added to the range only after the suite has passed on it.
@@ -33,12 +36,12 @@ A version outside the range is not "probably fine" — it is one nobody has run.
33
36
 
34
37
  ```js
35
38
  // eslint.config.js
36
- import kerfjs from 'eslint-plugin-kerfjs';
37
- import tsParser from '@typescript-eslint/parser';
39
+ import kerfjs from "eslint-plugin-kerfjs";
40
+ import tsParser from "@typescript-eslint/parser";
38
41
 
39
42
  export default [
40
43
  {
41
- files: ['**/*.ts', '**/*.tsx'],
44
+ files: ["**/*.ts", "**/*.tsx"],
42
45
  languageOptions: {
43
46
  parser: tsParser,
44
47
  parserOptions: { ecmaFeatures: { jsx: true } },
@@ -48,25 +51,84 @@ export default [
48
51
  ];
49
52
  ```
50
53
 
54
+ Applications using the UI catalog can select one of two additive flat configs:
55
+
56
+ ```js
57
+ export default [
58
+ // parser/files configuration as above
59
+ kerfjs.configs['recommended-ui'], // preferences and wiring are warnings
60
+ // or kerfjs.configs['strict-ui'] // all UI contracts are errors
61
+ ];
62
+ ```
63
+
64
+ The UI rules resolve the installed `@kerfjs/ui` selection catalog (`component-catalog.json`), composition catalog (`component-composition.json`), and application profile defaults. They then merge `.kerf-ui-profile.json` files from the workspace root toward the linted file. Package authors and monorepos can provide explicit artifacts without duplicating their facts:
65
+
66
+ ```js
67
+ settings: {
68
+ kerfjs: {
69
+ ui: {
70
+ workspaceRoot: import.meta.dirname,
71
+ catalogPath: './vendor/component-composition.json',
72
+ selectionCatalogPath: './vendor/component-catalog.json',
73
+ profileDefaultsPath: './vendor/application-ui-profile.defaults.json',
74
+ profileContractPath: './vendor/application-ui-profile-sync.cjs',
75
+ },
76
+ },
77
+ }
78
+ ```
79
+
80
+ For deterministic generated configs, the same settings accept parsed `catalog`, `selectionCatalog`, and `profile` objects. File-based precedence is package defaults, then workspace profile, then root-to-leaf directory profiles. The rules load `application-ui-profile-sync.cjs` from the installed `@kerfjs/ui` package by default because ESLint rule creation is synchronous; `profileContractPath` is only needed when artifacts are vendored, and then its directory must also hold `application-ui-diagnostic-ids-v1.json` and `choice-wiring-mode.cjs` plus `component-class-owners.cjs` (the class-to-component rule `KUI-L103` shares with `@kerfjs/ui`'s generated component pages) from the same `@kerfjs/ui` release. Every raw layer is schema- and catalog-reference-validated before merge, so a child cannot hide malformed or stale parent policy. Exceptions use exact `KUI-L*` diagnostic ids and repository-relative file or directory targets.
81
+
82
+ When linting a nested workspace package, set `workspaceRoot` to the repository root. Installed `@kerfjs/ui` assets still resolve from ESLint's package `cwd`, while profile discovery and exception targets use the workspace root.
83
+
84
+ `ui-css-values` consumes each catalog entry's property-specific grammar and
85
+ emits `KUI-L013`–`KUI-L016` with a preferred shorthand or helper. It covers JSX,
86
+ direct component calls, nested catalog paths, and explicitly configured
87
+ third-party catalogs; dynamic values remain governed by TypeScript. Its
88
+ companion `ui-exceptional-shorthands` walks the same contracts and emits the
89
+ review finding `KUI-L017` for a valid but exceptional off-scale shorthand. It
90
+ is `warn` in both `recommended-ui` and `strict-ui`, matching the analyzer's
91
+ `review` classification, so `kerf-ui-doctor` merges the ESLint and analyzer
92
+ reports into one review finding.
93
+
94
+ UI rule severities follow the analyzer's classification of the codes each rule
95
+ reports: an `error` code ships as `error`, and a `review` code ships as `warn`.
96
+
97
+ `ui-component-ownership` keeps code out of another package's component
98
+ internals: `KUI-L020` reports a reference to a component's private `--_*`
99
+ variable and `KUI-L021` an assignment to a token a typed prop sets (use the
100
+ prop). Each message ends by routing a real need with no prop to a component-gap
101
+ report instead of an override. `kerf-ui-analyze` reports the same ids, plus the
102
+ stylesheet-only `KUI-L019` / `KUI-L022`, for CSS files.
103
+
104
+ `KUI-L090` is reserved for catalog/profile loading and configuration failures. The supported-ESLint matrix installs real packed `eslint-plugin-kerfjs` and `@kerfjs/ui` tarballs in a downstream flat-config fixture, ensuring these defaults resolve from the consumer rather than this repository's source tree.
105
+
51
106
  ## Legacy `.eslintrc` configs are not supported
52
107
 
53
- The package is ESM-only. ESLint's `.eslintrc` system loads plugins with `require()`, which cannot load an ESM package, so `extends: ["plugin:kerfjs/legacy-recommended"]` fails with *"couldn't find the config to extend from"* on ESLint 8 **and** on ESLint 9's legacy mode.
108
+ The package is ESM-only. ESLint's `.eslintrc` system loads plugins with `require()`, which cannot load an ESM package, so `extends: ["plugin:kerfjs/legacy-recommended"]` fails with _"couldn't find the config to extend from"_ on ESLint 8 **and** on ESLint 9's legacy mode.
54
109
 
55
110
  Use flat config (`eslint.config.js`), shown above. The `legacy-recommended` export still exists in the package but is unreachable through any config system — treat it as deprecated.
56
111
 
57
-
58
112
  ## Rules
59
113
 
60
- | Rule | Hard Rule | Severity (recommended) |
61
- |---|---|---|
62
- | [`no-inline-jsx-event-handlers`](docs/rules/no-inline-jsx-event-handlers.md) | 10 — use `data-action` + `delegate()` | `error` |
63
- | [`require-data-key-in-each`](docs/rules/require-data-key-in-each.md) | 2 — `data-key` per item | `error` |
64
- | [`require-delegate-disposer`](docs/rules/require-delegate-disposer.md) | 5 — capture `delegate()` disposers when scope < page | `warn` |
65
- | [`no-nested-mount`](docs/rules/no-nested-mount.md) | 6 — one `mount()` per root | `error` |
66
- | [`prefer-module-jsx-augmentation`](docs/rules/prefer-module-jsx-augmentation.md) | 12 — augment `kerfjs/jsx-runtime`, not global | `error` |
67
- | [`prefer-attr-selector`](docs/rules/prefer-attr-selector.md) | — (rename-safety nudge for `delegate()` selectors) | `warn` |
68
- | [`no-raw-with-dynamic-arg`](docs/rules/no-raw-with-dynamic-arg.md) | — (XSS audit trail) | `warn` |
69
- | [`ai-assistant-configs`](docs/rules/ai-assistant-configs.md) | — (project hygiene) | `warn` |
114
+ | Rule | Hard Rule | Severity (recommended) |
115
+ | -------------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------------- |
116
+ | [`no-inline-jsx-event-handlers`](docs/rules/no-inline-jsx-event-handlers.md) | 10 — use `data-action` + `delegate()` | `error` |
117
+ | [`require-data-key-in-each`](docs/rules/require-data-key-in-each.md) | 2 — `data-key` per item | `error` |
118
+ | [`require-delegate-disposer`](docs/rules/require-delegate-disposer.md) | 5 — capture `delegate()` disposers when scope < page | `warn` |
119
+ | [`no-nested-mount`](docs/rules/no-nested-mount.md) | 6 — one `mount()` per root | `error` |
120
+ | [`prefer-module-jsx-augmentation`](docs/rules/prefer-module-jsx-augmentation.md) | 12 — augment `kerfjs/jsx-runtime`, not global | `error` |
121
+ | [`prefer-signal-leaf`](docs/rules/prefer-signal-leaf.md) | — (typed editor suggestion for a mounted DOM leaf) | off |
122
+ | [`prefer-attr-selector`](docs/rules/prefer-attr-selector.md) | — (rename-safety nudge for `delegate()` selectors) | `warn` |
123
+ | [`no-raw-with-dynamic-arg`](docs/rules/no-raw-with-dynamic-arg.md) | — (XSS audit trail) | `warn` |
124
+ | [`ai-assistant-configs`](docs/rules/ai-assistant-configs.md) | — (project hygiene) | `warn` |
125
+ | [`ui-public-boundaries`](docs/rules/ui-public-boundaries.md) | — (cataloged classes/tokens; component anatomy on app elements) | `error` |
126
+ | [`ui-component-ownership`](docs/rules/ui-component-ownership.md) | — (configure components, never override them) | `error` |
127
+ | [`ui-composition`](docs/rules/ui-composition.md) | — (cataloged parents and zones) | `error` |
128
+ | [`ui-css-values`](docs/rules/ui-css-values.md) | — (cataloged property-specific value grammar) | `error` |
129
+ | [`ui-exceptional-shorthands`](docs/rules/ui-exceptional-shorthands.md) | — (review deliberate off-scale shorthands) | `warn` |
130
+ | [`ui-preferences`](docs/rules/ui-preferences.md) | — (application component choices) | `warn` |
131
+ | [`ui-wiring`](docs/rules/ui-wiring.md) | — (required setup and cleanup) | `warn` |
70
132
 
71
133
  The "Hard Rule" column refers to the numbered rules in [`docs/ai/usage-guide.md`](../docs/ai/usage-guide.md) on the main kerf repo. `no-raw-with-dynamic-arg` and `ai-assistant-configs` don't map to numbered Hard Rules — the former creates an audit trail for every dynamic `raw()` call site (potential XSS); the latter checks that the bundled AI-assistant configs are installed and current. See [`docs/12-ai-assistant-configs.md`](../docs/12-ai-assistant-configs.md) on the main kerf repo for the AI-configs design.
72
134
 
@@ -81,6 +143,8 @@ When a real bug ships that the existing defense stack misses AND a new lint rule
81
143
  ```bash
82
144
  npm install
83
145
  npm test
146
+ npm run check # matrix-parity check, then the rule suite (what CI runs)
147
+ npm run test:eslint-matrix # real packed-plugin loading on every supported ESLint major
84
148
  ```
85
149
 
86
150
  The AST rules' test suites use ESLint's `RuleTester` with `@typescript-eslint/parser`. The `ai-assistant-configs` tests are filesystem-driven — they build temp project roots with fixture `node_modules/kerfjs/ai/` bundles, drive the classifier directly, and use the real ESLint API to prove plain lint is read-only while explicit `--fix` performs the external write.
@@ -1,6 +1,6 @@
1
1
  # `kerfjs/ai-assistant-configs`
2
2
 
3
- Check that the [kerf-app Claude Code skill](https://github.com/brianwestphal/kerf/blob/main/kerf.claude-skill.md) and [Cursor rules](https://github.com/brianwestphal/kerf/blob/main/kerf.cursorrules) drop-ins are installed in the project and up-to-date with the canonical files bundled inside the consumer's installed `kerfjs` package.
3
+ Check that the [kerf-app Claude Code skill](https://github.com/brianwestphal/kerf/blob/main/kerf.claude-skill.md), [kerf-ui skill](https://github.com/brianwestphal/kerf/blob/main/kerf.ui-skill.md), and [Cursor rules](https://github.com/brianwestphal/kerf/blob/main/kerf.cursorrules) drop-ins are installed in the project and up-to-date with the canonical files bundled inside the consumer's installed `kerfjs` package.
4
4
 
5
5
  Unlike the other AST-based rules in this plugin, this rule reads the **filesystem**, not source code. It runs once per lint pass and reports project-level hygiene issues rather than per-file code defects. Severity in `kerfjs.configs.recommended` is `warn`, not `error` — a missing skill file shouldn't fail CI.
6
6
 
@@ -10,13 +10,24 @@ Maps to design doc [`docs/12-ai-assistant-configs.md`](https://github.com/brianw
10
10
 
11
11
  The rule resolves `kerfjs/ai/manifest.json` from the consumer's installed `kerfjs` (silently no-ops if `kerfjs` isn't a dep). For each bundled file, it picks a trigger heuristic — "is this project using the tool this file is for?" — and only nudges the consumer when the trigger says yes:
12
12
 
13
- | Bundled file | Triggers when | Installed to |
14
- |---|---|---|
15
- | `ai/skill.md` (Claude Code) | `.claude/` directory exists at the project root | `.claude/skills/kerf-app/SKILL.md` |
16
- | `ai/cursorrules` (Cursor) | `.cursorrules` file or `.cursor/` directory exists | `.cursorrules` |
13
+ | Bundled file | Triggers when | Installed to |
14
+ | ------------------------------ | -------------------------------------------------------------------------------------- | ---------------------------------- |
15
+ | `ai/skill.md` (Claude Code) | `.claude/` directory exists at the project root | `.claude/skills/kerf-app/SKILL.md` |
16
+ | `ai/ui-skill.md` (Claude Code) | `.claude/` exists and the project declares `@kerfjs/ui` or setup state records UI mode | `.claude/skills/kerf-ui/SKILL.md` |
17
+ | `ai/cursorrules` (Cursor) | `.cursorrules` file or `.cursor/` directory exists | `.cursorrules` |
17
18
 
18
19
  A triggered file is then classified into one of three reported states (a fourth, "up-to-date," is silent):
19
20
 
21
+ With `--guidance-source AGENTS.md`, setup writes an import-only Claude skill.
22
+ The rule accepts its generated form and checks that the import resolves within
23
+ the workspace to a readable document containing Kerf and a project check command
24
+ instructions. A missing, malformed, or ineffective source is reported as
25
+ forked. This authored guidance mode does not compare the source to the bundled
26
+ skill version; review its Kerf instructions during upgrades.
27
+ When lint runs inside a workspace package, the rule finds setup state in a
28
+ parent directory and checks the workspace-root guidance. `eslint --fix`
29
+ restores the import-only skill when that mode is recorded in setup state.
30
+
20
31
  - **Missing** — the consumer's `dest` doesn't exist.
21
32
  - **Stale** — exists, parses cleanly, its `kerf-skill-version` line is older than the bundle's, and its canonical-section hash matches that version in the manifest's history.
22
33
  - **Forked** — the consumer's file no longer matches the canonical layout: marker is missing, marker appears more than once, `kerf-skill-version` line is missing, or the content above the marker has been edited.
@@ -78,4 +89,4 @@ Both `claude` and `cursor` default to `true`. Setting either to `false` makes th
78
89
  - It does not install the configs at `npm install` time — there are no postinstall scripts. The first lint pass after `npm install kerfjs` surfaces the recommendation.
79
90
  - It does not write to disk under plain `eslint` (no `--fix`). The warning is emitted; nothing changes on disk.
80
91
  - It does not push Claude Code or Cursor on consumers who haven't signalled they use them — no `.claude/` or `.cursor*` ⇒ silent.
81
- - It does not validate the *content* of the canonical files in the bundle. That's the kerf maintainer's responsibility (and the `check:ai-bundle-in-sync` gate in the kerf repo).
92
+ - It does not validate the _content_ of the canonical files in the bundle. That's the kerf maintainer's responsibility (and the `check:ai-bundle-in-sync` gate in the kerf repo).
@@ -40,8 +40,8 @@ delegate(rootEl, 'submit', ACTIONS.submit.selector, submit);
40
40
  String literals still work for ad-hoc fixed selectors:
41
41
 
42
42
  ```tsx
43
- <button data-action="save">Save</button>
44
- delegate(rootEl, 'click', '[data-action="save"]', save);
43
+ <button data-action="save">Save</button>;
44
+ delegate(rootEl, "click", '[data-action="save"]', save);
45
45
  ```
46
46
 
47
47
  ## Why this rule is AST-only
@@ -24,7 +24,12 @@ mount(bodyRoot, () => <Body />);
24
24
 
25
25
  // Composition via plain functions:
26
26
  const Header = () => <h1>{title.value}</h1>;
27
- const Body = () => <main><Header /><div>{count.value}</div></main>;
27
+ const Body = () => (
28
+ <main>
29
+ <Header />
30
+ <div>{count.value}</div>
31
+ </main>
32
+ );
28
33
  mount(root, () => <Body />);
29
34
  ```
30
35
 
@@ -9,21 +9,21 @@ Warn when `raw()` is called with a dynamic argument (any expression that is not
9
9
  ## ❌ Incorrect
10
10
 
11
11
  ```ts
12
- raw(userInput) // variable reference
13
- raw(fetchedHtml()) // function call
14
- raw(`<b>${title}</b>`) // template literal with expressions
15
- raw(isAdmin ? adminHtml : guestHtml) // conditional expression
12
+ raw(userInput); // variable reference
13
+ raw(fetchedHtml()); // function call
14
+ raw(`<b>${title}</b>`); // template literal with expressions
15
+ raw(isAdmin ? adminHtml : guestHtml); // conditional expression
16
16
  ```
17
17
 
18
18
  ## ✅ Correct
19
19
 
20
20
  ```ts
21
- raw('<p>Static markup</p>') // string literal — no warning
22
- raw(`<p>Static template</p>`) // expression-free template literal — no warning
21
+ raw("<p>Static markup</p>"); // string literal — no warning
22
+ raw(`<p>Static template</p>`); // expression-free template literal — no warning
23
23
 
24
24
  // Dynamic but audited — suppress with eslint-disable
25
25
  // eslint-disable-next-line kerfjs/no-raw-with-dynamic-arg
26
- raw(DOMPurify.sanitize(marked(userMarkdown)))
26
+ raw(DOMPurify.sanitize(marked(userMarkdown)));
27
27
  ```
28
28
 
29
29
  ## Why `warn` and not `error`
@@ -7,8 +7,8 @@ Prefer `attr('name', 'value').selector` over a literal `[name="value"]` selector
7
7
  ## ❌ Discouraged
8
8
 
9
9
  ```tsx
10
- <button data-action="toggle">Toggle</button>
11
- delegate(root, 'click', '[data-action="toggle"]', handler);
10
+ <button data-action="toggle">Toggle</button>;
11
+ delegate(root, "click", '[data-action="toggle"]', handler);
12
12
  ```
13
13
 
14
14
  The JSX attribute and the selector string are two independent literals; renaming the action key in JSX leaves the delegate selector unchanged, and the handler silently stops firing.
@@ -16,14 +16,14 @@ The JSX attribute and the selector string are two independent literals; renaming
16
16
  ## ✅ Recommended
17
17
 
18
18
  ```tsx
19
- import { attr, delegate, type AttrSpec } from 'kerfjs';
19
+ import { attr, delegate, type AttrSpec } from "kerfjs";
20
20
 
21
21
  const ACTIONS = {
22
- toggle: attr('data-action', 'toggle'),
23
- } as const satisfies Record<string, AttrSpec<'data-action'>>;
22
+ toggle: attr("data-action", "toggle"),
23
+ } as const satisfies Record<string, AttrSpec<"data-action">>;
24
24
 
25
- <button {...ACTIONS.toggle.attrs}>Toggle</button>
26
- delegate(root, 'click', ACTIONS.toggle.selector, handler);
25
+ <button {...ACTIONS.toggle.attrs}>Toggle</button>;
26
+ delegate(root, "click", ACTIONS.toggle.selector, handler);
27
27
  ```
28
28
 
29
29
  Rename `'toggle'` to `'on'` in the `ACTIONS` map and both the rendered attribute and the delegate selector update — no string-grep migration required.
@@ -10,7 +10,7 @@ Maps to **kerf Hard Rule 11** — kerf's JSX runtime looks up custom-element typ
10
10
  declare global {
11
11
  namespace JSX {
12
12
  interface IntrinsicElements {
13
- 'my-tag': { foo?: string };
13
+ "my-tag": { foo?: string };
14
14
  }
15
15
  }
16
16
  }
@@ -19,10 +19,10 @@ declare global {
19
19
  ## ✅ Correct
20
20
 
21
21
  ```ts
22
- declare module 'kerfjs/jsx-runtime' {
22
+ declare module "kerfjs/jsx-runtime" {
23
23
  namespace JSX {
24
24
  interface IntrinsicElements {
25
- 'my-tag': KerfCustomElement & { foo?: string };
25
+ "my-tag": KerfCustomElement & { foo?: string };
26
26
  }
27
27
  }
28
28
  }
@@ -31,7 +31,11 @@ declare module 'kerfjs/jsx-runtime' {
31
31
  Import the building-block types from `kerfjs/jsx-runtime`:
32
32
 
33
33
  ```ts
34
- import type { KerfCustomElement, KerfBaseAttrs, AttrLike } from 'kerfjs/jsx-runtime';
34
+ import type {
35
+ KerfCustomElement,
36
+ KerfBaseAttrs,
37
+ AttrLike,
38
+ } from "kerfjs/jsx-runtime";
35
39
  ```
36
40
 
37
41
  ## What this rule does NOT catch
@@ -0,0 +1,43 @@
1
+ # `kerfjs/prefer-signal-leaf`
2
+
3
+ An editor suggestion can move a dependency from a Kerf mount render to one DOM text node or attribute. If a signal is the render's only dependency, subsequent writes update the bound node without running the render again.
4
+
5
+ ```tsx
6
+ import { mount, signal } from "kerfjs";
7
+
8
+ const label = signal("Ready");
9
+ mount(root, () => <span>{label.value}</span>);
10
+ // Editor suggestion: <span>{label}</span>
11
+ ```
12
+
13
+ ## Enabling the rule
14
+
15
+ Add a flat-config entry to the project's existing ESLint configuration. Install `@typescript-eslint/parser` and its supported TypeScript peer. The rule uses the TypeScript program supplied by the parser. All Kerf presets leave it off.
16
+
17
+ ```js
18
+ import kerfjs from "eslint-plugin-kerfjs";
19
+ import parser from "@typescript-eslint/parser";
20
+
21
+ export default [
22
+ {
23
+ files: ["**/*.tsx"],
24
+ languageOptions: { parser, parserOptions: { projectService: true } },
25
+ plugins: { kerfjs },
26
+ rules: { "kerfjs/prefer-signal-leaf": "warn" },
27
+ },
28
+ ];
29
+ ```
30
+
31
+ The file's TypeScript project needs strict null checks, automatic JSX (`react-jsx` or `react-jsxdev`), and `jsxImportSource: "kerfjs"`. An untyped file receives no suggestions. Files with JSX pragmas are skipped.
32
+
33
+ ## Which reads qualify?
34
+
35
+ - A direct text child containing just `name.value` with a string or number payload, or `title={name.value}` with a string payload.
36
+ - `name` is a stable `const` outside the render, initialized by a named `signal` or `computed` import from `kerfjs`. Aliases work. A similarly shaped object, a getter, or a nullable or erased signal type gives insufficient evidence.
37
+ - The element is returned directly by an inline callback passed to the imported Kerf `mount`. Its JSX ancestors are fragments or ordinary `div`, `span`, `small`, `em`, or `strong` elements. The narrow list avoids raw-text, form, SVG, parser-sensitive and custom-element contexts. Spreads, content editing and explicit morph ownership can change who controls a node, so those hosts and their descendants are skipped.
38
+
39
+ Reads used for branching, formatting, custom component props, and list rows need a separate decision about who should subscribe. A signal carrying `SafeHtml` can render markup when read in JSX, whereas a direct text binding would stringify its value.
40
+
41
+ ## Reviewing the suggestion
42
+
43
+ Review work elsewhere in the mount that relies on a rerender, including effects of calling other functions. Apply the suggestion when the text or title should update independently. Code that observes child-node boundaries, parser normalization of control characters, or mount invocation counts can observe the change. ESLint offers the edit in the editor and leaves the file alone under `--fix`. The runtime `valueOnlyRerender` warning observes actual renders and can surface patterns outside this rule's static checks.
@@ -7,24 +7,32 @@ Maps to **kerf Hard Rule 2** — the keyed reconciler matches items by `id` firs
7
7
  ## ❌ Incorrect
8
8
 
9
9
  ```tsx
10
- each(items, (item) => <li>{item.name}</li>)
10
+ each(items, (item) => <li>{item.name}</li>);
11
11
 
12
12
  each(items, (item) => {
13
13
  return <li class="row">{item.name}</li>;
14
- })
14
+ });
15
15
 
16
- each(items, (item) => <>{item.name}</>)
16
+ each(items, (item) => <>{item.name}</>);
17
+
18
+ // A dynamic object does not prove that a component receives a row key.
19
+ each(items, (item) => <ListActionRow rootAttributes={item.attrs} />);
17
20
  ```
18
21
 
19
22
  ## ✅ Correct
20
23
 
21
24
  ```tsx
22
- each(items, (item) => <li data-key={item.id}>{item.name}</li>)
25
+ each(items, (item) => <li data-key={item.id}>{item.name}</li>);
26
+
27
+ each(items, (item) => <li id={item.id}>{item.name}</li>);
23
28
 
24
- each(items, (item) => <li id={item.id}>{item.name}</li>)
29
+ // Component roots can pass a statically named key through rootAttributes.
30
+ each(items, (item) => (
31
+ <ListActionRow rootAttributes={{ "data-key": item.id }} />
32
+ ));
25
33
 
26
34
  // Spread attributes are conservatively allowed — they may include the key.
27
- each(items, (item) => <li {...item.attrs}>{item.name}</li>)
35
+ each(items, (item) => <li {...item.attrs}>{item.name}</li>);
28
36
  ```
29
37
 
30
38
  ## What this rule does NOT catch
@@ -32,3 +40,5 @@ each(items, (item) => <li {...item.attrs}>{item.name}</li>)
32
40
  - Non-inline callbacks: `each(items, renderRow)` — the rule only inspects arrow / function-expression callbacks passed directly to `each()`.
33
41
  - `each` calls qualified by a namespace: `MyLib.each(items, …)` — the rule only fires on a bare `each` identifier.
34
42
  - Computed key keys behind a runtime branch: if the JSX root only sometimes carries a `data-key`, the rule reports the missing static attribute. Fix by always setting it.
43
+ - A component's dynamic `rootAttributes` object or unknown computed property name is not treated as proof of a key. Use an object literal with a `"data-key"` or `id` property where the component forwards it to its single root. A later object spread or computed property may overwrite an earlier key, so put the key last.
44
+ - The `rootAttributes` exception applies to component JSX roots, not native elements or fragment roots. The rule cannot verify a component's implementation; confirm that it forwards the key to the rendered root.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Require capturing the disposer returned by `delegate()` and `delegateCapture()`.
4
4
 
5
- Both helpers install a single listener on the root element and return a `() => void` disposer — the *only* way to remove the listener once it's attached. Discarding the return value is safe in exactly one case: the registration is genuinely page-lifetime (root is `document.body` or another never-torn-down element, attached once at startup, never re-registered). In every other case the listener closure pins `rootEl`, `handler`, and everything the handler closes over (stores, signals, app state) — so an undisposed delegate on a transient root leaks both the listener and the app graph it references, and re-mount cycles stack listeners linearly. `mount()`'s own disposer does NOT remove delegates for you.
5
+ Both helpers install a single listener on the root element and return a `() => void` disposer — the _only_ way to remove the listener once it's attached. Discarding the return value is safe in exactly one case: the registration is genuinely page-lifetime (root is `document.body` or another never-torn-down element, attached once at startup, never re-registered). In every other case the listener closure pins `rootEl`, `handler`, and everything the handler closes over (stores, signals, app state) — so an undisposed delegate on a transient root leaks both the listener and the app graph it references, and re-mount cycles stack listeners linearly. `mount()`'s own disposer does NOT remove delegates for you.
6
6
 
7
7
  See [kerf docs §5.3 — Disposers](https://brianwestphal.github.io/kerf/docs/5-event-delegation/#53-disposers) for the full rationale.
8
8
 
@@ -49,8 +49,8 @@ Or collect into a disposer array:
49
49
  ```ts
50
50
  const disposers: Array<() => void> = [];
51
51
  disposers.push(mount(host, render));
52
- disposers.push(delegate(host, 'click', '[data-action]', onAction));
53
- disposers.push(delegate(host, 'keydown', '[data-edit]', onEdit));
52
+ disposers.push(delegate(host, "click", "[data-action]", onAction));
53
+ disposers.push(delegate(host, "keydown", "[data-edit]", onEdit));
54
54
 
55
55
  function teardown() {
56
56
  for (const off of disposers) off();
@@ -64,13 +64,18 @@ If the registration is attached once at module load and the root never tears dow
64
64
 
65
65
  ```ts
66
66
  // 1. The `void` operator as an explicit-discard sigil.
67
- void delegate(document.body, 'click', ACTIONS.inc.selector, () => count.value++);
67
+ void delegate(
68
+ document.body,
69
+ "click",
70
+ ACTIONS.inc.selector,
71
+ () => count.value++,
72
+ );
68
73
  ```
69
74
 
70
75
  ```ts
71
76
  // 2. Standard eslint-disable for one-off cases.
72
77
  // eslint-disable-next-line kerfjs/require-delegate-disposer
73
- delegate(document.body, 'click', ACTIONS.inc.selector, () => count.value++);
78
+ delegate(document.body, "click", ACTIONS.inc.selector, () => count.value++);
74
79
  ```
75
80
 
76
81
  `void` is the lower-friction option when the file has many page-lifetime registrations clustered together; eslint-disable carries the rule name with it, which makes it easier to grep for.
@@ -0,0 +1,43 @@
1
+ # `ui-component-ownership`
2
+
3
+ Components own their styles and are configured, never overridden. This rule
4
+ keeps application and component-package code from reaching into another
5
+ package's component through its variables:
6
+
7
+ - `KUI-L020` — a string, template, object key, or `style` value references a
8
+ component's private `--_<root>-*` variable (`--_kui-list-gap`), or any
9
+ `--_kui-*` variable. Private variables are implementation; reading or writing
10
+ them breaks when the component changes.
11
+ - `KUI-L021` — code assigns a component token that a typed prop sets, in a
12
+ `style` string (`style="--kui-list-gap: 4px"`), a style object key
13
+ (`style={{ '--kui-floating-toolbar-inset': '0' }}`), or
14
+ `style.setProperty('--kui-disclosure-arrow-size', …)`. Set the prop instead
15
+ (`<List gap="xs" />`).
16
+
17
+ Both messages name the owning component and end with the same guidance: if no
18
+ configuration covers the need, report the component gap to the owning package
19
+ (open a feature request) instead of overriding it.
20
+
21
+ ```tsx
22
+ // KUI-L020 / KUI-L021
23
+ <div style="--_kui-list-gap: 2px; --kui-list-gap: 4px">…</div>;
24
+
25
+ // Configure the component instead.
26
+ <List gap="xs">…</List>;
27
+ ```
28
+
29
+ Ownership comes from the loaded composition catalogs, so third-party component
30
+ packages declared in `.kerf-ui-profile.json` get the same protection. A file
31
+ inside the package that owns a component (the nearest `package.json` names the
32
+ catalog entry's `package`) may use that component's own private variables and
33
+ tokens. Reading a public token (`var(--kui-list-divider-color)`) and setting a
34
+ theme token with no equivalent prop remain configuration and are not reported.
35
+
36
+ CSS files are outside ESLint's reach: `kerf-ui-analyze` (and `kerf-ui-doctor`)
37
+ report the same `KUI-L020` / `KUI-L021` ids in stylesheets, plus `KUI-L019`
38
+ (a rule whose subject is a cataloged component) and `KUI-L022` (a hook class
39
+ on a component's root). See `@kerfjs/ui/docs/ui-analyzer.md`.
40
+
41
+ Exact profile exceptions may name either id. The rule reads
42
+ `@kerfjs/ui/ai/component-composition.json` by default; see the plugin README for
43
+ alternate catalog settings.
@@ -0,0 +1,115 @@
1
+ # `ui-composition`
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. `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
+
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
+ Toolbar zones accept `KerfUiContent`, so the zone rule allows direct JSX
7
+ controls and custom components there. Their own parent contracts still apply,
8
+ including when a direct child is supplied through a zone prop.
9
+
10
+ An additional JSX export from an entry can declare its own `jsxExports.<name>.parents` contract. It uses that placement instead of the entry's root placement and is opaque to zone matching, so an action link does not impersonate its enclosing control group.
11
+
12
+ `KUI-L202` inspects JSX written directly in a bound zone prop, including its
13
+ fragments, arrays, and conditional branches. It does not follow a local binding
14
+ such as `const actions = <div />; <TabBar trailing={actions} />`. Review those
15
+ bindings against the zone's catalog contract; an unknown expression produces
16
+ no zone-child diagnostic.
17
+
18
+ ## Inset-free children (`KUI-L204`)
19
+
20
+ An entry may declare `insetFreeChildren`: prop conditions under which its
21
+ direct children must bring no content-item inset, because owner chrome already
22
+ provides that geometry. `@kerfjs/ui` declares it for `Disclosure` with
23
+ `appearance="embedded"`. A direct child (including through fragments, arrays,
24
+ and conditional branches) reports `KUI-L204` when its catalog geometry owns
25
+ its margin, border, and padding (`self` on all three) and none of its own
26
+ `insetFreeWhen` conditions holds. `Text` declares `flush` and
27
+ `variant="span"` as its inset-free forms, so the message tells you to set one
28
+ of them; a child with no inset-free form should be replaced with inline
29
+ content or a `Text flush`.
30
+
31
+ ```tsx
32
+ import { ContentItem, Disclosure, Text } from '@kerfjs/ui';
33
+
34
+ <ContentItem>
35
+ <Disclosure title="AI Feedback" appearance="embedded">
36
+ <Text>Group Export and Share.</Text> {/* KUI-L204: set `flush` */}
37
+ <Text flush>Keep Delete in the overflow menu.</Text> {/* valid */}
38
+ </Disclosure>
39
+ </ContentItem>;
40
+ ```
41
+
42
+ The check reads only statically written props: a parent `appearance` or a
43
+ child prop supplied by an expression or a spread is not reported. Uncataloged
44
+ children (intrinsic elements, text) and entries whose geometry is not owned on
45
+ all three sides, such as `List`, are not checked.
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.
72
+
73
+ ## Application and third-party wrappers
74
+
75
+ Beyond `@kerfjs/ui`'s own catalog, the rule loads every composition catalog the
76
+ resolved `.kerf-ui-profile.json` declares under `catalogs`. Their components
77
+ resolve by package subpath (`import { GroupWrap } from '@acme/bits/group-wrap'`,
78
+ matched to the entry's `publicExports`) or, for an application's own relative
79
+ imports, by source file (matched to the entry's `source`, trying the TypeScript
80
+ ESM extensions a `.js` specifier stands for). An export without a `subpath` (a
81
+ private application's, which is never imported by package name) resolves only
82
+ by source file.
83
+
84
+ A relative import may also reach the source file through relative re-exports,
85
+ the way apps import wrappers through a components barrel:
86
+ `import { DemandSegmentsControl } from './components/index.js'` resolves when
87
+ `index.ts` has `export { DemandSegmentsControl } from '../demand-segments-control.js'`,
88
+ a renamed `export { X as Y } from …` (import `Y`), or `export * from …`, and
89
+ through chains of them (a directory import tries its `index` file). Type-only
90
+ and namespace (`export * as ns`) re-exports, a component defined in the barrel
91
+ itself, and re-exports of anything the catalogs do not declare stay unresolved,
92
+ and cycles stop without resolving.
93
+
94
+ An entry that declares `rendersAs` (a wrapper that renders one of the listed
95
+ cataloged roots, or nothing) is checked as those roots:
96
+
97
+ - **Zones (`KUI-L202`):** the zone must accept every declared root.
98
+ - **Parents (`KUI-L201`):** each root's listed parents apply where the wrapper
99
+ is placed, and a wrapper used as a parent counts as each of its roots. A
100
+ placement reports once, using the first violated root requirement before a
101
+ separate wrapper requirement if both apply.
102
+ - **Cardinality (`KUI-L203`):** the wrapper counts as zero or one child, since
103
+ it may render nothing.
104
+
105
+ ```tsx
106
+ import { Toolbar } from '@kerfjs/ui';
107
+ import { DemandSegmentsControl } from './demand-segments-control.js';
108
+
109
+ // Valid when the app's catalog declares
110
+ // rendersAs: ["@kerfjs/ui:toolbar-control-group"].
111
+ <Toolbar trailing={<DemandSegmentsControl />} />;
112
+ ```
113
+
114
+ A wrapper without `rendersAs`, or one the profile's catalogs do not declare,
115
+ is still an unknown element and reports `KUI-L202` in a cataloged zone.