Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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