Skip to content

Commit bcf9ae4

Browse files
committed
Handle self-closing tags
1 parent f5e5287 commit bcf9ae4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/rules/__tests__/direct-slot-children.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ ruleTester.run('direct-slot-children', rule, {
1717
`import {PageLayout} from '@primer/react'; <PageLayout><div><PageLayout.Pane>Header</PageLayout.Pane></div></PageLayout>`,
1818
`import {PageLayout} from '@primer/react'; <PageLayout>{true ? <PageLayout.Header>Header</PageLayout.Header> : null}</PageLayout>`,
1919
`import {PageLayout} from './PageLayout'; <PageLayout.Header>Header</PageLayout.Header>`,
20+
`import {FormControl, Radio} from '@primer/react'; <FormControl><Radio value="one" /><FormControl.Label>Choice one</FormControl.Label></FormControl>`,
2021
{
2122
code: `import {Foo} from './Foo'; <Foo><div><Foo.Bar></Foo.Bar></div></Foo>`,
2223
options: [{skipImportCheck: true}]

src/rules/direct-slot-children.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ module.exports = {
6161
}
6262
}
6363

64-
// Push the current element onto the stack
65-
stack.push(name)
64+
// If tag is not self-closing, push it onto the stack
65+
if (!jsxNode.selfClosing) {
66+
stack.push(name)
67+
}
6668
},
6769
JSXClosingElement() {
6870
// Pop the current element off the stack

0 commit comments

Comments
 (0)