Skip to content

Commit

Permalink
Merge pull request #2109 from jomasti/issue-2105
Browse files Browse the repository at this point in the history
[Fix] `display-name`: fix false positive for `React.memo`

Fixes #2105.
  • Loading branch information
ljharb committed Jan 3, 2019
2 parents c93cbc6 + 5f9863e commit a86b339
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/util/Components.js
Expand Up @@ -479,7 +479,7 @@ function componentRule(rule, context) {
const isArgument = node.parent && node.parent.type === 'CallExpression'; // Arguments (callback, etc.)
// Attribute Expressions inside JSX Elements (<button onClick={() => props.handleClick()}></button>)
const isJSXExpressionContainer = node.parent && node.parent.type === 'JSXExpressionContainer';
if (node.parent && this.isPragmaComponentWrapper(node.parent)) {
if (isFunction && node.parent && this.isPragmaComponentWrapper(node.parent)) {
return node.parent;
}
// Stop moving up if we reach a class or an argument (like a callback)
Expand Down Expand Up @@ -620,7 +620,9 @@ function componentRule(rule, context) {
if (!utils.isPragmaComponentWrapper(node)) {
return;
}
components.add(node, 2);
if (node.arguments.length > 0 && astUtil.isFunctionLikeExpression(node.arguments[0])) {
components.add(node, 2);
}
},

ClassExpression: function(node) {
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -437,6 +437,21 @@ ruleTester.run('display-name', rule, {
createElement("a");
`,
parser: 'babel-eslint'
}, {
code: `
import React from 'react'
import { string } from 'prop-types'
function Component({ world }) {
return <div>Hello {world}</div>
}
Component.propTypes = {
world: string,
}
export default React.memo(Component)
`
}],

invalid: [{
Expand Down

0 comments on commit a86b339

Please sign in to comment.