Skip to content

Commit 30423b7

Browse files
committed
[Fix] display-name: fix false positive for HOF returning only nulls
1 parent 91d3757 commit 30423b7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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)