Skip to content

fix(template-no-unsupported-role-attributes): skip elements with a dynamic role - #2831

Merged
NullVoxPopuli merged 1 commit into
ember-cli:masterfrom
johanrd:fix/unsupported-role-attributes-dynamic-role
Aug 2, 2026
Merged

NullVoxPopuli merged 1 commit into
ember-cli:masterfrom
johanrd:fix/unsupported-role-attributes-dynamic-role

Conversation

@johanrd

@johanrd johanrd commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Reported during an ember-template-lint → eslint-plugin-ember migration.

Problem

An element carrying a dynamic role was treated as if it had no role attribute at all. The rule fell back to the element's implicit role and judged every aria-* attribute against it — and the fixer then deleted them.

<div role={{if @useCase "dialog"}} aria-modal={{if @useCase "true"}}></div>

reported:

The attribute aria-modal is not supported by the element div with the implicit role of generic

and --fix rewrote it to <div role={{if @useCase "dialog"}}></div>, silently dropping aria-modal.

ember-template-lint reports nothing here: it branches on the presence of the role attribute before looking at its value, so a dynamic value leaves role undefined and the element is skipped — it never falls through to the implicit role. The port collapsed those two branches into one, losing the distinction between "no role attribute" and "role attribute present but not statically resolvable".

Fix

getExplicitRole now distinguishes the three cases, and a dynamic role short-circuits the element instead of falling back to the implicit role.

Verification

  • New valid cases cover role={{this.role}}, role="{{this.role}}", role={{if ...}} and role={{@role}}, in both .gjs and .hbs mode.
  • Differentially fuzzed against ember-template-lint 7.9.3 over 41,280 generated role/aria-* combinations (every non-abstract aria-query role × 8 host elements × 10 attribute-value forms × 6 aria probes): zero cases where upstream reports and this plugin stays silent. The remaining differences are the pre-existing deliberate ones — this plugin also normalizes whitespace-padded and uppercase role values.

…namic role

An element carrying `role={{...}}` was treated as if it had no `role`
attribute at all, so the rule fell back to the element's implicit role and
judged every `aria-*` attribute against it. On top of the false positive, the
fixer then deleted those attributes:

    <div role={{if @usecase "dialog"}} aria-modal={{if @usecase "true"}}></div>

reported `aria-modal is not supported by ... div with the implicit role of
generic` and `--fix` removed `aria-modal`.

ember-template-lint branches on the presence of the `role` attribute before
looking at its value, and reports nothing here. Restore that: a `role`
attribute with a non-static value means the role is unknowable, so the element
is skipped rather than falling through to the implicit role.
@NullVoxPopuli
NullVoxPopuli merged commit fdea714 into ember-cli:master Aug 2, 2026
10 of 11 checks passed
@github-actions github-actions Bot mentioned this pull request Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants