Commit 3a1d640
committed
refactor: extract landmark-roles util (preserving deliberate per-rule region exclusion)
Adds `lib/utils/landmark-roles.js` deriving landmark roles from aria-query
(non-abstract roles with 'landmark' in their superClass chain, filtering
out DPub-ARIA doc-* roles). Exports two sets:
- `ALL_LANDMARK_ROLES` — the 8 WAI-ARIA 1.2 §5.3.4 landmark roles
(banner, complementary, contentinfo, form, main, navigation, region,
search).
- `LANDMARK_ROLES` — the 7-role subset excluding `region`, safe for
static-linting rules that cannot verify accessible names at lint time.
`<section>` only gets the `region` landmark role when it has an
accessible name (aria-label / aria-labelledby / title). Without one,
`<section>` has role `generic` per the WAI-ARIA APG landmark examples:
https://www.w3.org/WAI/ARIA/apg/patterns/landmarks/examples/HTML5.html
A static linter cannot verify that accessible names resolve to non-empty
values at runtime, so rules that enumerate landmarks should use the
7-role subset (`LANDMARK_ROLES`) to avoid false-positive-flagging
unnamed-section nesting/redundancy. Rules that DO verify accessible
names can use `ALL_LANDMARK_ROLES`.
This was the reasoning behind ember-cli#2694 (post-merge-review that dropped
section/region from `template-no-nested-landmark`). An earlier draft of
this PR reversed that fix by treating the exclusion as "drift"; this
revision preserves the exclusion and codifies the reasoning in the
shared util so future rule authors inherit the safe default.
- `template-no-duplicate-landmark-elements` — imports `ALL_LANDMARK_ROLES`
as `LANDMARK_ROLES`. This rule inspects aria-label / aria-labelledby
before classifying a node as a landmark (see `getLabel` + dynamic-label
skip in `GlimmerElementNode`), so it can safely include `region`.
- `template-no-nested-landmark` — imports `LANDMARK_ROLES` (the safe
subset). Preserves the ember-cli#2694 behavior.
- `template-no-redundant-role` — imports `LANDMARK_ROLES` (the safe
subset). Also removes the `region: ['section']` entry from
`ROLE_TO_ELEMENTS` for the same reason — ember-cli#2694's reasoning applies
here too: `<section role="region">` should not be flagged as redundant
because we can't verify the section has a name.
- New util tests cover both sets, the DPub exclusion, and non-landmark
role rejection.
- `template-no-nested-landmark` tests preserve the original valid test
for nested `role="region"` without accessible names.
- `template-no-redundant-role` tests preserve the original `<div role="region">`
as valid (div has no implicit role); the previously-regressed test for
`<section role="region">` flagged-in-landmark-only is no longer present
because the rule no longer flags that pattern (consistent with ember-cli#2694).1 parent 414d6d5 commit 3a1d640
7 files changed
Lines changed: 119 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
1 | 7 | | |
2 | 8 | | |
3 | 9 | | |
| |||
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 42 | | |
49 | 43 | | |
50 | 44 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
| 1 | + | |
10 | 2 | | |
11 | 3 | | |
12 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | 23 | | |
34 | 24 | | |
35 | 25 | | |
| |||
114 | 104 | | |
115 | 105 | | |
116 | 106 | | |
117 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
118 | 113 | | |
119 | 114 | | |
120 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
48 | | - | |
| 48 | + | |
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
51 | 52 | | |
52 | 53 | | |
53 | 54 | | |
| |||
66 | 67 | | |
67 | 68 | | |
68 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
69 | 77 | | |
70 | 78 | | |
71 | 79 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
0 commit comments