eslint-plugin-kerfjs 5.0.0-beta.13 → 5.0.0-beta.130
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 +85 -21
- package/docs/rules/ai-assistant-configs.md +17 -6
- package/docs/rules/no-generated-view-edits.md +42 -0
- package/docs/rules/no-inline-jsx-event-handlers.md +2 -2
- package/docs/rules/no-nested-mount.md +6 -1
- package/docs/rules/no-raw-with-dynamic-arg.md +7 -7
- package/docs/rules/prefer-attr-selector.md +7 -7
- package/docs/rules/prefer-module-jsx-augmentation.md +8 -4
- package/docs/rules/require-data-key-in-each.md +16 -6
- package/docs/rules/require-delegate-disposer.md +10 -5
- package/docs/rules/ui-component-ownership.md +43 -0
- package/docs/rules/ui-composition.md +116 -0
- package/docs/rules/ui-css-values.md +51 -0
- package/docs/rules/ui-exceptional-shorthands.md +22 -0
- package/docs/rules/ui-preferences.md +41 -0
- package/docs/rules/ui-public-boundaries.md +48 -0
- package/docs/rules/ui-wiring.md +57 -0
- package/index.js +51 -1
- package/lib/html-template-classes.js +104 -0
- package/lib/rules/ai-assistant-configs.js +184 -23
- package/lib/rules/no-generated-view-edits.js +81 -0
- package/lib/rules/no-inline-jsx-event-handlers.js +1 -1
- package/lib/rules/no-nested-mount.js +2 -1
- package/lib/rules/no-raw-with-dynamic-arg.js +7 -6
- package/lib/rules/prefer-module-jsx-augmentation.js +3 -2
- package/lib/rules/require-data-key-in-each.js +38 -3
- package/lib/rules/require-delegate-disposer.js +2 -1
- package/lib/rules/ui-component-ownership.js +211 -0
- package/lib/rules/ui-composition.js +425 -0
- package/lib/rules/ui-css-values.js +3 -0
- package/lib/rules/ui-exceptional-shorthands.js +3 -0
- package/lib/rules/ui-preferences.js +116 -0
- package/lib/rules/ui-public-boundaries.js +196 -0
- package/lib/rules/ui-wiring.js +440 -0
- package/lib/ui-contract.js +643 -0
- package/lib/ui-css-value-contracts.js +317 -0
- package/package.json +8 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# `ui-css-values`
|
|
2
|
+
|
|
3
|
+
Checks literal JSX and direct component-function calls against each component's
|
|
4
|
+
cataloged `cssValueProps` contracts. The catalog keeps length, size, flex,
|
|
5
|
+
color, declaration-list, media-query, and numeric-pixel grammars distinct and
|
|
6
|
+
names their accepted helpers, finite shorthands, and raw-value policy.
|
|
7
|
+
A contract path is dot-separated object members, each optionally suffixed with
|
|
8
|
+
`[]` to visit every array element: `gap`, `choices[].swatch`, `iconTile.color`.
|
|
9
|
+
A member that is not a literal object or array (a tone string such as
|
|
10
|
+
`iconTile="brand"`, a variable) is skipped.
|
|
11
|
+
|
|
12
|
+
Stable diagnostics are `KUI-L013` (raw or unknown shorthand), `KUI-L014`
|
|
13
|
+
(wrong property helper), `KUI-L015` (non-standalone expression), `KUI-L016`
|
|
14
|
+
(forbidden declaration list). Messages name the preferred shorthand or helper.
|
|
15
|
+
Dynamic values are left to TypeScript rather than guessed. The review finding
|
|
16
|
+
`KUI-L017` (exceptional spacing shorthand) is reported by the companion
|
|
17
|
+
[`ui-exceptional-shorthands`](ui-exceptional-shorthands.md) rule so it can carry
|
|
18
|
+
the `warn` severity that matches the analyzer's `review` classification.
|
|
19
|
+
|
|
20
|
+
Only component exports carry an entry's contracts. A catalog entry's
|
|
21
|
+
`publicExports` also lists the helpers its props consume (`Select` ships
|
|
22
|
+
`uiColor`, `List` ships `px`, `rem`, and `flex`); a helper call such as
|
|
23
|
+
`flex({ gap: '12px' })` is not a `List` call and is never checked as one. A
|
|
24
|
+
component export is one whose name starts with an uppercase letter, the rule
|
|
25
|
+
JSX itself uses to tell a component tag from an intrinsic element; a default
|
|
26
|
+
import keeps its subpath's entry. `@kerfjs/ui`'s catalog check enforces the
|
|
27
|
+
convention for the package, and `kerf-ui-analyze` applies the same rule.
|
|
28
|
+
|
|
29
|
+
A helper is identified by its imported name when its module is the
|
|
30
|
+
component's package or any subpath of it, the same way `kerf-ui-analyze`
|
|
31
|
+
resolves it. Named, aliased, and namespace imports all count, so these are
|
|
32
|
+
equivalent:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { ListItem } from '@kerfjs/ui/list-item';
|
|
36
|
+
import { foregroundColor } from '@kerfjs/ui/css-values';
|
|
37
|
+
import { foregroundColor as fg } from '@kerfjs/ui';
|
|
38
|
+
import * as css from '@kerfjs/ui/css-values';
|
|
39
|
+
|
|
40
|
+
// Each reports KUI-L014: a fill takes `fillColor()`, `uiColor()`, or `colorVar()`.
|
|
41
|
+
<ListItem label="A" iconTile={{ color: foregroundColor('#000') }} />;
|
|
42
|
+
<ListItem label="B" iconTile={{ color: fg('#000') }} />;
|
|
43
|
+
<ListItem label="C" iconTile={{ color: css.foregroundColor('#000') }} />;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
A same-named helper from another package (`other-ui/css-values`, or a
|
|
47
|
+
package that only shares the prefix, such as `@kerfjs/ui-extras`) is not a
|
|
48
|
+
cataloged helper, and the rule leaves its call alone.
|
|
49
|
+
|
|
50
|
+
Third-party component suites can provide the same contracts in a composition
|
|
51
|
+
catalog through `settings.kerfjs.ui.catalog` and its matching selection catalog.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# `ui-exceptional-shorthands`
|
|
2
|
+
|
|
3
|
+
Reports `KUI-L017` when a Kerf UI component prop uses a valid but exceptional
|
|
4
|
+
off-scale shorthand — for example `<List gap="s" />` or `<Row gap="xl" />`,
|
|
5
|
+
where the catalog lists `s` and `xl` under the prop's `exceptionalShorthands`.
|
|
6
|
+
The value renders correctly; the finding asks whether the off-scale choice is
|
|
7
|
+
deliberate. The message names the canonical shorthands and helpers to prefer.
|
|
8
|
+
|
|
9
|
+
This is a review finding, not a contract violation. The analyzer classifies
|
|
10
|
+
`KUI-L017` as `review`, so the rule is `warn` in both `recommended-ui` and
|
|
11
|
+
`strict-ui`, and `kerf-ui-doctor` merges the ESLint and analyzer reports into a
|
|
12
|
+
single review finding. To make review findings fail a run, use the doctor's
|
|
13
|
+
`failOn: 'review'` rather than promoting this rule to `error`.
|
|
14
|
+
|
|
15
|
+
Keep a deliberate choice by recording a profile exception for `KUI-L017` with a
|
|
16
|
+
rationale, or move to a canonical shorthand or a typed helper such as
|
|
17
|
+
`space('s')`.
|
|
18
|
+
|
|
19
|
+
The rule shares its catalog walk with [`ui-css-values`](ui-css-values.md),
|
|
20
|
+
which reports the `KUI-L013`–`KUI-L016` contract violations at `error`. It
|
|
21
|
+
covers JSX and direct component calls against the bundled `@kerfjs/ui` catalog
|
|
22
|
+
and any third-party catalog configured through `settings.kerfjs.ui.catalog`.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# `ui-preferences`
|
|
2
|
+
|
|
3
|
+
Reports cataloged components listed in an application UI profile preference's `avoid` set and points to the package-qualified `preferred` component. The stable diagnostic is `KUI-L301`.
|
|
4
|
+
|
|
5
|
+
A component matches whether it is rendered through an imported export (`<WaButtonGroup />`) or written directly as its custom-element tag (`<wa-dropdown>`), which resolves through the selection catalog's `customElement`. The `@kerfjs/ui` package defaults avoid every `Discouraged` Web Awesome element, so each of these reports and names the Kerf component to render instead:
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
<wa-dropdown>…</wa-dropdown> // KUI-L301: prefer @kerfjs/ui:popup-menu
|
|
9
|
+
<wa-select>…</wa-select> // KUI-L301: prefer @kerfjs/ui:select
|
|
10
|
+
<wa-tab-group>…</wa-tab-group> // KUI-L301: prefer @kerfjs/ui:tab-bar
|
|
11
|
+
<wa-icon name="gear" /> // KUI-L301: prefer @kerfjs/ui:lucide-icon
|
|
12
|
+
<wa-button>Save</wa-button> // KUI-L301: prefer @kerfjs/ui:button
|
|
13
|
+
<wa-input label="Name" /> // KUI-L301: prefer @kerfjs/ui:text-field
|
|
14
|
+
```
|
|
15
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# `ui-public-boundaries`
|
|
2
|
+
|
|
3
|
+
Rejects `kui-*` classes and `--kui-*` custom properties that are not listed in the versioned composition catalog, and cataloged component classes written onto elements the application owns. This keeps application code out of private component anatomy while allowing cataloged styling seams.
|
|
4
|
+
|
|
5
|
+
Diagnostics are stable: `KUI-L101` identifies a private/unknown class, `KUI-L102` an unknown token, and `KUI-L103` a component's anatomy class placed on an application-owned element. Exact profile exceptions can name any of these ids. The rule deliberately does not rewrite selectors, tokens, or markup because there is no generally safe replacement.
|
|
6
|
+
|
|
7
|
+
## Component anatomy on your own element (`KUI-L103`)
|
|
8
|
+
|
|
9
|
+
A public class such as `kui-toolbar` or `kui-pane__content` is the rendered anatomy of a component. Writing it onto your own element recreates the component by class: the element inherits (and invites you to restyle) the component's CSS without its props, behavior, accessibility, or future fixes. Components own their styles; render and configure them instead.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<div class="kui-toolbar">…</div> // KUI-L103: render `Toolbar`
|
|
13
|
+
<aside class="kui-pane"><nav class="kui-pane__content"> // KUI-L103: render `Pane`
|
|
14
|
+
<wa-dropdown class="kui-popup-menu">…</wa-dropdown> // KUI-L103: render `PopupMenu`
|
|
15
|
+
<Text class="kui-toolbar-text" /> // KUI-L103: render `ToolbarText`
|
|
16
|
+
<div class="kui-content-item">…</div> // KUI-L103: render `ContentItem`
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The catalog marks the classes an application may place with `boundaries.placeableClasses`; these stay allowed:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
<div id="app" class="kui-app-root" /> // document root
|
|
23
|
+
<main class="kui-content kui-scroll-owner" /> // layout utilities
|
|
24
|
+
<footer class="kui-control-cluster kui-content-item" /> // item geometry on a non-div carrier
|
|
25
|
+
<Toolbar className="kui-toolbar" /> // a component's own element
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
A placeable class can still be a component's own root. When a catalog entry names the `boundaries.rootElement` its component renders around its placeable classes, a plain element of that tag carrying them is the component recreated and is reported: `<div class="kui-content-item">` is exactly what `ContentItem` renders. The class stays placeable on any other carrier — a `<ul>`, a `Text`, or a control-cluster `<footer>` that must carry the geometry itself. `@kerfjs/ui`'s own `check:guidance` derives its repository check from the same catalog fields, so the two cannot disagree.
|
|
29
|
+
|
|
30
|
+
The component a diagnostic names is the export named after the class's block, tried from the whole block down to its last word (`kui-toolbar-action-link` → `ToolbarActionLink`, `kui-pane__content` → `Pane`, `acme-meter__bar` → `Meter`), else the entry's own component, else every component the entry exports. That rule ships once, as `@kerfjs/ui/ai/component-class-owners.cjs`; the rule loads it beside `application-ui-profile-sync.cjs`, and `@kerfjs/ui`'s generated `ai/components/*.md` pages render their "render X instead" lines from the same file, so the lint message and the component reference always name the same component. An `@kerfjs/ui` too old to ship it fails the contract load (`KUI-L090`) rather than guessing.
|
|
31
|
+
|
|
32
|
+
## Component packages
|
|
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). 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
|
+
|
|
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
|
+
|
|
38
|
+
The no-build `kerfjs/html` tagged template writes the same markup without JSX, so its `class` attributes carry the same `KUI-L101` / `KUI-L103` contract. The rule reads the template's static parts by the runtime's own rules: a complete static value (`class="kui-pane"`, `class='…'`, or unquoted) counts, tag and attribute names are case-insensitive, and the element is the tag the markup names, so a plain `<div class="kui-content-item">` is `ContentItem` recreated there too. A hole is a whole attribute value (`class=${cls}`), so the class it supplies is unknown and skipped; comments, text, and tags or attributes whose name is a hole are not inspected. Only the `html` tag imported from `kerfjs/html` (by name, alias, or namespace) is read.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { html } from 'kerfjs/html';
|
|
42
|
+
html`<aside class="kui-pane">…</aside>`; // KUI-L103: render `Pane`
|
|
43
|
+
html`<div class="kui-content-item">…</div>`; // KUI-L103: render `ContentItem`
|
|
44
|
+
html`<ul class="kui-content-item">…</ul>`; // allowed: placeable on a <ul>
|
|
45
|
+
html`<aside class=${paneClass}>…</aside>`; // not inspected: the value is a hole
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The rule reads `@kerfjs/ui/ai/component-composition.json` by default. See the plugin README for alternate catalog settings used by monorepos and package authors.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# `ui-wiring`
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
Declare application entry modules in the application UI profile to check root wiring once per entry:
|
|
6
|
+
|
|
7
|
+
```json
|
|
8
|
+
{ "schemaVersion": 1, "scope": "workspace", "wiring": { "entries": ["src/main.tsx"] } }
|
|
9
|
+
```
|
|
10
|
+
|
|
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
|
+
|
|
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
|
+
|
|
15
|
+
For server-rendered pages whose document loads a separate browser entry, pair the roots in one item:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{ "wiring": { "entries": [{ "render": ["src/routes/admin/index.tsx"], "client": ["src/client/app/admin.ts"] }] } }
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The rule checks an application-scoped obligation raised by any module reachable from `render` against helper calls and registration imports reachable from any `client` root in the same item. It reports a missing obligation at the first client entry. Each pair is isolated; another pair's client wiring does not satisfy it. String entries keep their existing single-graph behavior. List every server page that loads that browser entry in `render`; the HTML document's script URL is not an import edge the rule can discover. `wiring.scope: "module"` obligations remain local to the rendering module.
|
|
22
|
+
|
|
23
|
+
For a page-lifetime root helper, declare the actual app entry in the workspace `.kerf-ui-profile.json`. For example, if `src/client/app.tsx` imports `init.ts`, `init.ts` calls `wireShellSearch(root)`, and that imported helper calls `wireSearchFields(root)`, use:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{ "schemaVersion": 1, "scope": "workspace", "wiring": { "entries": ["src/client/app.tsx"] } }
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The entry graph then covers a `SearchField` in an imported view without duplicate wiring in that view. Include every independently mounted application entry. The path must resolve through relative imports from each entry to both the view and the helper; merely naming the helper in the profile does not count as invoking it.
|
|
30
|
+
|
|
31
|
+
For `ChoiceChips`, only `multiple={true}` needs `wireChoiceChips`. The default radio group and `multiple="toggle"` use native inputs, so they create no wiring finding. A dynamic `multiple` expression still requires wiring because it may render the listbox mode.
|
|
32
|
+
|
|
33
|
+
Consumer composition catalogs can name an application helper's defining file in `wiring.sources`:
|
|
34
|
+
|
|
35
|
+
```json
|
|
36
|
+
"wiring": {
|
|
37
|
+
"required": true,
|
|
38
|
+
"helpers": ["wireTicketSearch"],
|
|
39
|
+
"sources": [{ "export": "wireTicketSearch", "source": "src/interactions/ticket-search.ts" }]
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
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.
|
|
44
|
+
|
|
45
|
+
Application-owned helpers default to returning a disposer. If a composition root is typed `void` and owns page-lifetime wiring internally, set `"returnsDisposer": false` on its `wiring.sources` entry. A direct call then satisfies `KUI-L401` without triggering `KUI-L402` or requiring a meaningless `void` operator. Set this only when the exported helper genuinely has no cleanup handle; disposer-returning helpers still need their return value retained or returned.
|
|
46
|
+
|
|
47
|
+
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):
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
"wiring": { "required": true, "helpers": [], "actions": ["open-card"], "obligations": ["Handle open-card at the page root."] }
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`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.
|
|
54
|
+
|
|
55
|
+
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.
|
|
56
|
+
|
|
57
|
+
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
|
@@ -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';
|
|
@@ -6,11 +7,19 @@ import preferAttrSelector from './lib/rules/prefer-attr-selector.js';
|
|
|
6
7
|
import preferModuleJsxAugmentation from './lib/rules/prefer-module-jsx-augmentation.js';
|
|
7
8
|
import requireDataKeyInEach from './lib/rules/require-data-key-in-each.js';
|
|
8
9
|
import requireDelegateDisposer from './lib/rules/require-delegate-disposer.js';
|
|
10
|
+
import uiComponentOwnership from './lib/rules/ui-component-ownership.js';
|
|
11
|
+
import uiComposition from './lib/rules/ui-composition.js';
|
|
12
|
+
import uiCssValues from './lib/rules/ui-css-values.js';
|
|
13
|
+
import uiExceptionalShorthands from './lib/rules/ui-exceptional-shorthands.js';
|
|
14
|
+
import uiPreferences from './lib/rules/ui-preferences.js';
|
|
15
|
+
import uiPublicBoundaries from './lib/rules/ui-public-boundaries.js';
|
|
16
|
+
import uiWiring from './lib/rules/ui-wiring.js';
|
|
9
17
|
|
|
10
18
|
const plugin = {
|
|
11
|
-
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.
|
|
19
|
+
meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.130' },
|
|
12
20
|
rules: {
|
|
13
21
|
'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
|
|
22
|
+
'no-generated-view-edits': noGeneratedViewEdits,
|
|
14
23
|
'no-raw-with-dynamic-arg': noRawWithDynamicArg,
|
|
15
24
|
'require-data-key-in-each': requireDataKeyInEach,
|
|
16
25
|
'require-delegate-disposer': requireDelegateDisposer,
|
|
@@ -18,6 +27,13 @@ const plugin = {
|
|
|
18
27
|
'prefer-module-jsx-augmentation': preferModuleJsxAugmentation,
|
|
19
28
|
'prefer-attr-selector': preferAttrSelector,
|
|
20
29
|
'ai-assistant-configs': aiAssistantConfigs,
|
|
30
|
+
'ui-component-ownership': uiComponentOwnership,
|
|
31
|
+
'ui-composition': uiComposition,
|
|
32
|
+
'ui-css-values': uiCssValues,
|
|
33
|
+
'ui-exceptional-shorthands': uiExceptionalShorthands,
|
|
34
|
+
'ui-preferences': uiPreferences,
|
|
35
|
+
'ui-public-boundaries': uiPublicBoundaries,
|
|
36
|
+
'ui-wiring': uiWiring,
|
|
21
37
|
},
|
|
22
38
|
configs: {},
|
|
23
39
|
};
|
|
@@ -30,6 +46,9 @@ const plugin = {
|
|
|
30
46
|
// would block too many legitimate uses without eslint-disable comments.
|
|
31
47
|
// `prefer-attr-selector` is `warn` — the literal-selector form is still
|
|
32
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.
|
|
33
52
|
// `require-delegate-disposer` is `warn` — the discarded-disposer form is
|
|
34
53
|
// still correct at runtime for page-lifetime roots, and downstream code
|
|
35
54
|
// that's been around since before the rule shipped needs a deprecation
|
|
@@ -43,6 +62,7 @@ const recommendedRules = {
|
|
|
43
62
|
'kerfjs/prefer-module-jsx-augmentation': 'error',
|
|
44
63
|
'kerfjs/prefer-attr-selector': 'warn',
|
|
45
64
|
'kerfjs/ai-assistant-configs': 'warn',
|
|
65
|
+
'kerfjs/no-generated-view-edits': 'error',
|
|
46
66
|
};
|
|
47
67
|
|
|
48
68
|
// Flat config (ESLint v9+) — consumers add this object to their config array.
|
|
@@ -50,6 +70,36 @@ plugin.configs.recommended = {
|
|
|
50
70
|
plugins: { kerfjs: plugin },
|
|
51
71
|
rules: recommendedRules,
|
|
52
72
|
};
|
|
73
|
+
// UI rule severities follow the analyzer's classification of the KUI codes a
|
|
74
|
+
// rule reports (`UI_ANALYSIS_RULES` in `@kerfjs/ui/analyzer`): an `error`
|
|
75
|
+
// code ships as `error`, a `review` code as `warn`. `ui-exceptional-shorthands`
|
|
76
|
+
// (`KUI-L017`) is a review finding — a deliberate off-scale choice to justify,
|
|
77
|
+
// not a defect — so it stays `warn` in strict-ui too; promoting it would
|
|
78
|
+
// contradict the analyzer and make kerf-ui-doctor report the same finding
|
|
79
|
+
// twice. Gate review findings with the doctor's `failOn: 'review'` instead.
|
|
80
|
+
// `@kerfjs/ui`'s eslint-severity-contract test pins this agreement.
|
|
81
|
+
const recommendedUiRules = {
|
|
82
|
+
...recommendedRules,
|
|
83
|
+
'kerfjs/ui-public-boundaries': 'error',
|
|
84
|
+
'kerfjs/ui-component-ownership': 'error',
|
|
85
|
+
'kerfjs/ui-composition': 'error',
|
|
86
|
+
'kerfjs/ui-css-values': 'error',
|
|
87
|
+
'kerfjs/ui-exceptional-shorthands': 'warn',
|
|
88
|
+
'kerfjs/ui-preferences': 'warn',
|
|
89
|
+
'kerfjs/ui-wiring': 'warn',
|
|
90
|
+
};
|
|
91
|
+
plugin.configs['recommended-ui'] = {
|
|
92
|
+
plugins: { kerfjs: plugin },
|
|
93
|
+
rules: recommendedUiRules,
|
|
94
|
+
};
|
|
95
|
+
plugin.configs['strict-ui'] = {
|
|
96
|
+
plugins: { kerfjs: plugin },
|
|
97
|
+
rules: {
|
|
98
|
+
...recommendedUiRules,
|
|
99
|
+
'kerfjs/ui-preferences': 'error',
|
|
100
|
+
'kerfjs/ui-wiring': 'error',
|
|
101
|
+
},
|
|
102
|
+
};
|
|
53
103
|
plugin.configs.all = plugin.configs.recommended;
|
|
54
104
|
|
|
55
105
|
// Legacy `.eslintrc` config — consumers extend `'plugin:kerfjs/legacy-recommended'`.
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// The `class` attributes a `kerfjs/html` tagged template writes, read from its
|
|
2
|
+
// static parts. It follows the runtime's static-part rules
|
|
3
|
+
// (`src/utils/parseTemplate.ts`): markup is text, open tags, and comments; a
|
|
4
|
+
// `${…}` hole is a whole attribute value (`class=${x}` / `class="${x}"`), so
|
|
5
|
+
// a class it supplies is unknown and skipped. A complete static value
|
|
6
|
+
// (`class="kui-pane"`) counts in full; when a hole interrupts a value (which
|
|
7
|
+
// the runtime rejects as a partial value) only the whitespace-delimited names
|
|
8
|
+
// the static text completes count, as for a JSX template literal. Tags whose
|
|
9
|
+
// name is a hole, and holes inside comments, are not markup and are skipped.
|
|
10
|
+
|
|
11
|
+
const HOLE = '\0';
|
|
12
|
+
|
|
13
|
+
const isSpace = (ch) => /\s/.test(ch);
|
|
14
|
+
|
|
15
|
+
// `{ quasi, tag, value }` for every `class` attribute, where `quasi` is the
|
|
16
|
+
// index of the static part the attribute name starts in, `tag` the lowercased
|
|
17
|
+
// element name, and `value` the attribute value with each hole as `\0`.
|
|
18
|
+
export function htmlTemplateClassAttributes(strings) {
|
|
19
|
+
const text = strings.join(HOLE);
|
|
20
|
+
// Offset where each static part starts in `text`.
|
|
21
|
+
const starts = [];
|
|
22
|
+
let offset = 0;
|
|
23
|
+
for (const part of strings) {
|
|
24
|
+
starts.push(offset);
|
|
25
|
+
offset += part.length + 1;
|
|
26
|
+
}
|
|
27
|
+
const quasiAt = (position) => {
|
|
28
|
+
let index = 0;
|
|
29
|
+
while (index + 1 < starts.length && starts[index + 1] <= position)
|
|
30
|
+
index += 1;
|
|
31
|
+
return index;
|
|
32
|
+
};
|
|
33
|
+
const attributes = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
while (i < text.length) {
|
|
36
|
+
if (text[i] !== '<') {
|
|
37
|
+
i += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (text.startsWith('<!--', i)) {
|
|
41
|
+
const end = text.indexOf('-->', i + 4);
|
|
42
|
+
i = end === -1 ? text.length : end + 3;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (!/[a-zA-Z]/.test(text[i + 1] ?? '')) {
|
|
46
|
+
// A closing tag, `<!DOCTYPE`, `<?…`, or a tag-name hole: skip it whole.
|
|
47
|
+
if (/[!/?]/.test(text[i + 1] ?? '')) {
|
|
48
|
+
const end = text.indexOf('>', i + 1);
|
|
49
|
+
i = end === -1 ? text.length : end + 1;
|
|
50
|
+
} else i += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let j = i + 1;
|
|
54
|
+
while (j < text.length && !/[\s/>]/.test(text[j]) && text[j] !== HOLE)
|
|
55
|
+
j += 1;
|
|
56
|
+
const tag = text.slice(i + 1, j).toLowerCase();
|
|
57
|
+
// A hole completing the tag name (`<div${x}>`) makes it unknown.
|
|
58
|
+
const knownTag = text[j] !== HOLE;
|
|
59
|
+
// Attributes until the tag closes.
|
|
60
|
+
while (j < text.length && text[j] !== '>') {
|
|
61
|
+
if (isSpace(text[j]) || text[j] === '/' || text[j] === HOLE) {
|
|
62
|
+
j += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const nameStart = j;
|
|
66
|
+
while (j < text.length && !/[\s"'<>/=]/.test(text[j]) && text[j] !== HOLE)
|
|
67
|
+
j += 1;
|
|
68
|
+
if (j === nameStart) {
|
|
69
|
+
// A stray quote or `=` with no name; step past it.
|
|
70
|
+
j += 1;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const name = text.slice(nameStart, j).toLowerCase();
|
|
74
|
+
// A hole completing the name (`data-${x}=…`) makes it unknown.
|
|
75
|
+
const knownName = text[j] !== HOLE;
|
|
76
|
+
let k = j;
|
|
77
|
+
while (k < text.length && isSpace(text[k])) k += 1;
|
|
78
|
+
if (text[k] !== '=') continue;
|
|
79
|
+
k += 1;
|
|
80
|
+
while (k < text.length && isSpace(text[k])) k += 1;
|
|
81
|
+
let value;
|
|
82
|
+
if (text[k] === '"' || text[k] === "'") {
|
|
83
|
+
const end = text.indexOf(text[k], k + 1);
|
|
84
|
+
value = text.slice(k + 1, end === -1 ? text.length : end);
|
|
85
|
+
j = end === -1 ? text.length : end + 1;
|
|
86
|
+
} else {
|
|
87
|
+
let end = k;
|
|
88
|
+
while (end < text.length && !/[\s>]/.test(text[end])) end += 1;
|
|
89
|
+
value = text.slice(k, end);
|
|
90
|
+
j = end;
|
|
91
|
+
}
|
|
92
|
+
if (knownTag && knownName && name === 'class')
|
|
93
|
+
attributes.push({ quasi: quasiAt(nameStart), tag, value });
|
|
94
|
+
}
|
|
95
|
+
i = j + 1;
|
|
96
|
+
}
|
|
97
|
+
return attributes;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// The class names a value states outright: whitespace-delimited names no hole
|
|
101
|
+
// touches.
|
|
102
|
+
export function staticClassNames(value) {
|
|
103
|
+
return value.split(/\s+/).filter((name) => name && !name.includes(HOLE));
|
|
104
|
+
}
|