eslint-plugin-kerfjs 5.0.0-beta.105 → 5.0.0-beta.107

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.
@@ -1,6 +1,6 @@
1
1
  # `ui-composition`
2
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. 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.
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. A zone participates only when it declares an explicit `jsx.prop` binding, including `children`; the rule never guesses that a zone id is a JSX prop. Toolbar, Pane, TabBar, TabBarItem, feedback, search, and layout validation is therefore catalog-driven rather than duplicated in rule-local component cases.
4
4
 
5
5
  The parent check is intentionally conservative about the child: it runs only for a child that resolves to a cataloged entry (or a declared wrapper's roots) whose parents are `listed`. Its direct JSX parent may be any element the rule can see: a cataloged component, a declared wrapper (which counts as each of its roots), an intrinsic element such as `<div>`, or an unresolved component, and any parent that is not a listed parent reports `KUI-L201`. Bound zone checks understand aliases, namespace imports, fragments, arrays, and conditional/logical branches, but expressions whose content cannot be resolved statically remain runtime and accessibility work. Accepted concepts that do not identify a catalog entry remain machine-readable guidance while the rule enforces their statically provable cardinality only. No autofix is offered because wrapping or moving UI changes structure and behavior.
6
6
  Toolbar zones accept `KerfUiContent`, so the zone rule allows direct JSX
@@ -15,6 +15,35 @@ such as `const actions = <div />; <TabBar trailing={actions} />`. Review those
15
15
  bindings against the zone's catalog contract; an unknown expression produces
16
16
  no zone-child diagnostic.
17
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
+
18
47
  ## Application and third-party wrappers
19
48
 
20
49
  Beyond `@kerfjs/ui`'s own catalog, the rule loads every composition catalog the
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.105' },
18
+ meta: { name: 'eslint-plugin-kerfjs', version: '5.0.0-beta.107' },
19
19
  rules: {
20
20
  'no-inline-jsx-event-handlers': noInlineJsxEventHandlers,
21
21
  'no-raw-with-dynamic-arg': noRawWithDynamicArg,
@@ -12,6 +12,7 @@ import {
12
12
  const PARENT_CODE = 'KUI-L201';
13
13
  const ZONE_CODE = 'KUI-L202';
14
14
  const CARDINALITY_CODE = 'KUI-L203';
15
+ const INSET_CODE = 'KUI-L204';
15
16
 
16
17
  const emptyShape = () => ({ min: 0, max: 0, items: [] });
17
18
 
@@ -60,7 +61,13 @@ function zoneShape(node, registry, contract) {
60
61
  return {
61
62
  min: 1,
62
63
  max: 1,
63
- items: [{ key, label: key ?? jsxLabel(node.openingElement.name) }],
64
+ items: [
65
+ {
66
+ key,
67
+ label: key ?? jsxLabel(node.openingElement.name),
68
+ element: node.openingElement,
69
+ },
70
+ ],
64
71
  };
65
72
  }
66
73
  if (node.type === 'JSXFragment')
@@ -117,6 +124,56 @@ function directParentKey(node, registry, contract) {
117
124
  : undefined;
118
125
  }
119
126
 
127
+ // A prop's statically written value: `{ known: true, value }`, where a bare
128
+ // boolean prop is `true` and an absent one is `undefined`, or
129
+ // `{ known: false }` when a spread or an expression could supply it.
130
+ function staticProp(openingElement, prop) {
131
+ const attribute = openingElement.attributes.find(
132
+ (candidate) =>
133
+ candidate.type === 'JSXAttribute' && candidate.name.name === prop,
134
+ );
135
+ if (!attribute)
136
+ return openingElement.attributes.some(
137
+ (candidate) => candidate.type === 'JSXSpreadAttribute',
138
+ )
139
+ ? { known: false }
140
+ : { known: true, value: undefined };
141
+ if (attribute.value === null) return { known: true, value: true };
142
+ const value =
143
+ attribute.value.type === 'JSXExpressionContainer'
144
+ ? attribute.value.expression
145
+ : attribute.value;
146
+ if (value.type === 'Literal') return { known: true, value: value.value };
147
+ if (value.type === 'TemplateLiteral' && value.expressions.length === 0)
148
+ return { known: true, value: value.quasis[0].value.cooked };
149
+ return { known: false };
150
+ }
151
+
152
+ const conditionLabel = ({ prop, equals }) =>
153
+ equals === true
154
+ ? `\`${prop}\``
155
+ : typeof equals === 'string'
156
+ ? `\`${prop}="${equals}"\``
157
+ : `\`${prop}={${equals}}\``;
158
+
159
+ // An element owns the shared content-item inset when its geometry owns its
160
+ // margin, border, and padding, unless one of its inset-free conditions holds.
161
+ // A condition the rule cannot read statically counts as holding.
162
+ function bringsInset(entry, element) {
163
+ const geometry = entry?.layout?.geometry;
164
+ if (
165
+ !geometry ||
166
+ !['margin', 'border', 'padding'].every(
167
+ (dimension) => geometry[dimension] === 'self',
168
+ )
169
+ )
170
+ return false;
171
+ return !(entry.insetFreeWhen ?? []).some((condition) => {
172
+ const prop = staticProp(element, condition.prop);
173
+ return !prop.known || prop.value === condition.equals;
174
+ });
175
+ }
176
+
120
177
  // The cataloged roots an element stands for: a declared wrapper's `rendersAs`,
121
178
  // otherwise the element's own entry.
122
179
  const rootsOf = (key, contract) =>
@@ -160,6 +217,8 @@ export default {
160
217
  zone: 'KUI-L202: `{{component}}` zone `{{zone}}` does not accept {{child}}; catalog accepts: {{accepts}}.',
161
218
  cardinality:
162
219
  'KUI-L203: `{{component}}` zone `{{zone}}` requires {{cardinality}} direct children; statically found {{count}}.',
220
+ inset:
221
+ 'KUI-L204: `{{child}}` brings its own content-item inset (1px border + 8px padding) into `{{component}}` with {{condition}}, which expects inset-free content and double-insets it; {{fix}}.',
163
222
  },
164
223
  },
165
224
  create(context) {
@@ -227,6 +286,34 @@ export default {
227
286
  });
228
287
  }
229
288
  }
