-
-
Notifications
You must be signed in to change notification settings - Fork 211
Extract rule: template-no-aria-unsupported-elements #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NullVoxPopuli
merged 1 commit into
ember-cli:master
from
NullVoxPopuli:nvp/template-lint-extract-rule-template-no-aria-unsupported-elements
Feb 19, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # ember/template-no-aria-unsupported-elements | ||
|
|
||
| <!-- end auto-generated rule header --> | ||
|
|
||
| Disallows using ARIA roles, states, and properties on elements that do not support them. | ||
|
|
||
| Certain HTML elements do not support ARIA roles, states, and properties. This rule helps ensure that ARIA attributes are only used on elements that support them, improving accessibility. | ||
|
|
||
| ## Rule Details | ||
|
|
||
| This rule disallows ARIA attributes on elements that do not support them, including: | ||
|
|
||
| - `meta` | ||
| - `html` | ||
| - `script` | ||
| - `style` | ||
| - `title` | ||
| - `base` | ||
| - `head` | ||
| - `link` | ||
|
|
||
| ## Examples | ||
|
|
||
| Examples of **incorrect** code for this rule: | ||
|
|
||
| ```gjs | ||
| <template> | ||
| <meta role="button" /> | ||
| </template> | ||
| ``` | ||
|
|
||
| ```gjs | ||
| <template> | ||
| <script aria-label="Analytics"></script> | ||
| </template> | ||
| ``` | ||
|
|
||
| ```gjs | ||
| <template> | ||
| <style role="presentation"></style> | ||
| </template> | ||
| ``` | ||
|
|
||
| Examples of **correct** code for this rule: | ||
|
|
||
| ```gjs | ||
| <template> | ||
| <div role="button" aria-label="Submit"></div> | ||
| </template> | ||
| ``` | ||
|
|
||
| ```gjs | ||
| <template> | ||
| <button aria-pressed="true">Toggle</button> | ||
| </template> | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [WAI-ARIA in HTML](https://www.w3.org/TR/html-aria/) | ||
| - [ember-template-lint no-aria-unsupported-elements](https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/rule/no-aria-unsupported-elements.md) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** @type {import('eslint').Rule.RuleModule} */ | ||
| module.exports = { | ||
| meta: { | ||
| type: 'problem', | ||
| docs: { | ||
| description: | ||
| 'disallow ARIA roles, states, and properties on elements that do not support them', | ||
| category: 'Accessibility', | ||
| strictGjs: true, | ||
| strictGts: true, | ||
| url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-aria-unsupported-elements.md', | ||
| }, | ||
| fixable: null, | ||
| schema: [], | ||
| messages: { | ||
| unsupported: | ||
| 'ARIA attribute "{{attribute}}" is not supported on <{{element}}> elements. Consider using a different element.', | ||
| }, | ||
| }, | ||
|
|
||
| create(context) { | ||
| // Elements that don't support ARIA | ||
| const ELEMENTS_WITHOUT_ARIA_SUPPORT = new Set([ | ||
| 'meta', | ||
| 'html', | ||
| 'script', | ||
| 'style', | ||
| 'title', | ||
| 'base', | ||
| 'head', | ||
| 'link', | ||
| ]); | ||
|
|
||
| return { | ||
| GlimmerElementNode(node) { | ||
| if (ELEMENTS_WITHOUT_ARIA_SUPPORT.has(node.tag)) { | ||
| const ariaAttributes = node.attributes?.filter( | ||
| (attr) => | ||
| attr.type === 'GlimmerAttrNode' && | ||
| attr.name && | ||
| (attr.name.startsWith('aria-') || attr.name === 'role') | ||
| ); | ||
|
|
||
| for (const attr of ariaAttributes || []) { | ||
| context.report({ | ||
| node: attr, | ||
| messageId: 'unsupported', | ||
| data: { | ||
| attribute: attr.name, | ||
| element: node.tag, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| }; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| const rule = require('../../../lib/rules/template-no-aria-unsupported-elements'); | ||
| const RuleTester = require('eslint').RuleTester; | ||
|
|
||
| const ruleTester = new RuleTester({ | ||
| parser: require.resolve('ember-eslint-parser'), | ||
| parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, | ||
| }); | ||
|
|
||
| ruleTester.run('template-no-aria-unsupported-elements', rule, { | ||
| valid: [ | ||
| '<template><div role="button" aria-label="Submit"></div></template>', | ||
| '<template><button aria-pressed="true">Toggle</button></template>', | ||
| '<template><input aria-label="Username"></template>', | ||
| ], | ||
|
|
||
| invalid: [ | ||
| { | ||
| code: '<template><meta role="button"></template>', | ||
| output: null, | ||
| errors: [{ messageId: 'unsupported' }], | ||
| }, | ||
| { | ||
| code: '<template><script aria-label="Script"></script></template>', | ||
| output: null, | ||
| errors: [{ messageId: 'unsupported' }], | ||
| }, | ||
| { | ||
| code: '<template><style role="presentation"></style></template>', | ||
| output: null, | ||
| errors: [{ messageId: 'unsupported' }], | ||
| }, | ||
| ], | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an expanded list from template-lint https://github.com/ember-template-lint/ember-template-lint/blob/main/lib/rules/no-aria-unsupported-elements.js#L7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems fine tho, it's correct afaict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the documentation to match then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is updated? https://github.com/ember-cli/eslint-plugin-ember/pull/2405/changes#diff-909209d64ff307edeee2114afd241bfde27b22f2bd4b03c66fe7b69e8ee4cb07R13
did you see something specifically?