From 8a78051a0142c07cce4182a5009116921e278b68 Mon Sep 17 00:00:00 2001 From: David Zidar Date: Fri, 8 Nov 2024 11:21:06 +0100 Subject: [PATCH] eslint-plugin-react-hooks: Fix international component name compatibility --- .../__tests__/ESLintRulesOfHooks-test.js | 9 +++++++++ packages/eslint-plugin-react-hooks/src/RulesOfHooks.ts | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index b8ec97678aa16..03a3b4ce2717e 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -561,6 +561,15 @@ const tests = { }; `, }, + { + code: normalizeIndent` + // Valid because React supports international languages + function ÄndraVärdeComponent() { + useHook(); + return
; + } + ` + }, ], invalid: [ { diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.ts b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.ts index 0ab0c5ff21e4b..ac60f9f625f37 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.ts +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.ts @@ -42,7 +42,10 @@ function isHook(node: Node): boolean { * always start with an uppercase letter. */ function isComponentName(node: Node): boolean { - return node.type === 'Identifier' && /^[A-Z]/.test(node.name); + return node.type === 'Identifier' && + node.name[0] === node.name[0].toUpperCase() && + node.name[0] !== '_' && + node.name[0] !== '$'; } function isReactFunction(node: Node, functionName: string): boolean {