-
-
Notifications
You must be signed in to change notification settings - Fork 211
refactor: extract landmark-roles util (preserving deliberate per-rule region exclusion) #2758
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
johanrd:fix/landmark-roles-util
Apr 28, 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
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,46 @@ | ||
| 'use strict'; | ||
|
|
||
| const { roles } = require('aria-query'); | ||
|
|
||
| // Non-abstract landmark roles derived from aria-query's role taxonomy: any | ||
| // role whose superClass chain includes 'landmark', minus DPub-ARIA `doc-*` | ||
| // (which share that superClass but are outside this plugin's rules' scope — | ||
| // downstream callers can extend if needed). The exact size is intentionally | ||
| // not hard-coded: the derivation is what matters, so if aria-query adds a | ||
| // new non-abstract landmark upstream it will be picked up automatically. | ||
| const ALL_LANDMARK_ROLES = buildLandmarkRoleSet(); | ||
|
|
||
| // The subset that's safe for static-linting rules to treat as landmarks | ||
| // without further verification. `region` is EXCLUDED because a static linter | ||
| // cannot determine at lint time whether the element has an accessible name | ||
| // (via aria-label / aria-labelledby / title), which is required for the | ||
| // `region` role to actually apply to a `<section>` per HTML-AAM. | ||
| // | ||
| // See PR #2694 for the full rationale and spec citation | ||
| // (https://www.w3.org/TR/html-aam-1.0/#el-section): | ||
| // `<section>` without an accessible name has role `generic`, not `region`. | ||
| // | ||
| // Most a11y rules that enumerate landmarks should use this subset. | ||
| // Rules that DO verify accessible names (e.g. template-no-duplicate- | ||
| // landmark-elements, which inspects aria-label / aria-labelledby before | ||
| // classifying a node as a landmark) should import ALL_LANDMARK_ROLES. | ||
| const LANDMARK_ROLES = new Set([...ALL_LANDMARK_ROLES].filter((role) => role !== 'region')); | ||
|
|
||
| function buildLandmarkRoleSet() { | ||
| const result = new Set(); | ||
| for (const [role, def] of roles) { | ||
| if (def.abstract) { | ||
| continue; | ||
| } | ||
| if (role.startsWith('doc-')) { | ||
| continue; | ||
| } | ||
| const descendsFromLandmark = (def.superClass || []).some((chain) => chain.includes('landmark')); | ||
| if (descendsFromLandmark) { | ||
| result.add(role); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| module.exports = { LANDMARK_ROLES, ALL_LANDMARK_ROLES }; | ||
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
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 @@ | ||
| 'use strict'; | ||
|
|
||
| const { LANDMARK_ROLES, ALL_LANDMARK_ROLES } = require('../../../lib/utils/landmark-roles'); | ||
|
|
||
| // The WAI-ARIA 1.2 §5.3.4 landmark roles known at authoring time. Asserting | ||
| // set-inclusion (not an exact-equality / size match) keeps the test robust | ||
| // to future aria-query updates that add non-abstract landmark roles — the | ||
| // derivation (non-abstract + superClass contains 'landmark' + not doc-*) | ||
| // is what we actually care about. | ||
| const KNOWN_LANDMARK_ROLES = [ | ||
| 'banner', | ||
| 'complementary', | ||
| 'contentinfo', | ||
| 'form', | ||
| 'main', | ||
| 'navigation', | ||
| 'region', | ||
| 'search', | ||
| ]; | ||
|
|
||
| describe('ALL_LANDMARK_ROLES', () => { | ||
| it('includes every WAI-ARIA 1.2 §5.3.4 landmark role', () => { | ||
| for (const role of KNOWN_LANDMARK_ROLES) { | ||
| expect(ALL_LANDMARK_ROLES.has(role)).toBe(true); | ||
| } | ||
| // Floor, not ceiling — lets the set grow if aria-query adds new | ||
| // non-abstract landmark roles upstream. | ||
| expect(ALL_LANDMARK_ROLES.size).toBeGreaterThanOrEqual(KNOWN_LANDMARK_ROLES.length); | ||
| }); | ||
|
|
||
| it('excludes DPub-ARIA doc-* roles', () => { | ||
| for (const role of ALL_LANDMARK_ROLES) { | ||
| expect(role.startsWith('doc-')).toBe(false); | ||
| } | ||
| }); | ||
| }); | ||
|
|
||
| describe('LANDMARK_ROLES (the statically-verifiable subset)', () => { | ||
| it('includes every known landmark role except region', () => { | ||
| for (const role of KNOWN_LANDMARK_ROLES) { | ||
| if (role === 'region') { | ||
| continue; | ||
| } | ||
| expect(LANDMARK_ROLES.has(role)).toBe(true); | ||
| } | ||
| // Floor, not ceiling — mirrors the ALL_LANDMARK_ROLES rationale, minus | ||
| // the deliberate region exclusion. | ||
| expect(LANDMARK_ROLES.size).toBeGreaterThanOrEqual(KNOWN_LANDMARK_ROLES.length - 1); | ||
| }); | ||
|
|
||
| it('excludes region (cannot verify accessible-name presence statically)', () => { | ||
| expect(LANDMARK_ROLES.has('region')).toBe(false); | ||
| expect(ALL_LANDMARK_ROLES.has('region')).toBe(true); | ||
| }); | ||
|
|
||
| it('excludes non-landmark roles (button, link, article)', () => { | ||
| expect(LANDMARK_ROLES.has('button')).toBe(false); | ||
| expect(LANDMARK_ROLES.has('link')).toBe(false); | ||
| expect(LANDMARK_ROLES.has('article')).toBe(false); | ||
| }); | ||
| }); |
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.
why does this need a function now where it didn't before?
Uh oh!
There was an error while loading. Please reload this page.
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.
The set is now computed by being derived by
aria-query's role map rather than being hand-maintained. This aligns with other external-lib derivations and picks up any new landmark roles aria-query adds automatically.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.
wouldn't importing it also do that? I don't understand
Uh oh!
There was an error while loading. Please reload this page.
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.
aria-query doesn't expose a landmark-roles list as a top-level export. The landmark role only appears as a superClass entry inside the per-role definitions in roles. So to get "every non-abstract role that descends from landmark" you have to walk roles and filter on superClass, which is what
buildLandmarkRoleSet()does. If aria-query ever adds a direct export we can swap to that.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.
gotchya, thanks!