astralis-cli 0.5.1 → 0.6.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 +17 -1
- package/package.json +2 -2
- package/src/lib/css-value.mjs +13 -2
- package/src/lib/validate-core.mjs +77 -13
package/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,23 @@ 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.6.0 (2026-11-21)
|
|
10
|
+
|
|
11
|
+
Publish with astralis-ui 0.10.0, whose system spec is version 4.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- **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).
|
|
16
|
+
- **State props on Text, Heading and Link are checked** against the props they take.
|
|
17
|
+
- **Scale and angle values are judged**, including inside `hover`; a bare `rotate` number gets a `deg` suggestion.
|
|
18
|
+
- **Grid template values** are accepted as track lists, per breakpoint.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **Names in the spec's `domStyleProps` are never reported as stray style props** (Textarea `rows`, Table cell `colSpan`).
|
|
23
|
+
- **`unknown-style-prop` on a component that takes no style props says so** instead of naming an empty group list.
|
|
24
|
+
|
|
25
|
+
## 0.5.1 (2026-11-20)
|
|
10
26
|
|
|
11
27
|
Uses astralis-ui 0.9.0, whose specification adds the animation props, so
|
|
12
28
|
`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.6.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.10.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,12 +11,16 @@
|
|
|
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)
|
|
22
26
|
- a component left empty that its type requires children for (missing-children):
|
|
@@ -33,7 +37,7 @@
|
|
|
33
37
|
========================================================================== */
|
|
34
38
|
|
|
35
39
|
import { parse } from "@babel/parser";
|
|
36
|
-
import { classifyChannelValue } from "./css-value.mjs";
|
|
40
|
+
import { classifyChannelValue, CSS_WIDE } from "./css-value.mjs";
|
|
37
41
|
import { ARIA_ATTRS, ROLES } from "./aria.mjs";
|
|
38
42
|
import { suggest } from "./suggest.mjs";
|
|
39
43
|
import { checkRequiredChildren } from "./children-rule.mjs";
|
|
@@ -220,6 +224,15 @@ function checkScalar(ctx, comp, prop, propSpec, value, node) {
|
|
|
220
224
|
ctx.error("empty-channel-value", node, `${comp}: ${prop}="" resolves to nothing`);
|
|
221
225
|
return;
|
|
222
226
|
}
|
|
227
|
+
// A channel value rides a CSS variable, where a CSS-wide keyword applies to
|
|
228
|
+
// the variable: the props list the ones that still work (specs from v4).
|
|
229
|
+
const keyword = value.trim().toLowerCase();
|
|
230
|
+
if (CSS_WIDE.has(keyword) && propSpec.cssKeywords && !propSpec.cssKeywords.includes(keyword)) {
|
|
231
|
+
ctx.error("unsupported-css-keyword", node,
|
|
232
|
+
`${comp}: ${prop}="${value}" cannot work: the value rides a CSS variable, so the keyword would apply to the variable ` +
|
|
233
|
+
`and copy the nearest ${prop.replace(/^.*\./, "")} set above, not the property. It takes ${propSpec.cssKeywords.join(", ")}`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
223
236
|
for (const m of value.matchAll(CSS_VAR_REF)) {
|
|
224
237
|
if (!ctx.knownVar(m[1])) {
|
|
225
238
|
ctx.error("unknown-css-variable", node, `${comp}: ${prop} references var(${m[1]}), which no token stylesheet declares`);
|
|
@@ -233,7 +246,7 @@ function checkScalar(ctx, comp, prop, propSpec, value, node) {
|
|
|
233
246
|
(near ? ` (did you mean "${near}"?)` : ""));
|
|
234
247
|
} else if (verdict.verdict === "bare-number" || (BARE_NUMBER.test(value) && !propSpec.unitless)) {
|
|
235
248
|
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"?`);
|
|
249
|
+
`${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
250
|
} else if (ctx.opts.strictTokens && propSpec.valueType === "color") {
|
|
238
251
|
ctx.warn("off-token-color", node,
|
|
239
252
|
`${comp}: ${prop}="${value}" is a raw color — it won't follow the theme or dark mode; prefer a token`);
|
|
@@ -267,7 +280,8 @@ function checkPropValue(ctx, comp, prop, propSpec, valueNode, attr) {
|
|
|
267
280
|
}
|
|
268
281
|
}
|
|
269
282
|
|
|
270
|
-
|
|
283
|
+
/** `takes`, when given, narrows the payload to the component's own base props. */
|
|
284
|
+
function checkStateValue(ctx, comp, state, valueNode, takes) {
|
|
271
285
|
if (valueNode?.type !== "JSXExpressionContainer" || valueNode.expression.type !== "ObjectExpression") return;
|
|
272
286
|
for (const p of valueNode.expression.properties) {
|
|
273
287
|
if (p.type !== "ObjectProperty" || p.computed) continue;
|
|
@@ -278,6 +292,11 @@ function checkStateValue(ctx, comp, state, valueNode) {
|
|
|
278
292
|
`${comp}: "${key}" cannot appear in ${state} — states carry channel props only (spacing, sizing, gap, paint, …)`);
|
|
279
293
|
continue;
|
|
280
294
|
}
|
|
295
|
+
if (takes && !takes[key]) {
|
|
296
|
+
ctx.error("invalid-state-prop", p,
|
|
297
|
+
`${comp}: "${key}" cannot appear in ${state} — ${comp} has no ${key} prop, and a state carries only the props it takes`);
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
281
300
|
const v = literalOf(p.value);
|
|
282
301
|
if (v !== null) checkScalar(ctx, comp, `${state}.${key}`, payloadSpec, v, p.value);
|
|
283
302
|
}
|
|
@@ -356,6 +375,49 @@ function checkTabIndex(ctx, attr) {
|
|
|
356
375
|
|
|
357
376
|
/* ---- rule: astralis component props --------------------------------------------- */
|
|
358
377
|
|
|
378
|
+
const LITERAL_KINDS = { StringLiteral: "string", NumericLiteral: "number", BooleanLiteral: "boolean" };
|
|
379
|
+
|
|
380
|
+
/** One literal value of an own prop: in its vocabulary, or of its scalar kind.
|
|
381
|
+
* `at` is where a finding is reported: the attribute, or the map entry. */
|
|
382
|
+
function checkOwnLeaf(ctx, name, comp, prop, node, at = node) {
|
|
383
|
+
const value = literalOf(node);
|
|
384
|
+
if (value === null) return;
|
|
385
|
+
const values = comp.props?.[prop];
|
|
386
|
+
const kind = comp.scalarProps?.[prop];
|
|
387
|
+
const given = LITERAL_KINDS[node.type] ?? "string";
|
|
388
|
+
if (kind === given || values?.includes(value)) return;
|
|
389
|
+
if (values && (!kind || given === "string")) {
|
|
390
|
+
ctx.error("invalid-recipe-value", at, `${name}: "${value}" is not a ${prop} value` + closedSetHint(value, values));
|
|
391
|
+
} else {
|
|
392
|
+
const shown = given === "string" ? `the string "${value}"` : `${given === "number" ? "a number" : "a boolean"}`;
|
|
393
|
+
ctx.error("invalid-prop-type", at, `${name}: ${prop} takes a ${kind}, not ${shown}` +
|
|
394
|
+
(kind === "number" && given === "string" && /^-?\d+(\.\d+)?$/.test(value) ? ` — write ${prop}={${value}}` : ""));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function checkOwnValue(ctx, name, comp, prop, attr) {
|
|
399
|
+
const valueNode = attr.value;
|
|
400
|
+
if (valueNode === null) return; // a bare attribute is {true}; TypeScript's to judge
|
|
401
|
+
const node = valueNode.type === "JSXExpressionContainer" ? valueNode.expression : valueNode;
|
|
402
|
+
if (node.type !== "ObjectExpression") return checkOwnLeaf(ctx, name, comp, prop, node, attr);
|
|
403
|
+
// Specs from version 4 list the own props that take a responsive map.
|
|
404
|
+
if (!comp.responsiveProps?.includes(prop)) {
|
|
405
|
+
if ((ctx.spec.specVersion ?? 0) >= 4) {
|
|
406
|
+
ctx.error("invalid-prop-type", node, `${name}: ${prop} takes no responsive map — give it one value`);
|
|
407
|
+
}
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
for (const p of node.properties) {
|
|
411
|
+
if (p.type !== "ObjectProperty" || p.computed) continue;
|
|
412
|
+
const key = keyName(p);
|
|
413
|
+
if (!ctx.bpKeys.has(key)) {
|
|
414
|
+
ctx.error("invalid-breakpoint-key", p, `${name}: "${key}" is not a breakpoint — responsive maps take ${[...ctx.bpKeys].join("/")}`);
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
checkOwnLeaf(ctx, name, comp, prop, p.value);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
|
|
359
421
|
function checkComponentProp(ctx, identity, comp, allowed, attr, prop) {
|
|
360
422
|
const name = identity.specName;
|
|
361
423
|
if (comp.exclude?.includes(prop)) {
|
|
@@ -373,8 +435,10 @@ function checkComponentProp(ctx, identity, comp, allowed, attr, prop) {
|
|
|
373
435
|
const overridden = comp.overrides?.includes(prop);
|
|
374
436
|
if (overridden && !comp.props?.[prop]) return;
|
|
375
437
|
if (!overridden && ctx.stateProps.has(prop)) {
|
|
376
|
-
//
|
|
438
|
+
// Box-composing primitives resolve every stateable prop; Text, Heading and
|
|
439
|
+
// Link only those they take as base props. Elsewhere no claim.
|
|
377
440
|
if (comp.groups.includes("box")) checkStateValue(ctx, name, prop, attr.value);
|
|
441
|
+
else if (comp.groups.includes("text")) checkStateValue(ctx, name, prop, attr.value, allowed);
|
|
378
442
|
return;
|
|
379
443
|
}
|
|
380
444
|
if (!overridden && allowed[prop]) {
|
|
@@ -382,25 +446,25 @@ function checkComponentProp(ctx, identity, comp, allowed, attr, prop) {
|
|
|
382
446
|
return;
|
|
383
447
|
}
|
|
384
448
|
// 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
|
-
}
|
|
449
|
+
// out of the shipped d.ts, and the library's own scalar props (Carousel
|
|
450
|
+
// slidesPerView takes a number). Literal values only; dynamic ones are TypeScript's.
|
|
451
|
+
if (comp.props?.[prop] || comp.scalarProps?.[prop]) {
|
|
452
|
+
checkOwnValue(ctx, name, comp, prop, attr);
|
|
392
453
|
return;
|
|
393
454
|
}
|
|
394
455
|
// A style prop this component's type does not take at all: it is passed to
|
|
395
456
|
// the DOM, where it is a meaningless attribute. Only decided when the spec
|
|
396
457
|
// lists the component's own style-prop names (spec builds from Oct 2026).
|
|
397
|
-
|
|
458
|
+
// `domStyleProps` are the element's own attributes under a style prop's
|
|
459
|
+
// name (Textarea rows, Table.Cell colSpan): real, so never stray.
|
|
460
|
+
if (comp.ownStyleProps && !comp.ownStyleProps.includes(prop) && !comp.domStyleProps?.includes(prop) &&
|
|
461
|
+
ctx.stylePropNames.has(prop) && !HTML_ATTRIBUTE_NAMES.has(prop)) {
|
|
398
462
|
const recipe = comp.groups.length === 1 && comp.groups[0] === "placement" && DOCTRINE_PAINT_PROPS.has(prop);
|
|
399
463
|
ctx.error("unknown-style-prop", attr,
|
|
400
464
|
`${name} does not take ${prop}: it reaches the HTML as a stray attribute and changes nothing` +
|
|
401
465
|
(recipe
|
|
402
466
|
? ` (${name} owns how it looks; reach for variant, size or colorScheme)`
|
|
403
|
-
: ` (${name} takes ${comp.groups.join(", ")} props; put ${prop} on a Box around it)`));
|
|
467
|
+
: ` (${name} takes ${comp.groups.length ? `${comp.groups.join(", ")} props` : "no style props"}; put ${prop} on a Box around it)`));
|
|
404
468
|
}
|
|
405
469
|
// Anything else: DOM prop or open-typed, no claim.
|
|
406
470
|
}
|