From 790aab0eaa1ec8d3df0bb57247cba4b9d6072a75 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Thu, 30 Nov 2023 17:35:56 -0500 Subject: [PATCH 1/2] [lint] treat React.use() the same as use() --- .../__tests__/ESLintRulesOfHooks-test.js | 3 +++ .../eslint-plugin-react-hooks/src/RulesOfHooks.js | 12 +++++++++++- 2 files changed, 14 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 260829d8ad083..f392cf61989bd 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -489,9 +489,12 @@ const tests = { }, { code: normalizeIndent` + import * as React from 'react'; function App() { if (shouldShowText) { const text = use(query); + const data = React.use(thing); + const data2 = react.use(thing2); return } return diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index 660d92f9ea77c..280ac6419731f 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -108,7 +108,17 @@ function isUseEffectEventIdentifier(node) { } function isUseIdentifier(node) { - return node.type === 'Identifier' && node.name === 'use'; + switch (node.type) { + case 'Identifier': + return node.name === 'use'; + case 'MemberExpression': + return ( + (node.object.name === 'React' || node.object.name === 'react') && + node.property.name === 'use' + ); + default: + return false; + } } export default { From 28a382ad63c3c5c5a5c6a87d50bdf2f9affb0bf2 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Fri, 1 Dec 2023 14:26:07 -0500 Subject: [PATCH 2/2] use isReactFunction --- .../eslint-plugin-react-hooks/src/RulesOfHooks.js | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index 280ac6419731f..bdc23f9f885ca 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -108,17 +108,7 @@ function isUseEffectEventIdentifier(node) { } function isUseIdentifier(node) { - switch (node.type) { - case 'Identifier': - return node.name === 'use'; - case 'MemberExpression': - return ( - (node.object.name === 'React' || node.object.name === 'react') && - node.property.name === 'use' - ); - default: - return false; - } + return isReactFunction(node, 'use'); } export default {