Skip to content

Commit cdd0d97

Browse files
committed
Fix childs detection in self-closing-comp (fixes #3)
1 parent f9e07da commit cdd0d97

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/rules/self-closing-comp.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ module.exports = function(context) {
2020
}
2121

2222
function hasChildren(node) {
23+
var childrens = node.parent.children;
2324
if (
24-
!node.parent.children.length ||
25-
(node.parent.children[0].type === 'Literal' && !node.parent.children[0].value.trim())
25+
!childrens.length ||
26+
(childrens.length === 1 && childrens[0].type === 'Literal' && !childrens[0].value.trim())
2627
) {
2728
return false;
2829
}

tests/lib/rules/self-closing-comp.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ eslintTester.addRuleTest('lib/rules/self-closing-comp', {
3434
ecmaFeatures: {
3535
jsx: true
3636
}
37+
}, {
38+
code: '\
39+
<Hello>\
40+
<Hello name="John" />\
41+
</Hello>',
42+
ecmaFeatures: {
43+
jsx: true
44+
}
3745
}
3846
],
3947

0 commit comments

Comments
 (0)