Skip to content

Commit b646485

Browse files
authored
Merge pull request jsx-eslint#1089 from benstepp/bs-multicomp-false-positives
Bug fix for false positives with no-multi-comp
2 parents 8148833 + c038899 commit b646485

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lib/util/Components.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,25 @@ function componentRule(rule, context) {
237237
* @returns {Boolean} True if React.createElement called
238238
*/
239239
isReactCreateElement: function(node) {
240-
return (
240+
var calledOnReact = (
241241
node &&
242242
node.callee &&
243243
node.callee.object &&
244244
node.callee.object.name === 'React' &&
245245
node.callee.property &&
246246
node.callee.property.name === 'createElement'
247247
);
248+
249+
var calledDirectly = (
250+
node &&
251+
node.callee &&
252+
node.callee.name === 'createElement'
253+
);
254+
255+
if (this.hasDestructuredReactCreateElement()) {
256+
return calledDirectly || calledOnReact;
257+
}
258+
return calledOnReact;
248259
},
249260

250261
/**
@@ -290,10 +301,7 @@ function componentRule(rule, context) {
290301
node[property] &&
291302
node[property].type === 'JSXElement'
292303
;
293-
var returnsReactCreateElement =
294-
this.hasDestructuredReactCreateElement() ||
295-
this.isReactCreateElement(node[property])
296-
;
304+
var returnsReactCreateElement = this.isReactCreateElement(node[property]);
297305

298306
return Boolean(
299307
returnsConditionalJSX ||

tests/lib/rules/no-multi-comp.js

+16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
var rule = require('../../../lib/rules/no-multi-comp');
1212
var RuleTester = require('eslint').RuleTester;
13+
var assign = require('object.assign');
1314

1415
var parserOptions = {
1516
ecmaVersion: 6,
@@ -89,6 +90,21 @@ ruleTester.run('no-multi-comp', rule, {
8990
options: [{
9091
ignoreStateless: true
9192
}]
93+
}, {
94+
// multiple non-components
95+
code: [
96+
'import React, { createElement } from "react"',
97+
'const helperFoo = () => {',
98+
' return true;',
99+
'};',
100+
'function helperBar() {',
101+
' return false;',
102+
'};',
103+
'function RealComponent() {',
104+
' return createElement("img");',
105+
'};'
106+
].join('\n'),
107+
parserOptions: assign({sourceType: 'module'}, parserOptions)
92108
}],
93109

94110
invalid: [{

0 commit comments

Comments
 (0)