Skip to content

feat(cli): validate rm-* and JSON component attributes at validation time#33

Merged
LeadcodeDev merged 1 commit into
mainfrom
feat/html-transpile-validation
Jul 18, 2026
Merged

feat(cli): validate rm-* and JSON component attributes at validation time#33
LeadcodeDev merged 1 commit into
mainfrom
feat/html-transpile-validation

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #17.

Goal: LLM authoring mistakes surface at rustmotion validate, not silently at render.

  • New validate_attrs module: a lazy per-tag known-attribute map generated from schemars::schema_for!(Component). Verified empirically that flattened TimingConfig fields are inlined per variant (no allowlist needed); explicit handling for wrapper keys (position/x/y/z-index), the two serde tag aliases, and recursion into children only for real containers. No component has catch-all/dynamic keys (audited).
  • Unknown attribute → warning with did-you-mean + known set, e.g. unknown attribute 'sufix' on 'counter' — … (did you mean 'suffix'? …). New --strict-attrs flag promotes to errors. Applies to JSON scenarios too — same safety net either way.
  • Typed-parse failures are now always blocking (accepted deviation): a child failing typed deserialization is dropped at render, so a "valid" verdict was a lie. This also gives readable errors for unknown CSS properties coming from the HTML dialect (CssStyle is deny_unknown_fields).

Tests: 8 new (TDD) — exact-name warning, strict promotion, flatten/wrapper non-flagging, clean-scenario zero warnings, nested paths, alias tags, blocking invalid component, readable CSS error from HTML. showcase.html/hello.html stay green with zero attr warnings (no false positives).

Verify: cargo test --workspace → 159 passed ✓ · cargo fmt --check ✓ · clippy 0 warnings ✓ · manual end-to-end: typo warns (exit 0) / --strict-attrs errors (exit 1) ✓

LLM authoring errors now surface at validation instead of vanishing at
render:

- new validate_attrs module builds a per-tag known-attribute map from
  the schemars JSON Schema (flattened TimingConfig fields verified to
  be inlined; wrapper keys and serde tag aliases handled explicitly)
- unknown attributes warn with a did-you-mean suggestion and the known
  set; --strict-attrs promotes them to errors (JSON and HTML sources)
- typed-parse failures are now always blocking: a child that fails
  typed deserialization is dropped at render, so validate previously
  saying 'valid' was a lie (this also surfaces unknown CSS properties
  from the HTML dialect with a readable error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(html): validate rm-* attributes and CSS properties at transpile time

1 participant