Skip to content

Commit fc9664f

Browse files
golopotljharb
authored andcommitted
[Fix] display-name: fix false positive for HOF returning only nulls
Fixes #3289.
1 parent 91d3757 commit fc9664f

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
55

66
## Unreleased
77

8+
### Fixed
9+
* [`display-name`]: fix false positive for HOF returning only nulls ([#3291][] @golopot)
10+
11+
[#3291]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3291
12+
813
## [7.30.0] - 2022.05.18
914

1015
### Added

lib/util/Components.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,13 @@ function componentRule(rule, context) {
498498
return undefined;
499499
}
500500

501-
// case: function any() { return (props) { return not-jsx-and-not-null } }
502-
if (node.parent.type === 'ReturnStatement' && !utils.isReturningJSX(node) && !utils.isReturningOnlyNull(node)) {
501+
// case: const any = () => { return (props) => null }
502+
// case: const any = () => (props) => null
503+
if (
504+
(node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression))
505+
&& !utils.isReturningJSX(node)
506+
&& !utils.isReturningOnlyNull(node)
507+
) {
503508
return undefined;
504509
}
505510

tests/lib/rules/display-name.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,15 @@ ruleTester.run('display-name', rule, {
579579
}
580580
`,
581581
},
582+
{
583+
// issue #3289
584+
code: `
585+
export const demo = (a) => (b) => {
586+
if (a == null) return null;
587+
return b;
588+
}
589+
`,
590+
},
582591
]),
583592

584593
invalid: parsers.all([

0 commit comments

Comments
 (0)