Skip to content

Commit 1353572

Browse files
committed
🐛 Fix tests after aria-query update (5.2.0)
They added more information on the elementRoles set which broke the current logic for matching element roles
1 parent d1d0523 commit 1353572

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Diff for: src/rules/no-redundant-roles.ts

+15-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,22 @@ import {
1313
const exceptions: { [type: string]: string[] } = { nav: ["navigation"] };
1414

1515
function getImplicitRoleSet(node: AST.VElement): any[] | null {
16-
for (const [elementRole, roleSet] of elementRoles.entries()) {
17-
if (matchesElementRole(node, elementRole)) {
18-
// The types for this are wrong, it's actually a string[]
19-
return roleSet as unknown as any[];
20-
}
21-
}
16+
const matchingRoles = elementRoles.entries()
17+
.filter(([consept]) => {
18+
return matchesElementRole(node, consept);
19+
})
20+
.sort(([a], [b]) => {
21+
// try ordering by the concept that is more difficult to match first.
22+
// the number of attributes needed to "match" is used here as a proxy of
23+
// that difficulty.
24+
return (b.attributes?.length ?? 0) - (a.attributes?.length ?? 0);
25+
});
26+
27+
const [preferedRole] = matchingRoles;
28+
const [, roleSet = null] = preferedRole || [];
2229

23-
return null;
30+
// The types for this are wrong, it's actually a string[]
31+
return roleSet as unknown as string[];
2432
}
2533

2634
const rule: Rule.RuleModule = {

0 commit comments

Comments
 (0)