diff --git a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js index fd0ad9b046c20..260829d8ad083 100644 --- a/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js +++ b/packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js @@ -479,6 +479,45 @@ const tests = { } `, }, + { + code: normalizeIndent` + function App() { + const text = use(Promise.resolve('A')); + return + } + `, + }, + { + code: normalizeIndent` + function App() { + if (shouldShowText) { + const text = use(query); + return + } + return + } + `, + }, + { + code: normalizeIndent` + function App() { + let data = []; + for (const query of queries) { + const text = use(item); + data.push(text); + } + return + } + `, + }, + { + code: normalizeIndent` + function App() { + const data = someCallback((x) => use(x)); + return + } + `, + }, ], invalid: [ { @@ -1058,6 +1097,58 @@ const tests = { `, errors: [asyncComponentHookError('useState')], }, + { + code: normalizeIndent` + Hook.use(); + Hook._use(); + Hook.useState(); + Hook._useState(); + Hook.use42(); + Hook.useHook(); + Hook.use_hook(); + `, + errors: [ + topLevelError('Hook.use'), + topLevelError('Hook.useState'), + topLevelError('Hook.use42'), + topLevelError('Hook.useHook'), + ], + }, + { + code: normalizeIndent` + function notAComponent() { + use(promise); + } + `, + errors: [functionError('use', 'notAComponent')], + }, + { + code: normalizeIndent` + const text = use(promise); + function App() { + return + } + `, + errors: [topLevelError('use')], + }, + { + code: normalizeIndent` + class C { + m() { + use(promise); + } + } + `, + errors: [classError('use')], + }, + { + code: normalizeIndent` + async function AsyncComponent() { + use(); + } + `, + errors: [asyncComponentHookError('use')], + }, ], }; @@ -1159,45 +1250,6 @@ if (__EXPERIMENTAL__) { } `, }, - { - code: normalizeIndent` - function App() { - const text = use(Promise.resolve('A')); - return - } - `, - }, - { - code: normalizeIndent` - function App() { - if (shouldShowText) { - const text = use(query); - return - } - return - } - `, - }, - { - code: normalizeIndent` - function App() { - let data = []; - for (const query of queries) { - const text = use(item); - data.push(text); - } - return - } - `, - }, - { - code: normalizeIndent` - function App() { - const data = someCallback((x) => use(x)); - return - } - `, - }, ]; tests.invalid = [ ...tests.invalid, @@ -1272,58 +1324,6 @@ if (__EXPERIMENTAL__) { `, errors: [useEffectEventError('onClick')], }, - { - code: normalizeIndent` - Hook.use(); - Hook._use(); - Hook.useState(); - Hook._useState(); - Hook.use42(); - Hook.useHook(); - Hook.use_hook(); - `, - errors: [ - topLevelError('Hook.use'), - topLevelError('Hook.useState'), - topLevelError('Hook.use42'), - topLevelError('Hook.useHook'), - ], - }, - { - code: normalizeIndent` - function notAComponent() { - use(promise); - } - `, - errors: [functionError('use', 'notAComponent')], - }, - { - code: normalizeIndent` - const text = use(promise); - function App() { - return - } - `, - errors: [topLevelError('use')], - }, - { - code: normalizeIndent` - class C { - m() { - use(promise); - } - } - `, - errors: [classError('use')], - }, - { - code: normalizeIndent` - async function AsyncComponent() { - use(); - } - `, - errors: [asyncComponentHookError('use')], - }, ]; } diff --git a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js index 9818d18938310..660d92f9ea77c 100644 --- a/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js +++ b/packages/eslint-plugin-react-hooks/src/RulesOfHooks.js @@ -16,10 +16,7 @@ */ function isHookName(s) { - if (__EXPERIMENTAL__) { - return s === 'use' || /^use[A-Z0-9]/.test(s); - } - return /^use[A-Z0-9]/.test(s); + return s === 'use' || /^use[A-Z0-9]/.test(s); } /** @@ -111,10 +108,7 @@ function isUseEffectEventIdentifier(node) { } function isUseIdentifier(node) { - if (__EXPERIMENTAL__) { - return node.type === 'Identifier' && node.name === 'use'; - } - return false; + return node.type === 'Identifier' && node.name === 'use'; } export default {