Skip to content

Commit

Permalink
[Fix] display-name: fix false positive when using memo
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot authored and ljharb committed Jun 1, 2022
1 parent e7fc22f commit b9aa04b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
### Fixed
* [`display-name`]: fix false positive for HOF returning only nulls ([#3291][] @golopot)
* [`jsx-no-leaked-render`]: avoid unnecessary negation operators and ternary branches deletion ([#3299][] @Belco90)
* [`display-name`]: fix false positive when using memo ([#3304][] @golopot)

### Changed
* [Docs] [`jsx-tag-spacing`]: rename option from [#3264][] ([#3294[] @ljharb)
* [Docs] [`jsx-key`]: split the examples ([#3293][] @ioggstream)

[#3304]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3304
[#3299]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3299
[#3294]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3294
[#3293]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3293
Expand Down
2 changes: 1 addition & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ function componentRule(rule, context) {

// Case like `React.memo(() => <></>)` or `React.forwardRef(...)`
const pragmaComponentWrapper = utils.getPragmaComponentWrapper(node);
if (pragmaComponentWrapper) {
if (pragmaComponentWrapper && utils.isReturningJSXOrNull(node)) {
return pragmaComponentWrapper;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,19 @@ ruleTester.run('display-name', rule, {
}
`,
},
{
// issue #3303
code: `
function MyComponent(props) {
return <b>{props.name}</b>;
}
const MemoizedMyComponent = React.memo(
MyComponent,
(prevProps, nextProps) => prevProps.name === nextProps.name
)
`,
},
]),

invalid: parsers.all([
Expand Down

0 comments on commit b9aa04b

Please sign in to comment.