From d4d406775084804448b6b86d4d8e8b738ec366ee Mon Sep 17 00:00:00 2001 From: Chiawen Chen Date: Thu, 2 Jun 2022 03:08:09 +0800 Subject: [PATCH] [Fix] `display-name`: fix false positive for HOF returning only nulls and literals --- lib/util/Components.js | 1 - tests/lib/rules/display-name.js | 11 +++++++ tests/lib/rules/no-this-in-sfc.js | 53 ------------------------------- 3 files changed, 11 insertions(+), 54 deletions(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index eb60d845a5..4e6cf07e89 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -503,7 +503,6 @@ function componentRule(rule, context) { if ( (node.parent.type === 'ReturnStatement' || (node.parent.type === 'ArrowFunctionExpression' && node.parent.expression)) && !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 be0c8442e5..87b47e10cf 100644 --- a/tests/lib/rules/display-name.js +++ b/tests/lib/rules/display-name.js @@ -556,6 +556,17 @@ ruleTester.run('display-name', rule, { } `, }, + { + // issue #3300 + code: ` + const f = (a) => () => { + if (a) { + return null; + } + return 1; + }; + `, + }, { code: ` class Test { diff --git a/tests/lib/rules/no-this-in-sfc.js b/tests/lib/rules/no-this-in-sfc.js index a8e80b8b45..0bbf84af28 100644 --- a/tests/lib/rules/no-this-in-sfc.js +++ b/tests/lib/rules/no-this-in-sfc.js @@ -275,58 +275,5 @@ ruleTester.run('no-this-in-sfc', rule, { { messageId: 'noThisInSFC' }, ], }, - { - code: ` - class Foo { - bar() { - return () => { - this.something(); - return null; - } - } - } - `, - errors: [{ messageId: 'noThisInSFC' }], - }, - { - code: ` - class Foo { - bar = () => () => { - this.something(); - return null; - }; - } - `, - features: ['class fields', 'no-ts-old'], // TODO: FIXME: remove `no-ts-old` and fix - errors: [{ messageId: 'noThisInSFC' }], - }, - { - code: ` - class Foo { - bar() { - function Bar(){ - return () => { - this.something(); - return null; - } - } - } - } - `, - errors: [{ messageId: 'noThisInSFC' }], - }, - { - code: ` - class Foo { - bar() { - () => () => { - this.something(); - return null; - }; - } - } - `, - errors: [{ messageId: 'noThisInSFC' }], - }, ]), });