Skip to content

Commit

Permalink
[Fix] display-name: fix false positive for assignment of function ret…
Browse files Browse the repository at this point in the history
…urning null
  • Loading branch information
apbarrero committed Jul 12, 2022
1 parent f7fe38f commit 9a40514
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ function componentRule(rule, context) {
return undefined;
}

// case: any = () => { return => null }
// case: any = () => null
if (node.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
if (isFirstLetterCapitalized(node.parent.left.name)) {
return node;
}
return undefined;
}

// for case abc = { [someobject.somekey]: props => { ... return not-jsx } }
if (node.parent && node.parent.key && node.parent.key.type === 'MemberExpression' && !utils.isReturningJSX(node) && !utils.isReturningOnlyNull(node)) {
return undefined;
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/display-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,15 @@ ruleTester.run('display-name', rule, {
}
`,
},
{
// issue #3329
code: `
let demo = null;
demo = (a) => {
if (a == null) return null;
return f(a);
};`,
},
{
// issue #3303
code: `
Expand Down

0 comments on commit 9a40514

Please sign in to comment.