forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
BUGFIX: template-no-unsupported-role-attributes — honor aria-query attribute constraints #52
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a61e9a6
fix(template-no-unsupported-role-attributes): honor aria-query attrib…
johanrd 26555dd
lint: prettier format
johanrd ef99ec7
test: add Phase 3 audit fixture translating role-supports-aria-props …
johanrd 088ab85
chore: prettier-format audit fixture
johanrd ffa45d0
docs(template-no-unsupported-role-attributes): document specificity h…
johanrd 5b12b64
fix: trim static attr value, remove dead code (Copilot review)
johanrd 3de05b9
docs: correct audit-fixture CI-run claim (Copilot review)
johanrd 7c90072
test: address Copilot review — strengthen coverage (PR #52)
johanrd 4064ffb
perf(template-no-unsupported-role-attributes): pre-index elementRoles…
johanrd abdbc0c
test(template-no-unsupported-role-attributes): absorb audit-fixture c…
johanrd 248b3ec
test(template-no-unsupported-role-attributes): cite HTML-AAM §3.5.3 i…
johanrd 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,213 @@ | ||
| // Audit fixture — translates peer-plugin test cases into assertions against | ||
| // our rule (`ember/template-no-unsupported-role-attributes`). Runs as part | ||
| // of the default Vitest suite (via the `tests/**/*.js` include glob) and | ||
| // serves double-duty: (1) auditable record of peer-parity divergences, | ||
|
johanrd marked this conversation as resolved.
Outdated
|
||
| // (2) regression coverage pinning CURRENT behavior. Each case encodes what | ||
|
johanrd marked this conversation as resolved.
Outdated
|
||
| // OUR rule does today; divergences from upstream plugins are annotated as | ||
| // `DIVERGENCE —`. Peer-only constructs that can't be translated to Ember | ||
| // templates (JSX spread props, Vue v-bind, Angular `$event`, undefined-handler | ||
| // expression analysis) are marked `AUDIT-SKIP`. | ||
| // | ||
| // Source files (context/ checkouts): | ||
| // - eslint-plugin-jsx-a11y-main/src/rules/role-supports-aria-props.js | ||
| // - eslint-plugin-jsx-a11y-main/__tests__/src/rules/role-supports-aria-props-test.js | ||
| // - eslint-plugin-lit-a11y/lib/rules/role-supports-aria-attr.js | ||
| // - eslint-plugin-lit-a11y/tests/lib/rules/role-supports-aria-attr.js | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const rule = require('../../../lib/rules/template-no-unsupported-role-attributes'); | ||
| const RuleTester = require('eslint').RuleTester; | ||
|
|
||
| const ruleTester = new RuleTester({ | ||
| parser: require.resolve('ember-eslint-parser'), | ||
| parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, | ||
| }); | ||
|
|
||
| ruleTester.run('audit:role-supports-aria-props (gts)', rule, { | ||
| valid: [ | ||
| // === Upstream parity (valid in jsx-a11y + ours) === | ||
| '<template><div /></template>', | ||
| '<template><div id="main" /></template>', | ||
|
|
||
| // Explicit role with supported attr. | ||
| '<template><div role="heading" aria-level="1" /></template>', | ||
| '<template><div role="button" aria-disabled="true" /></template>', | ||
| '<template><div role="textbox" aria-required="true" aria-errormessage="err" /></template>', | ||
| '<template><span role="checkbox" aria-checked={{this.checked}} /></template>', | ||
|
|
||
| // Implicit role tests that match between jsx-a11y and aria-query | ||
| // (we rely on aria-query's elementRoles). | ||
| // a with href — aria-query gives "generic" for first match; jsx-a11y | ||
| // gives "link". Both happen to support aria-describedby etc. | ||
| '<template><a href="#" aria-describedby="x"></a></template>', | ||
| // input[type=submit] — implicit "button". | ||
| '<template><input type="submit" aria-disabled="true" /></template>', | ||
| // select — implicit "combobox". | ||
| '<template><select aria-expanded="false" aria-controls="ctrlID" /></template>', | ||
| // menu[type=toolbar] — aria-query gives "list"; jsx-a11y gives "toolbar". | ||
| // aria-hidden is a global attr supported by both — valid in both. | ||
| '<template><menu type="toolbar" aria-hidden="true" /></template>', | ||
|
|
||
| // Components / unknown elements are skipped. | ||
| '<template><CustomComponent role="banner" /></template>', | ||
| '<template><some-custom-element /></template>', | ||
|
|
||
| // Dynamic role (mustache value) — we skip. | ||
| // jsx-a11y similarly skips non-literal role values. | ||
|
|
||
| // === DIVERGENCE — <a> without href === | ||
| // jsx-a11y: `<a>` without href has NO implicit role → uses global aria | ||
| // set → `<a aria-checked />` is VALID. | ||
| // Our rule: aria-query's first entry for `a` has no attribute constraint | ||
| // and returns "generic". `generic` does not support aria-checked → we | ||
| // would FLAG. (Invalid section captures this.) | ||
| // Captured as the opposite: `<a aria-describedby="x">` passes in both | ||
| // because aria-describedby is global. | ||
| '<template><a aria-describedby="x"></a></template>', | ||
| ], | ||
| invalid: [ | ||
| // === Upstream parity (invalid in jsx-a11y + ours) === | ||
| // Explicit role rejects unsupported attrs. | ||
| { | ||
| code: '<template><div role="link" href="#" aria-checked /></template>', | ||
| output: '<template><div role="link" href="#" /></template>', | ||
| errors: [{ messageId: 'unsupportedExplicit' }], | ||
| }, | ||
| { | ||
| code: '<template><div role="option" aria-notreal="x" aria-selected="false" /></template>', | ||
| output: '<template><div role="option" aria-selected="false" /></template>', | ||
| errors: [{ messageId: 'unsupportedExplicit' }], | ||
| }, | ||
| { | ||
| code: '<template><div role="combobox" aria-multiline="true" aria-expanded="false" aria-controls="x" /></template>', | ||
| output: | ||
| '<template><div role="combobox" aria-expanded="false" aria-controls="x" /></template>', | ||
| errors: [{ messageId: 'unsupportedExplicit' }], | ||
| }, | ||
| { | ||
| code: '<template><a role="menuitem" aria-checked={{this.checked}} /></template>', | ||
| output: '<template><a role="menuitem" /></template>', | ||
| errors: [{ messageId: 'unsupportedExplicit' }], | ||
| }, | ||
|
|
||
| // Implicit role rejects unsupported attrs (parity). | ||
| { | ||
| code: '<template><button type="submit" aria-valuetext="x"></button></template>', | ||
| output: '<template><button type="submit"></button></template>', | ||
| errors: [{ messageId: 'unsupportedImplicit' }], | ||
| }, | ||
| { | ||
| code: '<template><input type="button" aria-invalid="grammar" /></template>', | ||
| output: '<template><input type="button" /></template>', | ||
| errors: [{ messageId: 'unsupportedImplicit' }], | ||
| }, | ||
|
|
||
| // === DIVERGENCE — role-name in message differs for <menu type="toolbar"> === | ||
| // jsx-a11y reports role "toolbar"; we report role "list". | ||
| // Both FLAG though, so the divergence is cosmetic (message text). | ||
| { | ||
| code: '<template><menu type="toolbar" aria-expanded="true" /></template>', | ||
| output: '<template><menu type="toolbar" /></template>', | ||
| errors: [ | ||
| { | ||
| message: | ||
| 'The attribute aria-expanded is not supported by the element menu with the implicit role of list', | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // === DIVERGENCE — role-name differs for <body> === | ||
| // jsx-a11y: <body> implicit role = "document". | ||
| // Our rule: aria-query first match gives role "generic". | ||
| // aria-expanded is unsupported by both, so both FLAG — diff is message. | ||
| { | ||
| code: '<template><body aria-expanded="true"></body></template>', | ||
| output: '<template><body></body></template>', | ||
| errors: [ | ||
| { | ||
| message: | ||
| 'The attribute aria-expanded is not supported by the element body with the implicit role of generic', | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // === Parity — <input type="email"> without `list` → textbox === | ||
| // jsx-a11y considers these to be "textbox" (since aria-query's first | ||
| // "email" entry has "list attribute not set" constraint → textbox). | ||
| // Our rule now honors aria-query attribute constraints: `type=email` | ||
| // without a `list` attribute maps to "textbox". With `list=...` it | ||
| // maps to "combobox" (sibling case below). | ||
| // aria-level is not supported by either role; still flagged. | ||
| { | ||
| code: '<template><input type="email" aria-level={{this.level}} /></template>', | ||
| output: '<template><input type="email" /></template>', | ||
| errors: [ | ||
| { | ||
| message: | ||
| 'The attribute aria-level is not supported by the element input with the implicit role of textbox', | ||
| }, | ||
| ], | ||
| }, | ||
| // <input type="email" list="x"> → "combobox" (aria-level unsupported there too). | ||
| { | ||
| code: '<template><input type="email" list="x" aria-level={{this.level}} /></template>', | ||
| output: '<template><input type="email" list="x" /></template>', | ||
| errors: [ | ||
| { | ||
| message: | ||
| 'The attribute aria-level is not supported by the element input with the implicit role of combobox', | ||
| }, | ||
| ], | ||
| }, | ||
|
|
||
| // === DIVERGENCE — <a> without href, with non-global aria attr === | ||
| // jsx-a11y: VALID (no implicit role → global set). | ||
| // Our rule: role=generic, aria-checked not supported → FLAG. FALSE POSITIVE. | ||
| { | ||
| code: '<template><a aria-checked /></template>', | ||
| output: '<template><a /></template>', | ||
| errors: [{ messageId: 'unsupportedImplicit' }], | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| const hbsRuleTester = new RuleTester({ | ||
| parser: require.resolve('ember-eslint-parser/hbs'), | ||
| parserOptions: { ecmaVersion: 2022, sourceType: 'module' }, | ||
| }); | ||
|
|
||
| hbsRuleTester.run('audit:role-supports-aria-props (hbs)', rule, { | ||
| valid: [ | ||
| '<div />', | ||
| '<div role="heading" aria-level="1" />', | ||
| '<div role="button" aria-disabled="true" />', | ||
| '<a href="#" aria-describedby=""></a>', | ||
| '<menu type="toolbar" aria-hidden="true" />', | ||
| '<input type="submit" aria-disabled="true" />', | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: '<div role="link" href="#" aria-checked />', | ||
| output: '<div role="link" href="#" />', | ||
| errors: [{ message: 'The attribute aria-checked is not supported by the role link' }], | ||
| }, | ||
| { | ||
| code: '<menu type="toolbar" aria-expanded="true" />', | ||
| output: '<menu type="toolbar" />', | ||
| errors: [ | ||
| { | ||
| message: | ||
| 'The attribute aria-expanded is not supported by the element menu with the implicit role of list', | ||
| }, | ||
| ], | ||
| }, | ||
| // DIVERGENCE: <a aria-checked /> — jsx-a11y says valid (no implicit role). | ||
| // We flag with implicit role "generic". | ||
| { | ||
| code: '<a aria-checked />', | ||
| output: '<a />', | ||
| errors: [{ messageId: 'unsupportedImplicit' }], | ||
| }, | ||
| ], | ||
| }); | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.