Skip to content

Commit

Permalink
[Fix] display-name: fix false positive for HOF returning only nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
golopot committed May 20, 2022
1 parent 91d3757 commit 30423b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/util/Components.js
Expand Up @@ -498,8 +498,13 @@ function componentRule(rule, context) {
return undefined;
}

// case: function any() { return (props) { return not-jsx-and-not-null } }
if (node.parent.type === 'ReturnStatement' && !utils.isReturningJSX(node) && !utils.isReturningOnlyNull(node)) {
// case: const any = () => { return (props) => null }
// case: const any = () => (props) => null
if (
(node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression))
&& !utils.isReturningJSX(node)
&& !utils.isReturningOnlyNull(node)
) {
return undefined;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/display-name.js
Expand Up @@ -579,6 +579,15 @@ ruleTester.run('display-name', rule, {
}
`,
},
{
// issue #3289
code: `
export const demo = (a) => (b) => {
if (a == null) return null;
return b;
}
`,
},
]),

invalid: parsers.all([
Expand Down

0 comments on commit 30423b7

Please sign in to comment.