From e8d2ce9f901f229dfa8460c8ef4aeb515821ddec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odin=20H=C3=B8rthe=20Omdal?= Date: Mon, 27 Jul 2020 11:18:51 +0200 Subject: [PATCH] [Fix] `prop-types`: handle anonymous functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #2728. Co-authored-by: Odin Hørthe Omdal Co-authored-by: Dmitriy Lazarev Co-authored-by: Jordan Harband Co-authored-by: Johnny Zabala --- lib/util/Components.js | 2 +- tests/lib/rules/prop-types.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/util/Components.js b/lib/util/Components.js index deb26dda56..495d6f71f3 100644 --- a/lib/util/Components.js +++ b/lib/util/Components.js @@ -689,7 +689,7 @@ function componentRule(rule, context) { getStatelessComponent(node) { if ( node.type === 'FunctionDeclaration' - && isFirstLetterCapitalized(node.id.name) + && (!node.id || isFirstLetterCapitalized(node.id.name)) && utils.isReturningJSXOrNull(node) ) { return node; diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index 0089d1c812..69b84cf7a7 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -2569,6 +2569,11 @@ ruleTester.run('prop-types', rule, { return null; }`, parser: parsers.TYPESCRIPT_ESLINT + }, + { + code: ` + export default function() {} + ` } ], @@ -5161,6 +5166,16 @@ ruleTester.run('prop-types', rule, { errors: [{ message: '\'value\' is missing in props validation' }] + }, + { + code: ` + export default function ({ value = 'World' }) { + return

Hello {value}

+ } + `, + errors: [{ + message: '\'value\' is missing in props validation' + }] } ] });