feat: add template-no-autoplay#2759
Draft
johanrd wants to merge 8 commits intoember-cli:masterfrom
Draft
Conversation
…uted-video exception)
…ditionalElements, docs
…ases
Cover mixed static+dynamic concat (unknown → skip), single {{false}}
part on muted (falsy → autoplay allowed), and dynamic muted concat
(unknown → skip).
Empirically verified Glimmer behavior:
- <video muted="false"> → kept (muted=ON via HTML boolean attr)
- <video muted={{false}}> → omitted (muted=OFF)
- <video muted="{{false}}"> → omitted (muted=OFF)
So `<video autoplay muted="{{false}}">` actually has no muted attribute at
render time and the muted exemption shouldn't apply — it's a real autoplay
violation. Move the case from valid to invalid.
…tion" This reverts commit 2b35f35.
…ed Glimmer behavior
The rule's classifyAttrValue was based on an intuitive model that turns out
to be wrong in two ways, both confirmed empirically (see new
docs/glimmer-attribute-behavior.md):
- Bare-mustache string "false" (`attr={{"false"}}`) is JS-truthy, so Glimmer
renders it as `attr="false"` and sets the IDL property — not omitted as the
literal "false" suggests.
- Concat-mustache (`attr="{{X}}"`) sets the IDL property to true regardless
of the literal value inside, including `"{{false}}"`. Verified against
<video muted="{{false}}"> → videoEl.muted === true.
Result: the only literal form that genuinely makes Glimmer omit the
attribute is bare `{{false}}`. Everything else with a literal is truthy at
runtime.
Simplified classifyAttrValue accordingly and corrected three test fixtures:
- <audio autoplay={{"false"}}> → moved valid → invalid (autoplay plays).
- <audio autoplay="{{false}}"> → moved valid → invalid (autoplay plays).
- <video autoplay muted={{"false"}}> → moved invalid → valid (muted IDL=true,
exemption applies).
Plus added lock-in tests for forms that were silently ambiguous before:
muted={{"true"}}, muted="{{true}}", muted="{{false}}", autoplay="{{'false'}}".
Reverts the earlier "test: correct muted='{{false}}' expectation" commit on
this branch, which fixed the test in the wrong direction (muted IDL is
actually true under that form, exemption applies).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This is part of a series where Claude has audited
eslint-plugin-emberagainst jsx-a11y, vuejs-accessibility, angular-eslint, lit-a11y and html-validate,ember-template-lint, and the HTML and WCAG specs.See html-validate
no-autoplayfor the peer rule concept.Adds
template-no-autoplay: flagsautoplayon<audio>/<video>when the attribute is statically present.Premises
Premise 1 (HTML): The HTML spec's
autoplayattribute is a boolean attribute: presence alone means "true", regardless of value.<audio autoplay="false">reads.autoplay === trueat the DOM level (verified in Chrome).Premise 2 (WCAG): WCAG 2.1 SC 1.4.2 Audio Control (Level A) applies to audio that plays automatically for more than 3 seconds. The W3C ACT rule
aaa1bfthat operationalizes SC 1.4.2 is explicitly inapplicable whenmutedis true or the media has no audio track.<video autoplay muted>(GIF-style) is out of SC 1.4.2's scope. Silent-motion concerns fall under SC 2.2.2 Pause/Stop/Hide, which depends on runtime facts static analysis cannot determine.Conclusion: Flag
<audio>with a statically-presentautoplay. Flag<video>with a statically-presentautoplayunless a statically-truthymutedis also present. Skip mustache-unknown values — false positives are worse than false negatives. Recognize explicit{{false}}/{{"false"}}literals as opt-outs.Flags
Allows
Schema option
additionalElements: string[]extends the default{audio, video}set. Themutedexception applies only to<video>; elements added viaadditionalElementsare flagged onautoplayalone (their semantics are unknown).Prior art
media-has-captioncovers captions, not autoplay).no-autoplayautoplayon configured tags;include/excludeoptions; skipsDynamicValue. No muted-video exception.Notes
<video autoplay muted>is not flagged — aligned with W3C ACTaaa1bf's scoping of SC 1.4.2 to audio output.<audio autoplay muted>is still flagged — the combination is spec-nonsensical and strongly suggests author confusion.{audio, video}rather than html-validate's any-element default, because Ember codebases commonly passautoplayas a non-media component arg (e.g.<Carousel autoplay={{...}} />).