diff --git a/lib/rules/display-name.js b/lib/rules/display-name.js index c1e02be3cd..fcd77895c6 100644 --- a/lib/rules/display-name.js +++ b/lib/rules/display-name.js @@ -160,21 +160,27 @@ module.exports = { if (ignoreTranspilerName || !hasTranspilerName(node)) { return; } - markDisplayNameAsDeclared(node); + if (components.get(node)) { + markDisplayNameAsDeclared(node); + } }, FunctionDeclaration: function(node) { if (ignoreTranspilerName || !hasTranspilerName(node)) { return; } - markDisplayNameAsDeclared(node); + if (components.get(node)) { + markDisplayNameAsDeclared(node); + } }, ArrowFunctionExpression: function(node) { if (ignoreTranspilerName || !hasTranspilerName(node)) { return; } - markDisplayNameAsDeclared(node); + if (components.get(node)) { + markDisplayNameAsDeclared(node); + } }, MethodDefinition: function(node) { diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index 4259af7b7e..82f9bc604b 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -693,5 +693,65 @@ ruleTester.run('display-name', rule, { errors: [{ message: 'Component definition is missing display name' }] + }, { + code: ` + module.exports = function () { + function a () {} + const b = function b () {} + const c = function () {} + const d = () => {} + const obj = { + a: function a () {}, + b: function b () {}, + c () {}, + d: () => {}, + } + return React.createElement("div", {}, "text content"); + } + `, + errors: [{ + message: 'Component definition is missing display name' + }] + }, { + code: ` + module.exports = () => { + function a () {} + const b = function b () {} + const c = function () {} + const d = () => {} + const obj = { + a: function a () {}, + b: function b () {}, + c () {}, + d: () => {}, + } + + return React.createElement("div", {}, "text content"); + } + `, + errors: [{ + message: 'Component definition is missing display name' + }] + }, { + code: ` + export default class extends React.Component { + render() { + function a () {} + const b = function b () {} + const c = function () {} + const d = () => {} + const obj = { + a: function a () {}, + b: function b () {}, + c () {}, + d: () => {}, + } + return
Hello {this.props.name}
; + } + } + `, + errors: [{ + message: 'Component definition is missing display name' + }] }] });