Skip to content

Commit 3ac3b3b

Browse files
author
Lehoczky Zoltán
committed
Merge remote-tracking branch 'upstream/main'
2 parents 76f66a1 + 1353572 commit 3ac3b3b

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-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 = {

Diff for: src/utils/getElementType.ts

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import type { AST } from "vue-eslint-parser";
33
import getElementAttributeValue from "./getElementAttributeValue";
44
import makeKebabCase from "./makeKebabCase";
55

6+
/**
7+
* Returns a kebab-normalized string representing the element node name
8+
* or, if the `is` attribute is a string, its value if present.
9+
* @example <div is="foo-bar"> => "foo-bar"
10+
* @example <foo-bar> => "foo-bar"
11+
* @example <div> => "div"
12+
*/
613
function getElementType(node: AST.VElement) {
714
let is = getElementAttributeValue(node, "is");
815

0 commit comments

Comments
 (0)