astralis-cli 0.5.1 → 0.7.0
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/CHANGELOG.md +30 -1
- package/package.json +2 -2
- package/src/lib/css-value.mjs +13 -2
- package/src/lib/validate-core.mjs +141 -17
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,36 @@ breaking changes; a patch never does.
|
|
|
6
6
|
Versions marked **internal** were set in the repository but never published to
|
|
7
7
|
npm. Their changes reached npm in the next published version.
|
|
8
8
|
|
|
9
|
-
## 0.
|
|
9
|
+
## 0.7.0 (2026-11-22)
|
|
10
|
+
|
|
11
|
+
Published with astralis-ui 0.11.0: `unknown-prop` reads the spec's new `ownProps`, `domProps` and `domAttributes`. With an older spec it stays silent.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **`unknown-state-prop`** (error): `hover`, `focusVisible` or `active` on a component that takes no state props (Card, Button, Image...), where it changes nothing. Box, the layout primitives, Text, Heading and Link take them.
|
|
16
|
+
- **`unknown-prop`** (error): a prop the component's type does not take, with the nearest real one (`Image has no fit prop... did you mean "objectFit"?`). Silent with `as`, a spread, a polymorphic component or an unknown one.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **The paint-prop hint names the props a component really has**, and for a part points to its compound's: `CardFooter is part of Card and has no look of its own: set variant or size on the Card, or put p on a Box inside it`.
|
|
21
|
+
|
|
22
|
+
## 0.6.0 (2026-11-21)
|
|
23
|
+
|
|
24
|
+
Publish with astralis-ui 0.10.0, whose system spec is version 4.
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- **New errors**: `invalid-prop-type` (a number written as a string, a bad responsive map) and `unsupported-css-keyword` (a CSS-wide keyword a value prop cannot carry).
|
|
29
|
+
- **State props on Text, Heading and Link are checked** against the props they take.
|
|
30
|
+
- **Scale and angle values are judged**, including inside `hover`; a bare `rotate` number gets a `deg` suggestion.
|
|
31
|
+
- **Grid template values** are accepted as track lists, per breakpoint.
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
- **Names in the spec's `domStyleProps` are never reported as stray style props** (Textarea `rows`, Table cell `colSpan`).
|
|
36
|
+
- **`unknown-style-prop` on a component that takes no style props says so** instead of naming an empty group list.
|
|
37
|
+
|
|
38
|
+
## 0.5.1 (2026-11-20)
|
|
10
39
|
|
|
11
40
|
Uses astralis-ui 0.9.0, whose specification adds the animation props, so
|
|
12
41
|
`astralis validate` checks `animation`, `reveal`, `animationDuration` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astralis-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Setup and tooling CLI for Astralis UI — scaffold or wire up a project, add blocks, generate a static brand theme, validate code against the design system, connect the MCP server.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@babel/parser": "^8.0.4",
|
|
57
|
-
"astralis-ui": "^0.
|
|
57
|
+
"astralis-ui": "^0.11.0"
|
|
58
58
|
},
|
|
59
59
|
"scripts": {
|
|
60
60
|
"test": "node --test \"test/*.test.mjs\"",
|
package/src/lib/css-value.mjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
--------------------------------------------------------------------------
|
|
4
4
|
Classifies an ARBITRARY channel value (a string that is not a token)
|
|
5
5
|
against the value type its channel carries — length, color, shadow,
|
|
6
|
-
number, integer (spec propGroups[*].valueType).
|
|
6
|
+
number, integer, scale, angle (spec propGroups[*].valueType). A `template` (Grid's
|
|
7
|
+
track and area lists) is open CSS with no grammar here: never judged.
|
|
7
8
|
|
|
8
9
|
The design rule: NEVER reject valid CSS. A false "invalid" kills trust in
|
|
9
10
|
the whole validator, so the grammar only condemns what is definitely
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
as the runtime) | no-claim.
|
|
18
19
|
========================================================================== */
|
|
19
20
|
|
|
20
|
-
const CSS_WIDE = new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
|
|
21
|
+
export const CSS_WIDE = new Set(["inherit", "initial", "unset", "revert", "revert-layer"]);
|
|
21
22
|
|
|
22
23
|
const LENGTH_KEYWORDS = new Set([
|
|
23
24
|
"auto", "none", "max-content", "min-content", "fit-content", "stretch",
|
|
@@ -40,8 +41,12 @@ const FUNCTIONS = {
|
|
|
40
41
|
shadow: new Set(["var"]),
|
|
41
42
|
number: new Set(["var", "calc", "min", "max", "clamp"]),
|
|
42
43
|
integer: new Set(["var", "calc"]),
|
|
44
|
+
scale: new Set(["var", "calc", "min", "max", "clamp"]),
|
|
45
|
+
angle: new Set(["var", "calc", "min", "max", "clamp"]),
|
|
43
46
|
};
|
|
44
47
|
|
|
48
|
+
const ANGLE_UNITS = new Set(["deg", "rad", "grad", "turn"]);
|
|
49
|
+
|
|
45
50
|
/** The CSS named colors, plus transparent/currentColor. */
|
|
46
51
|
const NAMED_COLORS = new Set([
|
|
47
52
|
"aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige", "bisque",
|
|
@@ -83,6 +88,7 @@ const invalid = (reason) => ({ verdict: "invalid", reason });
|
|
|
83
88
|
*/
|
|
84
89
|
export function classifyChannelValue(raw, type) {
|
|
85
90
|
const value = raw.trim();
|
|
91
|
+
if (type === "template") return { verdict: "no-claim" };
|
|
86
92
|
|
|
87
93
|
// Function calls first — their arguments may contain spaces and commas.
|
|
88
94
|
const fn = value.match(/^([a-zA-Z-]+)\((.*)\)$/s);
|
|
@@ -110,7 +116,11 @@ export function classifyChannelValue(raw, type) {
|
|
|
110
116
|
case "integer":
|
|
111
117
|
return unit === "" && /^[+-]?\d+$/.test(value) ? ok : invalid("takes a whole number");
|
|
112
118
|
case "number":
|
|
119
|
+
case "scale":
|
|
113
120
|
return unit === "" || unit === "%" ? ok : invalid("takes a plain number or percentage");
|
|
121
|
+
case "angle":
|
|
122
|
+
if (unit === "") return { verdict: "bare-number" };
|
|
123
|
+
return ANGLE_UNITS.has(unit) ? ok : invalid(`"${unit}" is not a CSS angle unit`);
|
|
114
124
|
case "length":
|
|
115
125
|
if (unit === "") return { verdict: "bare-number" };
|
|
116
126
|
return unit === "%" || LENGTH_UNITS.has(unit)
|
|
@@ -127,6 +137,7 @@ export function classifyChannelValue(raw, type) {
|
|
|
127
137
|
if (type === "color") return NAMED_COLORS.has(word) ? ok : invalid("not a CSS color name");
|
|
128
138
|
if (type === "length") return LENGTH_KEYWORDS.has(word) ? ok : invalid("not a CSS sizing keyword");
|
|
129
139
|
if (type === "shadow") return word === "none" ? ok : invalid("not a shadow");
|
|
140
|
+
if (type === "scale" || type === "angle") return word === "none" ? ok : invalid(`takes a ${type === "angle" ? "CSS angle" : "number or percentage"}`);
|
|
130
141
|
return invalid(`takes a ${type === "integer" ? "whole number" : "number"}`);
|
|
131
142
|
}
|
|
132
143
|
|
|
@@ -11,14 +11,22 @@
|
|
|
11
11
|
- a component or compound part that doesn't exist (unknown-import,
|
|
12
12
|
unknown-part)
|
|
13
13
|
- a keyword prop value outside its closed set (invalid-keyword-value)
|
|
14
|
+
- an own prop given the wrong kind of value: a string (invalid-prop-type)
|
|
15
|
+
where it takes a number, a map where it takes one value
|
|
14
16
|
- a breakpoint or state key that isn't one (invalid-breakpoint-key,
|
|
15
17
|
invalid-state-prop)
|
|
16
18
|
- an `astralis:*` class missing from the compiled CSS (unknown-class)
|
|
17
19
|
- a var(--astralis-*) reference no stylesheet declares (unknown-css-variable)
|
|
18
20
|
- a prop its component deliberately types away (excluded-prop)
|
|
19
21
|
- a bare number where CSS needs a unit (bare-number-value)
|
|
22
|
+
- a CSS-wide keyword a channel prop cannot carry: w= (unsupported-css-keyword)
|
|
23
|
+
"inherit" would copy the nearest w above, not the parent's width
|
|
20
24
|
- a style prop the component does not take, which reaches the HTML as a
|
|
21
25
|
stray attribute and changes nothing (unknown-style-prop)
|
|
26
|
+
- hover/focusVisible/active on a component that takes (unknown-state-prop)
|
|
27
|
+
no state props: only the box and text groups resolve them
|
|
28
|
+
- a prop the component's type does not take at all, when the spec lists
|
|
29
|
+
the type's whole prop set (ownProps) (unknown-prop)
|
|
22
30
|
- a component left empty that its type requires children for (missing-children):
|
|
23
31
|
tsc catches it too, but agents and copied snippets produce code no one type-checks
|
|
24
32
|
|
|
@@ -33,7 +41,7 @@
|
|
|
33
41
|
========================================================================== */
|
|
34
42
|
|
|
35
43
|
import { parse } from "@babel/parser";
|
|
36
|
-
import { classifyChannelValue } from "./css-value.mjs";
|
|
44
|
+
import { classifyChannelValue, CSS_WIDE } from "./css-value.mjs";
|
|
37
45
|
import { ARIA_ATTRS, ROLES } from "./aria.mjs";
|
|
38
46
|
import { suggest } from "./suggest.mjs";
|
|
39
47
|
import { checkRequiredChildren } from "./children-rule.mjs";
|
|
@@ -57,6 +65,12 @@ const DOCTRINE_PAINT_PROPS = new Set([
|
|
|
57
65
|
so they are never reported as stray. */
|
|
58
66
|
const HTML_ATTRIBUTE_NAMES = new Set(["width", "height", "size", "color", "wrap", "align", "border"]);
|
|
59
67
|
|
|
68
|
+
/* The recipe props a paint-prop hint may point to, when the component has them. */
|
|
69
|
+
const LOOK_PROPS = ["variant", "size", "colorScheme"];
|
|
70
|
+
|
|
71
|
+
/* Props React itself takes on every component, whatever its type declares. */
|
|
72
|
+
const REACT_PROPS = new Set(["key", "ref", "children"]);
|
|
73
|
+
|
|
60
74
|
/* Packages whose components are icons, for the icon-only Button rule. */
|
|
61
75
|
const ICON_PACKAGES = /^(lucide-react|react-icons(\/.*)?|@heroicons\/react(\/.*)?|@radix-ui\/react-icons|@tabler\/icons-react|@phosphor-icons\/react)$/;
|
|
62
76
|
|
|
@@ -94,6 +108,9 @@ export function prepareSpec(spec) {
|
|
|
94
108
|
// them and older code must keep validating.
|
|
95
109
|
bpKeys: new Set(["base", ...Object.keys(spec.breakpoints), ...Object.keys(spec.containerBreakpoints ?? {})]),
|
|
96
110
|
stateProps: new Set(Object.keys(spec.states)),
|
|
111
|
+
// React's DOM and SVG attributes any component's type inherits (spec builds
|
|
112
|
+
// that list each component's ownProps). Null when the spec cannot say.
|
|
113
|
+
domAttributeSet: spec.domAttributes ? new Set(spec.domAttributes) : null,
|
|
97
114
|
// Every exported value and type (spec 3+). Null for older specs.
|
|
98
115
|
exportSet: spec.exports ? new Set(spec.exports) : null,
|
|
99
116
|
};
|
|
@@ -220,6 +237,15 @@ function checkScalar(ctx, comp, prop, propSpec, value, node) {
|
|
|
220
237
|
ctx.error("empty-channel-value", node, `${comp}: ${prop}="" resolves to nothing`);
|
|
221
238
|
return;
|
|
222
239
|
}
|
|
240
|
+
// A channel value rides a CSS variable, where a CSS-wide keyword applies to
|
|
241
|
+
// the variable: the props list the ones that still work (specs from v4).
|
|
242
|
+
const keyword = value.trim().toLowerCase();
|
|
243
|
+
if (CSS_WIDE.has(keyword) && propSpec.cssKeywords && !propSpec.cssKeywords.includes(keyword)) {
|
|
244
|
+
ctx.error("unsupported-css-keyword", node,
|
|
245
|
+
`${comp}: ${prop}="${value}" cannot work: the value rides a CSS variable, so the keyword would apply to the variable ` +
|
|
246
|
+
`and copy the nearest ${prop.replace(/^.*\./, "")} set above, not the property. It takes ${propSpec.cssKeywords.join(", ")}`);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
223
249
|
for (const m of value.matchAll(CSS_VAR_REF)) {
|
|
224
250
|
if (!ctx.knownVar(m[1])) {
|
|
225
251
|
ctx.error("unknown-css-variable", node, `${comp}: ${prop} references var(${m[1]}), which no token stylesheet declares`);
|
|
@@ -233,7 +259,7 @@ function checkScalar(ctx, comp, prop, propSpec, value, node) {
|
|
|
233
259
|
(near ? ` (did you mean "${near}"?)` : ""));
|
|
234
260
|
} else if (verdict.verdict === "bare-number" || (BARE_NUMBER.test(value) && !propSpec.unitless)) {
|
|
235
261
|
ctx.warn("bare-number-value", node,
|
|
236
|
-
`${comp}: ${prop}="${value}" is not a token, and a bare number is not valid CSS here — did you mean a token, or "${value}px"?`);
|
|
262
|
+
`${comp}: ${prop}="${value}" is not a token, and a bare number is not valid CSS here — did you mean a token, or "${value}${propSpec.valueType === "angle" ? "deg" : "px"}"?`);
|
|
237
263
|
} else if (ctx.opts.strictTokens && propSpec.valueType === "color") {
|
|
238
264
|
ctx.warn("off-token-color", node,
|
|
239
265
|
`${comp}: ${prop}="${value}" is a raw color — it won't follow the theme or dark mode; prefer a token`);
|
|
@@ -267,7 +293,8 @@ function checkPropValue(ctx, comp, prop, propSpec, valueNode, attr) {
|
|
|
267
293
|
}
|
|
268
294
|
}
|
|
269
295
|
|
|
270
|
-
|
|
296
|
+
/** `takes`, when given, narrows the payload to the component's own base props. */
|
|
297
|
+
function checkStateValue(ctx, comp, state, valueNode, takes) {
|
|
271
298
|
if (valueNode?.type !== "JSXExpressionContainer" || valueNode.expression.type !== "ObjectExpression") return;
|
|
272
299
|
for (const p of valueNode.expression.properties) {
|
|
273
300
|
if (p.type !== "ObjectProperty" || p.computed) continue;
|
|
@@ -278,6 +305,11 @@ function checkStateValue(ctx, comp, state, valueNode) {
|
|
|
278
305
|
`${comp}: "${key}" cannot appear in ${state} — states carry channel props only (spacing, sizing, gap, paint, …)`);
|
|
279
306
|
continue;
|
|
280
307
|
}
|
|
308
|
+
if (takes && !takes[key]) {
|
|
309
|
+
ctx.error("invalid-state-prop", p,
|
|
310
|
+
`${comp}: "${key}" cannot appear in ${state} — ${comp} has no ${key} prop, and a state carries only the props it takes`);
|
|
311
|
+
continue;
|
|
312
|
+
}
|
|
281
313
|
const v = literalOf(p.value);
|
|
282
314
|
if (v !== null) checkScalar(ctx, comp, `${state}.${key}`, payloadSpec, v, p.value);
|
|
283
315
|
}
|
|
@@ -356,7 +388,76 @@ function checkTabIndex(ctx, attr) {
|
|
|
356
388
|
|
|
357
389
|
/* ---- rule: astralis component props --------------------------------------------- */
|
|
358
390
|
|
|
359
|
-
|
|
391
|
+
const LITERAL_KINDS = { StringLiteral: "string", NumericLiteral: "number", BooleanLiteral: "boolean" };
|
|
392
|
+
|
|
393
|
+
/** One literal value of an own prop: in its vocabulary, or of its scalar kind.
|
|
394
|
+
* `at` is where a finding is reported: the attribute, or the map entry. */
|
|
395
|
+
function checkOwnLeaf(ctx, name, comp, prop, node, at = node) {
|
|
396
|
+
const value = literalOf(node);
|
|
397
|
+
if (value === null) return;
|
|
398
|
+
const values = comp.props?.[prop];
|
|
399
|
+
const kind = comp.scalarProps?.[prop];
|
|
400
|
+
const given = LITERAL_KINDS[node.type] ?? "string";
|
|
401
|
+
if (kind === given || values?.includes(value)) return;
|
|
402
|
+
if (values && (!kind || given === "string")) {
|
|
403
|
+
ctx.error("invalid-recipe-value", at, `${name}: "${value}" is not a ${prop} value` + closedSetHint(value, values));
|
|
404
|
+
} else {
|
|
405
|
+
const shown = given === "string" ? `the string "${value}"` : `${given === "number" ? "a number" : "a boolean"}`;
|
|
406
|
+
ctx.error("invalid-prop-type", at, `${name}: ${prop} takes a ${kind}, not ${shown}` +
|
|
407
|
+
(kind === "number" && given === "string" && /^-?\d+(\.\d+)?$/.test(value) ? ` — write ${prop}={${value}}` : ""));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function checkOwnValue(ctx, name, comp, prop, attr) {
|
|
412
|
+
const valueNode = attr.value;
|
|
413
|
+
if (valueNode === null) return; // a bare attribute is {true}; TypeScript's to judge
|
|
414
|
+
const node = valueNode.type === "JSXExpressionContainer" ? valueNode.expression : valueNode;
|
|
415
|
+
if (node.type !== "ObjectExpression") return checkOwnLeaf(ctx, name, comp, prop, node, attr);
|
|
416
|
+
// Specs from version 4 list the own props that take a responsive map.
|
|
417
|
+
if (!comp.responsiveProps?.includes(prop)) {
|
|
418
|
+
if ((ctx.spec.specVersion ?? 0) >= 4) {
|
|
419
|
+
ctx.error("invalid-prop-type", node, `${name}: ${prop} takes no responsive map — give it one value`);
|
|
420
|
+
}
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
for (const p of node.properties) {
|
|
424
|
+
if (p.type !== "ObjectProperty" || p.computed) continue;
|
|
425
|
+
const key = keyName(p);
|
|
426
|
+
if (!ctx.bpKeys.has(key)) {
|
|
427
|
+
ctx.error("invalid-breakpoint-key", p, `${name}: "${key}" is not a breakpoint — responsive maps take ${[...ctx.bpKeys].join("/")}`);
|
|
428
|
+
continue;
|
|
429
|
+
}
|
|
430
|
+
checkOwnLeaf(ctx, name, comp, prop, p.value);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** The hint for a paint prop on a component that owns its look: its own
|
|
435
|
+
* variant/size/colorScheme, or for a part, the ones on the compound it belongs to. */
|
|
436
|
+
function lookHint(ctx, name, comp, prop) {
|
|
437
|
+
const lookOf = (entry) => LOOK_PROPS.filter((p) => entry?.props?.[p]);
|
|
438
|
+
const or = (list) => (list.length > 1 ? `${list.slice(0, -1).join(", ")} or ${list.at(-1)}` : list[0]);
|
|
439
|
+
if (comp.partOf) {
|
|
440
|
+
const owner = comp.partOf;
|
|
441
|
+
const vocab = lookOf(ctx.spec.components[owner]);
|
|
442
|
+
return `${name} is part of ${owner} and has no look of its own: ` +
|
|
443
|
+
(vocab.length ? `set ${or(vocab)} on the ${owner}, or ` : "") + `put ${prop} on a Box inside it`;
|
|
444
|
+
}
|
|
445
|
+
const vocab = lookOf(comp);
|
|
446
|
+
return vocab.length
|
|
447
|
+
? `${name} owns how it looks; reach for ${or(vocab)}`
|
|
448
|
+
: `${name} owns how it looks; put ${prop} on a Box around it`;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/** Whether the component's type takes `prop` at all. Null when the spec cannot
|
|
452
|
+
* say: it lists ownProps only for types it read whole (not polymorphic ones). */
|
|
453
|
+
function takesProp(ctx, comp, allowed, prop) {
|
|
454
|
+
if (!comp.ownProps || (comp.domProps && !ctx.domAttributeSet)) return null;
|
|
455
|
+
if (allowed[prop] || comp.ownProps.includes(prop) || REACT_PROPS.has(prop) || /^data-/.test(prop)) return true;
|
|
456
|
+
if (comp.props?.[prop] || comp.scalarProps?.[prop] || comp.overrides?.includes(prop)) return true;
|
|
457
|
+
return Boolean(comp.domProps && (/^on[A-Z]/.test(prop) || ctx.domAttributeSet.has(prop)));
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function checkComponentProp(ctx, identity, comp, allowed, attr, prop, open) {
|
|
360
461
|
const name = identity.specName;
|
|
361
462
|
if (comp.exclude?.includes(prop)) {
|
|
362
463
|
const short = allowed[prop]?.short;
|
|
@@ -373,8 +474,18 @@ function checkComponentProp(ctx, identity, comp, allowed, attr, prop) {
|
|
|
373
474
|
const overridden = comp.overrides?.includes(prop);
|
|
374
475
|
if (overridden && !comp.props?.[prop]) return;
|
|
375
476
|
if (!overridden && ctx.stateProps.has(prop)) {
|
|
376
|
-
//
|
|
477
|
+
// Box-composing primitives resolve every stateable prop; Text, Heading and
|
|
478
|
+
// Link only those they take as base props. Elsewhere no claim.
|
|
377
479
|
if (comp.groups.includes("box")) checkStateValue(ctx, name, prop, attr.value);
|
|
480
|
+
else if (comp.groups.includes("text")) checkStateValue(ctx, name, prop, attr.value, allowed);
|
|
481
|
+
// Only box- and text-group components resolve state props. Decided only
|
|
482
|
+
// when the spec read the type (ownStyleProps), and never against a state
|
|
483
|
+
// name the component declares itself.
|
|
484
|
+
else if (comp.ownStyleProps && !comp.props?.[prop] && !comp.scalarProps?.[prop] && !comp.ownProps?.includes(prop)) {
|
|
485
|
+
ctx.error("unknown-state-prop", attr,
|
|
486
|
+
`${name} does not take ${prop}: state props work on Box, the layout primitives, Text, Heading and Link, ` +
|
|
487
|
+
`so here it changes nothing (put ${prop} on a Box around ${name})`);
|
|
488
|
+
}
|
|
378
489
|
return;
|
|
379
490
|
}
|
|
380
491
|
if (!overridden && allowed[prop]) {
|
|
@@ -382,27 +493,39 @@ function checkComponentProp(ctx, identity, comp, allowed, attr, prop) {
|
|
|
382
493
|
return;
|
|
383
494
|
}
|
|
384
495
|
// Recipe props (Button variant, Alert status, …): closed vocabularies read
|
|
385
|
-
// out of the shipped d.ts
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
if (value !== null && !values.includes(value)) {
|
|
390
|
-
ctx.error("invalid-recipe-value", attr, `${name}: "${value}" is not a ${prop} value` + closedSetHint(value, values));
|
|
391
|
-
}
|
|
496
|
+
// out of the shipped d.ts, and the library's own scalar props (Carousel
|
|
497
|
+
// slidesPerView takes a number). Literal values only; dynamic ones are TypeScript's.
|
|
498
|
+
if (comp.props?.[prop] || comp.scalarProps?.[prop]) {
|
|
499
|
+
checkOwnValue(ctx, name, comp, prop, attr);
|
|
392
500
|
return;
|
|
393
501
|
}
|
|
394
502
|
// A style prop this component's type does not take at all: it is passed to
|
|
395
503
|
// the DOM, where it is a meaningless attribute. Only decided when the spec
|
|
396
504
|
// lists the component's own style-prop names (spec builds from Oct 2026).
|
|
397
|
-
|
|
505
|
+
// `domStyleProps` are the element's own attributes under a style prop's
|
|
506
|
+
// name (Textarea rows, Table.Cell colSpan): real, so never stray.
|
|
507
|
+
if (comp.ownStyleProps && !comp.ownStyleProps.includes(prop) && !comp.domStyleProps?.includes(prop) &&
|
|
508
|
+
ctx.stylePropNames.has(prop) && !HTML_ATTRIBUTE_NAMES.has(prop)) {
|
|
398
509
|
const recipe = comp.groups.length === 1 && comp.groups[0] === "placement" && DOCTRINE_PAINT_PROPS.has(prop);
|
|
399
510
|
ctx.error("unknown-style-prop", attr,
|
|
400
511
|
`${name} does not take ${prop}: it reaches the HTML as a stray attribute and changes nothing` +
|
|
401
512
|
(recipe
|
|
402
|
-
? ` (${name
|
|
403
|
-
: ` (${name} takes ${comp.groups.join(", ")} props; put ${prop} on a Box around it)`));
|
|
513
|
+
? ` (${lookHint(ctx, name, comp, prop)})`
|
|
514
|
+
: ` (${name} takes ${comp.groups.length ? `${comp.groups.join(", ")} props` : "no style props"}; put ${prop} on a Box around it)`));
|
|
515
|
+
return;
|
|
404
516
|
}
|
|
405
|
-
//
|
|
517
|
+
// Style-prop names are the rule above's; `as` or a spread may hand the
|
|
518
|
+
// element another component's props, so neither is judged.
|
|
519
|
+
if (open || ctx.stylePropNames.has(prop) || takesProp(ctx, comp, allowed, prop) !== false) return;
|
|
520
|
+
const candidates = [...comp.ownProps, ...Object.keys(allowed)].filter((p) => !/^(aria|data)-|^on[A-Z]/.test(p) || /^on[A-Z]/.test(prop));
|
|
521
|
+
// A near spelling, else the one prop that ends or starts with it (fit, objectFit).
|
|
522
|
+
const lower = prop.toLowerCase();
|
|
523
|
+
const affixed = candidates.filter((p) => lower.length >= 3 && (p.toLowerCase().endsWith(lower) || p.toLowerCase().startsWith(lower)));
|
|
524
|
+
const near = (affixed.length === 1 ? affixed[0] : null) ?? suggest(prop, candidates);
|
|
525
|
+
ctx.error("unknown-prop", attr,
|
|
526
|
+
`${name} has no ${prop} prop: ` +
|
|
527
|
+
(comp.domProps ? "it reaches the HTML as a stray attribute and changes nothing" : "it changes nothing") +
|
|
528
|
+
(near ? ` (did you mean "${near}"?)` : ""));
|
|
406
529
|
}
|
|
407
530
|
|
|
408
531
|
/* ---- one element: identity, then every attribute ----------------------------- */
|
|
@@ -460,6 +583,7 @@ function analyzeOpening(ctx, node) {
|
|
|
460
583
|
if (comp) for (const g of comp.groups) Object.assign(allowed, ctx.spec.propGroups[g]);
|
|
461
584
|
|
|
462
585
|
let hasSpread = false;
|
|
586
|
+
const open = node.attributes.some((a) => a.type === "JSXSpreadAttribute") || Boolean(findAttribute(node, "as"));
|
|
463
587
|
let hasAlt = false;
|
|
464
588
|
let hasAriaCover = false; // aria-label / aria-labelledby / aria-hidden
|
|
465
589
|
|
|
@@ -477,7 +601,7 @@ function analyzeOpening(ctx, node) {
|
|
|
477
601
|
} else if (prop === "role") checkRole(ctx, attr);
|
|
478
602
|
else if (prop === "tabIndex") checkTabIndex(ctx, attr);
|
|
479
603
|
else if (prop === "alt") hasAlt = true;
|
|
480
|
-
else if (comp) checkComponentProp(ctx, identity, comp, allowed, attr, prop);
|
|
604
|
+
else if (comp) checkComponentProp(ctx, identity, comp, allowed, attr, prop, open);
|
|
481
605
|
}
|
|
482
606
|
|
|
483
607
|
if (identity.specName === "Flex") {
|