289
+ const insetCondition = exportContract
290
+ ? undefined
291
+ : entry.insetFreeChildren?.find((condition) => {
292
+ const prop = staticProp(node, condition.prop);
293
+ return prop.known && prop.value === condition.equals;
294
+ });
295
+ if (insetCondition && !isExcepted(contract, INSET_CODE, filename))
296
+ for (const child of combine(
297
+ (node.parent?.children ?? []).map((child) =>
298
+ zoneShape(child, registry, contract),
299
+ ),
300
+ ).items) {
301
+ const childEntry = child.element && contract.entries.get(child.key);
302
+ if (!childEntry || !bringsInset(childEntry, child.element))
303
+ continue;
304
+ context.report({
305
+ node: child.element.name,
306
+ messageId: 'inset',
307
+ data: {
308
+ child: child.key,
309
+ component: key,
310
+ condition: conditionLabel(insetCondition),
311
+ fix: childEntry.insetFreeWhen?.length
312
+ ? `set ${childEntry.insetFreeWhen.map(conditionLabel).join(' or ')}`
313
+ : 'use an inset-free child such as `Text flush`, or inline content',
314
+ },
315
+ });
316
+ }
230
317
  for (const zone of exportContract ? [] : (entry.zones ?? [])) {
231
318
  const bound = boundZone(node, zone, registry, contract);
232
319
  if (!bound) continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-kerfjs",
3
- "version": "5.0.0-beta.105",
3
+ "version": "5.0.0-beta.107",
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",