File tree 2 files changed +22
-7
lines changed
2 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -13,14 +13,22 @@ import {
13
13
const exceptions : { [ type : string ] : string [ ] } = { nav : [ "navigation" ] } ;
14
14
15
15
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 || [ ] ;
22
29
23
- return null ;
30
+ // The types for this are wrong, it's actually a string[]
31
+ return roleSet as unknown as string [ ] ;
24
32
}
25
33
26
34
const rule : Rule . RuleModule = {
Original file line number Diff line number Diff line change @@ -3,6 +3,13 @@ import type { AST } from "vue-eslint-parser";
3
3
import getElementAttributeValue from "./getElementAttributeValue" ;
4
4
import makeKebabCase from "./makeKebabCase" ;
5
5
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
+ */
6
13
function getElementType ( node : AST . VElement ) {
7
14
let is = getElementAttributeValue ( node , "is" ) ;
8
15
You can’t perform that action at this time.
0 commit comments