2 * @fileoverview Prevent extra closing tags for components without children
3 * @author Yannick Croissant
7 // ------------------------------------------------------------------------------
9 // ------------------------------------------------------------------------------
11 module.exports = function(context) {
13 var tagConvention = /^[a-z]|\-/;
14 function isTagName(name) {
15 return tagConvention.test(name);
18 function isComponent(node) {
19 return node.name && node.name.type === 'JSXIdentifier' && !isTagName(node.name.name);
22 function hasChildren(node) {
23 var childrens = node.parent.children;
26 (childrens.length === 1 && childrens[0].type === 'Literal' && !childrens[0].value.trim())
33 // --------------------------------------------------------------------------
35 // --------------------------------------------------------------------------
39 JSXOpeningElement: function(node) {
40 if (!isComponent(node) || node.selfClosing || hasChildren(node)) {
43 context.report(node, 'Empty components are self-closing');