@@ -67,35 +67,39 @@ const checkForKey = (
67
67
conditionalFamilies
68
68
) => {
69
69
if (
70
- node . parent &&
71
- node . parent . type === 'VElement' &&
72
- hasConditionalRenderedSiblings ( node , componentName )
70
+ ! node . parent ||
71
+ node . parent . type !== 'VElement' ||
72
+ ! hasConditionalRenderedSiblings ( node , componentName )
73
73
) {
74
- const conditionalFamily = conditionalFamilies . get ( node . parent )
74
+ return
75
+ }
75
76
76
- if ( conditionalFamily && ! utils . hasAttribute ( node , 'key' ) ) {
77
- const needsKey =
78
- conditionalFamily . if === node ||
79
- conditionalFamily . else === node ||
80
- conditionalFamily . elseIf . includes ( node )
77
+ const conditionalFamily = conditionalFamilies . get ( node . parent )
81
78
82
- if ( needsKey ) {
83
- context . report ( {
84
- node : node . startTag ,
85
- loc : node . startTag . loc ,
86
- messageId : 'requireKey' ,
87
- data : { componentName } ,
88
- fix ( fixer ) {
89
- const afterComponentNamePosition =
90
- node . startTag . range [ 0 ] + componentName . length + 1
91
- return fixer . insertTextBeforeRange (
92
- [ afterComponentNamePosition , afterComponentNamePosition ] ,
93
- ` key="${ uniqueKey } "`
94
- )
95
- }
96
- } )
79
+ if ( ! conditionalFamily || utils . hasAttribute ( node , 'key' ) ) {
80
+ return
81
+ }
82
+
83
+ const needsKey =
84
+ conditionalFamily . if === node ||
85
+ conditionalFamily . else === node ||
86
+ conditionalFamily . elseIf . includes ( node )
87
+
88
+ if ( needsKey ) {
89
+ context . report ( {
90
+ node : node . startTag ,
91
+ loc : node . startTag . loc ,
92
+ messageId : 'requireKey' ,
93
+ data : { componentName } ,
94
+ fix ( fixer ) {
95
+ const afterComponentNamePosition =
96
+ node . startTag . range [ 0 ] + componentName . length + 1
97
+ return fixer . insertTextBeforeRange (
98
+ [ afterComponentNamePosition , afterComponentNamePosition ] ,
99
+ ` key="${ uniqueKey } "`
100
+ )
97
101
}
98
- }
102
+ } )
99
103
}
100
104
}
101
105
0 commit comments