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

Fix display-name false positive for React.memo #2109

Merged
merged 1 commit into from Jan 3, 2019
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
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