From 9a4051476b71804095678225f0c305f354ee8e9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20P=C3=A9rez=20Barrero?= Date: Tue, 12 Jul 2022 18:40:06 +0200 Subject: [PATCH] [Fix] display-name: fix false positive for assignment of function returning null --- lib/util/Components.js | 9 +++++++++ tests/lib/rules/display-name.js | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/util/Components.js b/lib/util/Components.js index b6114717c5..dec1143162 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -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; diff --git a/tests/lib/rules/display-name.js b/tests/lib/rules/display-name.js index 445add83a5..39bdb59cb5 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -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: `