Skip to content

fix(lint): validate composition variables on every declaring element - #4391

Closed
leorivastech wants to merge 1 commit into
heygen-com:mainfrom
leorivastech:fix/4383-lint-comp-vars-root
Closed

leorivastech wants to merge 1 commit into
heygen-com:mainfrom
leorivastech:fix/4383-lint-comp-vars-root

Conversation

@leorivastech

Copy link
Copy Markdown
Contributor

What

Broken data-composition-variables JSON was only caught on <html>. If you put the same broken attribute on a composition root div or a template root, lint said nothing, even though the runtime reads it from there too and silently drops the defaults.

Why

A typo in the variables declaration on a root element meant defaults just disappeared, with no hint from lint. The binding check already looks at every declaring element, so this rule was the odd one out.

How

The rule now runs its existing checks (JSON, array shape, entry shape, and the unloadable media default check that lives in the same body) on every element that carries the attribute, not just <html>. Most of the diff is moving that body into a small helper so it can run per element.

Each finding points at its own element, so the line number is right. When the declaration isn't on <html>, the message names the element, so two broken declarations show up as two findings instead of being merged. Messages for <html> are exactly the same as before.

Test plan

  • Unit tests added/updated
    • New cases in composition.test.ts: broken JSON on a full-document root and on a template root (checking element and line), bad entry shapes on a template root, <html> and root checked independently, and a valid template declaration that stays clean. 4 of them fail on main.
  • Manual testing performed
    • Ran the repro script from the issue: html, root and template now all report invalid_composition_variables_declaration.
  • bun run --cwd packages/lint test (704 passing), lint typecheck, oxlint and oxfmt.

Fixes #4383

invalid_composition_variables_declaration only read
data-composition-variables from <html>. The runtime also reads it
from composition roots and template roots, so broken JSON or an
invalid declaration there dropped the defaults with no diagnostic.

Run the existing JSON and shape checks on each element that carries
the attribute, the same set the binding check already unions. Each
finding points at its own element (elementId + snippet, so it gets
that element's line), and a non-<html> declaration names its element
in the message so two broken ones are reported separately. Messages
for <html> are unchanged.

Fixes heygen-com#4383
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.

lint: validate composition variables declared on supported root elements

2 participants