Skip to content

Commit 004baae

Browse files
committed
Fix ES5 class detection when using createClass by itself (fixes #297)
1 parent 794a05a commit 004baae

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/util/Components.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ function componentRule(rule, context) {
116116
* @returns {Boolean} True if the node is a React ES5 component, false if not
117117
*/
118118
isES5Component: function(node) {
119-
return node.parent && sourceCode.getText(node.parent.callee) === 'React.createClass';
119+
if (!node.parent) {
120+
return false;
121+
}
122+
return /^(React\.)?createClass$/.test(sourceCode.getText(node.parent.callee));
120123
},
121124

122125
/**

tests/lib/rules/display-name.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,17 @@ ruleTester.run('display-name', rule, {
328328
'};'
329329
].join('\n'),
330330
parser: 'babel-eslint'
331+
}, {
332+
code: [
333+
'import React, { createClass } from \'react\';',
334+
'export default createClass({',
335+
' displayName: \'Foo\',',
336+
' render() {',
337+
' return <h1>foo</h1>;',
338+
' }',
339+
'});'
340+
].join('\n'),
341+
parser: 'babel-eslint'
331342
}
332343
],
333344

0 commit comments

Comments
 (0)