Skip to content

Commit

Permalink
🐛 Fix tests after aria-query update (5.2.0)
Browse files Browse the repository at this point in the history
They added more information on the elementRoles set which broke the current logic for matching element roles
  • Loading branch information
vhoyer committed Jul 16, 2023
1 parent d1d0523 commit 1353572
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/rules/no-redundant-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ import {
const exceptions: { [type: string]: string[] } = { nav: ["navigation"] };

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

const [preferedRole] = matchingRoles;
const [, roleSet = null] = preferedRole || [];

return null;
// The types for this are wrong, it's actually a string[]
return roleSet as unknown as string[];
}

const rule: Rule.RuleModule = {
Expand Down

0 comments on commit 1353572

Please sign in to comment.