Skip to content

Commit 644b2ee

Browse files
committed
Fix display-name false negative on es6-style method in React.createClass (fixes #852)
1 parent 8ae52a9 commit 644b2ee

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rules/display-name.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ module.exports = {
125125
var namedFunctionExpression = (
126126
(node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') &&
127127
node.parent &&
128-
(node.parent.type === 'VariableDeclarator' || node.parent.method === true)
128+
(node.parent.type === 'VariableDeclarator' || node.parent.method === true) &&
129+
(!node.parent.parent || !utils.isES5Component(node.parent.parent))
129130
);
130131

131132
if (

tests/lib/rules/display-name.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,18 @@ ruleTester.run('display-name', rule, {
464464
errors: [{
465465
message: 'Component definition is missing display name'
466466
}]
467+
}, {
468+
code: [
469+
'module.exports = React.createClass({',
470+
' render() {',
471+
' return <div>Hello {this.props.name}</div>;',
472+
' }',
473+
'});'
474+
].join('\n'),
475+
parser: 'babel-eslint',
476+
errors: [{
477+
message: 'Component definition is missing display name'
478+
}]
467479
}, {
468480
code: [
469481
'var Hello = React.createClass({',

0 commit comments

Comments
 (0)