@@ -3,17 +3,25 @@ const {last} = require('lodash')
3
3
4
4
const slotParentToChildMap = {
5
5
PageLayout : [ 'PageLayout.Header' , 'PageLayout.Footer' ] ,
6
+ SplitPageLayout : [ 'SplitPageLayout.Header' , 'SplitPageLayout.Footer' ] ,
6
7
FormControl : [ 'FormControl.Label' , 'FormControl.Caption' , 'FormControl.LeadingVisual' , 'FormControl.TrailingVisual' ] ,
7
- MarkdownEditor : [ 'MarkdownEditor.Toolbar' , 'MarkdownEditor.Actions' , 'MarkdownEditor.Label' ] ,
8
8
'ActionList.Item' : [ 'ActionList.LeadingVisual' , 'ActionList.TrailingVisual' , 'ActionList.Description' ] ,
9
+ 'ActionList.LinkItem' : [ 'ActionList.LeadingVisual' , 'ActionList.TrailingVisual' , 'ActionList.Description' ] ,
10
+ 'NavList.Item' : [ 'NavList.LeadingVisual' , 'NavList.TrailingVisual' ] ,
9
11
'TreeView.Item' : [ 'TreeView.LeadingVisual' , 'TreeView.TrailingVisual' ] ,
10
12
RadioGroup : [ 'RadioGroup.Label' , 'RadioGroup.Caption' , 'RadioGroup.Validation' ] ,
11
13
CheckboxGroup : [ 'CheckboxGroup.Label' , 'CheckboxGroup.Caption' , 'CheckboxGroup.Validation' ]
14
+ // Ignore `MarkdownEditor` for now because it's still in drafts
15
+ // MarkdownEditor: ['MarkdownEditor.Toolbar', 'MarkdownEditor.Actions', 'MarkdownEditor.Label'],
12
16
}
13
17
14
18
const slotChildToParentMap = Object . entries ( slotParentToChildMap ) . reduce ( ( acc , [ parent , children ] ) => {
15
19
for ( const child of children ) {
16
- acc [ child ] = parent
20
+ if ( acc [ child ] ) {
21
+ acc [ child ] . push ( parent )
22
+ } else {
23
+ acc [ child ] = [ parent ]
24
+ }
17
25
}
18
26
return acc
19
27
} , { } )
@@ -50,19 +58,24 @@ module.exports = {
50
58
( skipImportCheck || isPrimerComponent ( jsxNode . name , context . getScope ( jsxNode ) ) ) &&
51
59
slotChildToParentMap [ name ]
52
60
) {
53
- const expectedParentName = slotChildToParentMap [ name ]
61
+ const expectedParentNames = slotChildToParentMap [ name ]
54
62
const parent = last ( stack )
55
- if ( parent !== expectedParentName ) {
63
+ if ( ! expectedParentNames . includes ( parent ) ) {
56
64
context . report ( {
57
65
node : jsxNode ,
58
66
messageId : 'directSlotChildren' ,
59
- data : { childName : name , parentName : expectedParentName }
67
+ data : {
68
+ childName : name ,
69
+ parentName : expectedParentNames . length > 1 ? expectedParentNames . join ( ' or ' ) : expectedParentNames [ 0 ]
70
+ }
60
71
} )
61
72
}
62
73
}
63
74
64
- // Push the current element onto the stack
65
- stack . push ( name )
75
+ // If tag is not self-closing, push it onto the stack
76
+ if ( ! jsxNode . selfClosing ) {
77
+ stack . push ( name )
78
+ }
66
79
} ,
67
80
JSXClosingElement ( ) {
68
81
// Pop the current element off the stack
0 commit comments