Skip to content

Commit 9a40514

Browse files
committed
[Fix] display-name: fix false positive for assignment of function returning null
1 parent f7fe38f commit 9a40514

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/util/Components.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,15 @@ function componentRule(rule, context) {
508508
return undefined;
509509
}
510510

511+
// case: any = () => { return => null }
512+
// case: any = () => null
513+
if (node.parent.type === 'AssignmentExpression' && !isPropertyAssignment && utils.isReturningJSXOrNull(node)) {
514+
if (isFirstLetterCapitalized(node.parent.left.name)) {
515+
return node;
516+
}
517+
return undefined;
518+
}
519+
511520
// for case abc = { [someobject.somekey]: props => { ... return not-jsx } }
512521
if (node.parent && node.parent.key && node.parent.key.type === 'MemberExpression' && !utils.isReturningJSX(node) && !utils.isReturningOnlyNull(node)) {
513522
return undefined;

tests/lib/rules/display-name.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,15 @@ ruleTester.run('display-name', rule, {
588588
}
589589
`,
590590
},
591+
{
592+
// issue #3329
593+
code: `
594+
let demo = null;
595+
demo = (a) => {
596+
if (a == null) return null;
597+
return f(a);
598+
};`,
599+
},
591600
{
592601
// issue #3303
593602
code: `

0 commit comments

Comments
 (0)