Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix for false positives with no-multi-comp #1089

Merged
merged 1 commit into from Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/util/Components.js
Expand Up @@ -237,14 +237,25 @@ function componentRule(rule, context) {
* @returns {Boolean} True if React.createElement called
*/
isReactCreateElement: function(node) {
return (
var calledOnReact = (
node &&
node.callee &&
node.callee.object &&
node.callee.object.name === 'React' &&
node.callee.property &&
node.callee.property.name === 'createElement'
);

var calledDirectly = (
node &&
node.callee &&
node.callee.name === 'createElement'
);

if (this.hasDestructuredReactCreateElement()) {
return calledDirectly || calledOnReact;
}
return calledOnReact;
},

/**
Expand Down Expand Up @@ -290,10 +301,7 @@ function componentRule(rule, context) {
node[property] &&
node[property].type === 'JSXElement'
;
var returnsReactCreateElement =
this.hasDestructuredReactCreateElement() ||
this.isReactCreateElement(node[property])
;
var returnsReactCreateElement = this.isReactCreateElement(node[property]);

return Boolean(
returnsConditionalJSX ||
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/no-multi-comp.js
Expand Up @@ -10,6 +10,7 @@

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

var parserOptions = {
ecmaVersion: 6,
Expand Down Expand Up @@ -89,6 +90,21 @@ ruleTester.run('no-multi-comp', rule, {
options: [{
ignoreStateless: true
}]
}, {
// multiple non-components
code: [
'import React, { createElement } from "react"',
'const helperFoo = () => {',
' return true;',
'};',
'function helperBar() {',
' return false;',
'};',
'function RealComponent() {',
' return createElement("img");',
'};'
].join('\n'),
parserOptions: assign({sourceType: 'module'}, parserOptions)
}],

invalid: [{
Expand Down