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: fix false positive when using memo #3304

Merged
merged 1 commit into from Jun 1, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
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
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
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