diff --git a/docs/rules/self-closing-comp.md b/docs/rules/self-closing-comp.md index 989f38f98f..64a9c98b28 100644 --- a/docs/rules/self-closing-comp.md +++ b/docs/rules/self-closing-comp.md @@ -10,6 +10,8 @@ The following patterns are considered warnings: ```jsx var HelloJohn = ; + +var HelloJohnCompound = ; ``` The following patterns are **not** considered warnings: @@ -21,8 +23,12 @@ var intentionalSpace =
{' '}
; var HelloJohn = ; +var HelloJohnCompound = ; + var Profile = ; +var ProfileCompound = ; + var HelloSpace = {' '}; ``` @@ -58,7 +64,11 @@ var intentionalSpace =
{' '}
; var HelloJohn = ; +var HelloJohnCompound = ; + var Profile = ; + +var ProfileCompound = ; ``` ### `html` diff --git a/lib/rules/self-closing-comp.js b/lib/rules/self-closing-comp.js index 94ca78a374..3e5150939e 100644 --- a/lib/rules/self-closing-comp.js +++ b/lib/rules/self-closing-comp.js @@ -42,7 +42,11 @@ module.exports = { create(context) { function isComponent(node) { - return node.name && node.name.type === 'JSXIdentifier' && !jsxUtil.isDOMComponent(node); + return ( + node.name && + (node.name.type === 'JSXIdentifier' || node.name.type === 'JSXMemberExpression') && + !jsxUtil.isDOMComponent(node) + ); } function childrenIsEmpty(node) { diff --git a/tests/lib/rules/self-closing-comp.js b/tests/lib/rules/self-closing-comp.js index 57321bb405..ec36323d74 100644 --- a/tests/lib/rules/self-closing-comp.js +++ b/tests/lib/rules/self-closing-comp.js @@ -30,30 +30,52 @@ ruleTester.run('self-closing-comp', rule, { valid: [ { code: 'var HelloJohn = ;' + }, { + code: 'var HelloJohn = ;' }, { code: 'var Profile = ;' + }, { + code: 'var Profile = ;' }, { code: ` ` + }, { + code: ` + + + + ` }, { code: 'var HelloJohn = ;' + }, { + code: 'var HelloJohn = ;' }, { code: 'var HelloJohn = ;' + }, { + code: 'var HelloJohn = ;' }, { code: 'var HelloJohn =
 
;' }, { code: 'var HelloJohn =
{\' \'}
;' }, { code: 'var HelloJohn =  ;' + }, { + code: 'var HelloJohn =  ;' }, { code: 'var HelloJohn = ;', options: [] + }, { + code: 'var HelloJohn = ;', + options: [] }, { code: 'var Profile = ;', options: [] + }, { + code: 'var Profile = ;', + options: [] }, { code: ` @@ -61,6 +83,13 @@ ruleTester.run('self-closing-comp', rule, { `, options: [] + }, { + code: ` + + + + `, + options: [] }, { code: 'var HelloJohn =
;', options: [] @@ -76,15 +105,27 @@ ruleTester.run('self-closing-comp', rule, { }, { code: 'var HelloJohn =  ;', options: [] + }, { + code: 'var HelloJohn =  ;', + options: [] }, { code: 'var HelloJohn = ;', options: [{component: false}] + }, { + code: 'var HelloJohn = ;', + options: [{component: false}] }, { code: 'var HelloJohn = \n;', options: [{component: false}] + }, { + code: 'var HelloJohn = \n;', + options: [{component: false}] }, { code: 'var HelloJohn = ;', options: [{component: false}] + }, { + code: 'var HelloJohn = ;', + options: [{component: false}] }, { code: 'var contentContainer =
;', options: [{html: true}] @@ -121,12 +162,24 @@ ruleTester.run('self-closing-comp', rule, { errors: [{ message: 'Empty components are self-closing' }] + }, { + code: 'var CompoundHelloJohn = ;', + output: 'var CompoundHelloJohn = ;', + errors: [{ + message: 'Empty components are self-closing' + }] }, { code: 'var HelloJohn = \n;', output: 'var HelloJohn = ;', errors: [{ message: 'Empty components are self-closing' }] + }, { + code: 'var HelloJohn = \n;', + output: 'var HelloJohn = ;', + errors: [{ + message: 'Empty components are self-closing' + }] }, { code: 'var HelloJohn = ;', output: 'var HelloJohn = ;', @@ -134,6 +187,13 @@ ruleTester.run('self-closing-comp', rule, { errors: [{ message: 'Empty components are self-closing' }] + }, { + code: 'var HelloJohn = ;', + output: 'var HelloJohn = ;', + options: [], + errors: [{ + message: 'Empty components are self-closing' + }] }, { code: 'var HelloJohn = \n;', output: 'var HelloJohn = ;', @@ -141,6 +201,13 @@ ruleTester.run('self-closing-comp', rule, { errors: [{ message: 'Empty components are self-closing' }] + }, { + code: 'var HelloJohn = \n;', + output: 'var HelloJohn = ;', + options: [], + errors: [{ + message: 'Empty components are self-closing' + }] }, { code: 'var contentContainer =
;', output: 'var contentContainer =
;',