Skip to content

Commit bd3beb5

Browse files
committed
docs+comment: update stale audit comment + note isSemanticRoleElement perf (Copilot review)
1 parent 63c7097 commit bd3beb5

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

lib/rules/template-require-mandatory-role-attributes.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ function getTagName(node) {
6060
//
6161
// Mirrors jsx-a11y's `isSemanticRoleElement` util
6262
// (https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/src/util/isSemanticRoleElement.js).
63+
//
64+
// Perf note: this walks the full `elementAXObjects` map for every call, giving
65+
// an O(n·m) scan per node (n = concepts, m = axObject→roles). In practice the
66+
// map is small (~dozens of entries) and callers only invoke this after a role
67+
// attribute has already been matched, so it hasn't shown up as a hotspot.
68+
// A future optimization could precompute a `{tag,role} → boolean` lookup.
6369
function isSemanticRoleElement(node, role) {
6470
const tag = getTagName(node);
6571
if (!tag || typeof role !== 'string') {

tests/audit/role-has-required-aria/peer-parity.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,13 @@ ruleTester.run('audit:role-has-required-aria (gts)', rule, {
128128
errors: [{ messageId: 'missingAttributes' }],
129129
},
130130

131-
// === DIVERGENCE — undocumented input+role pairings ===
132-
// Pairings NOT on our whitelist remain flagged. jsx-a11y/angular defer to
133-
// axobject-query's `elementAXObjects`, which covers a larger set; we only
134-
// recognize the documented five pairings. Example mismatches:
135-
// - input[type=checkbox] role=radio → we flag, jsx-a11y/angular don't
136-
// - input[type=radio] role=switch → we flag, peer behavior varies
137-
// These remain invalid (missing aria-checked) in our rule.
131+
// === Pairings NOT exempt — axobject-query does not list them ===
132+
// Semantic-role exemption is driven by axobject-query's `elementAXObjects`
133+
// + `AXObjectRoles` maps — see `isSemanticRoleElement()` in the rule
134+
// source. Pairings the AX-tree data does not list (such as
135+
// `input[type=checkbox] role=radio` or `input[type=radio] role=switch`)
136+
// fall through to the normal required-attribute check and are flagged
137+
// for missing `aria-checked`.
138138
{
139139
code: '<template><input type="checkbox" role="radio" /></template>',
140140
output: null,
@@ -145,8 +145,9 @@ ruleTester.run('audit:role-has-required-aria (gts)', rule, {
145145
output: null,
146146
errors: [{ messageId: 'missingAttributes' }],
147147
},
148-
// Bare `<input role="switch">` (no `type`) — not on our whitelist, stays
149-
// flagged. The input's default `type=text` does not expose aria-checked.
148+
// Bare `<input role="switch">` (no `type`) has no exempt pairing either —
149+
// the element defaults to `type=text`, which axobject-query does not map
150+
// to the switch role.
150151
{
151152
code: '<template><input role="switch" /></template>',
152153
output: null,

0 commit comments

Comments
 (0)