Skip to content

Commit fcb6830

Browse files
committed
fix: add 3 missing ARIA 1.3 roles + report specific offending token (Copilot review)
The PR body claimed the ARIA 1.3 draft allowlist covers 5 roles (associationlist, associationlistitemkey, associationlistitemvalue, comment, suggestion). The code only listed 2 ('comment', 'suggestion'); the gap was invisible because no tests exercised any of them. Verified against aria-query 5.3.2: roles.has() returns false for all 5, so all 5 belong in the inline allowlist until aria-query catches up. Also: when reporting presentation/none on a semantic element, include the offending token in the message data instead of the raw role attribute string — avoids surfacing e.g. 'presentation listbox' when only 'presentation' is the issue. Tests: add 5 valid cases in each of the gts and hbs blocks covering all ARIA 1.3 draft roles.
1 parent ad4db80 commit fcb6830

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

lib/rules/template-no-invalid-role.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
const { roles } = require('aria-query');
22

3-
// Valid ARIA roles = concrete (non-abstract) entries from aria-query, plus a
4-
// couple of WAI-ARIA 1.3 draft roles that aria-query doesn't yet ship. The
3+
// Valid ARIA roles = concrete (non-abstract) entries from aria-query, plus the
4+
// WAI-ARIA 1.3 draft roles that aria-query 5.3.2 doesn't yet ship. The
55
// ARIA 1.2 base roles, DPUB-ARIA (doc-*), and Graphics-ARIA (graphics-*) all
6-
// come from aria-query. Both `comment` and `suggestion` are present in the
7-
// current ARIA 1.3 editor's draft (https://w3c.github.io/aria/).
8-
const ARIA_13_DRAFT_ROLES = ['comment', 'suggestion'];
6+
// come from aria-query. `associationlist*`, `comment`, and `suggestion` are in
7+
// the current ARIA 1.3 editor's draft (https://w3c.github.io/aria/) but not
8+
// yet in aria-query, so they're listed here until the next aria-query release
9+
// adds them.
10+
const ARIA_13_DRAFT_ROLES = [
11+
'associationlist',
12+
'associationlistitemkey',
13+
'associationlistitemvalue',
14+
'comment',
15+
'suggestion',
16+
];
917
const VALID_ROLES = new Set([
1018
...[...roles.keys()].filter((role) => !roles.get(role).abstract),
1119
...ARIA_13_DRAFT_ROLES,
@@ -171,14 +179,15 @@ module.exports = {
171179
// Check for presentation/none role on semantic elements (case-insensitive per WAI-ARIA 1.2:
172180
// "Case-sensitivity of the comparison inherits from the case-sensitivity of the host language"
173181
// and HTML is case-insensitive — https://www.w3.org/TR/wai-aria-1.2/#document-handling_author-errors_roles)
174-
if (
175-
tokens.some((t) => t === 'presentation' || t === 'none') &&
176-
SEMANTIC_ELEMENTS.has(node.tag)
177-
) {
182+
const offendingToken = tokens.find((t) => t === 'presentation' || t === 'none');
183+
if (offendingToken && SEMANTIC_ELEMENTS.has(node.tag)) {
178184
context.report({
179185
node: roleAttr,
180186
messageId: 'presentationOnSemantic',
181-
data: { role: raw, tag: node.tag },
187+
// Report the specific offending token, not the whole raw role
188+
// string — e.g. for role="presentation foo" we point at
189+
// 'presentation' rather than the full attribute value.
190+
data: { role: offendingToken, tag: node.tag },
182191
});
183192
}
184193
},

tests/lib/rules/template-no-invalid-role.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ ruleTester.run('template-no-invalid-role', rule, {
8080
'<template><div role="tabpanel row"></div></template>',
8181
'<template><svg role="graphics-document document"></svg></template>',
8282
'<template><section role="doc-appendix doc-bibliography"></section></template>',
83+
84+
// ARIA 1.3 draft roles — not in aria-query 5.3.2 but spec-blessed, so
85+
// the rule accepts them via the inline allowlist.
86+
'<template><div role="associationlist"></div></template>',
87+
'<template><div role="associationlistitemkey"></div></template>',
88+
'<template><div role="associationlistitemvalue"></div></template>',
89+
'<template><div role="comment"></div></template>',
90+
'<template><div role="suggestion"></div></template>',
8391
],
8492

8593
invalid: [
@@ -263,6 +271,14 @@ hbsRuleTester.run('template-no-invalid-role', rule, {
263271
'<div role="tabpanel row"></div>',
264272
'<svg role="graphics-document document"></svg>',
265273
'<section role="doc-appendix doc-bibliography"></section>',
274+
275+
// ARIA 1.3 draft roles — not in aria-query 5.3.2 but spec-blessed, so
276+
// the rule accepts them via the inline allowlist.
277+
'<div role="associationlist"></div>',
278+
'<div role="associationlistitemkey"></div>',
279+
'<div role="associationlistitemvalue"></div>',
280+
'<div role="comment"></div>',
281+
'<div role="suggestion"></div>',
266282
],
267283
invalid: [
268284
{

0 commit comments

Comments
 (0)