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
Fixes #3289.
  • Loading branch information
golopot authored and ljharb committed May 20, 2022
1 parent 91d3757 commit fc9664f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,11 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange

## Unreleased

### Fixed
* [`display-name`]: fix false positive for HOF returning only nulls ([#3291][] @golopot)

[#3291]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3291

## [7.30.0] - 2022.05.18

### Added
Expand Down
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 fc9664f

Please sign in to comment.