diff --git a/lib/rules/hook-use-state.js b/lib/rules/hook-use-state.js index 772abb6961..e2edbb4c3f 100644 --- a/lib/rules/hook-use-state.js +++ b/lib/rules/hook-use-state.js @@ -33,8 +33,10 @@ module.exports = { create: Components.detect((context, components) => ({ CallExpression(node) { const defaultReactImport = components.getDefaultReactImport(); - const defaultReactImportName = defaultReactImport ? defaultReactImport.local.name : undefined; const namedReactImports = components.getNamedReactImports(); + const defaultReactImportName = defaultReactImport + ? defaultReactImport.local.name + : undefined; const useStateReactImportSpecifier = namedReactImports ? namedReactImports.find((specifier) => specifier.imported.name === 'useState') : undefined; @@ -119,39 +121,4 @@ module.exports = { } }, })), - // create: ReactImport.detect((context) => { - // // context.foo = 'foo'; - // // const result = WithReactImport((reactLocalName, context) => { - // // return { - // // CallExpression(node) { - - // // } - // // } - // // }) - // let reactImportLocalName; - // let reactUseStateLocalName; - - // return { - // // Program - - // ImportDeclaration(node) { - // const isReactImported = node.source.type === 'Literal' && node.source.value === 'react'; - // const reactDefaultSpecifier = node.specifiers.find((specifier) => specifier.type === 'ImportDefaultSpecifier'); - // reactImportLocalName = reactDefaultSpecifier ? reactDefaultSpecifier.local.name : undefined; - - // const reactUseStateSpecifier = isReactImported - // ? node.specifiers.find( - // (specifier) => ( - // specifier.type === 'ImportSpecifier' - // && specifier.imported.name === 'useState' - // ) - // ) - // : undefined; - - // reactUseStateLocalName = reactUseStateSpecifier - // ? reactUseStateSpecifier.local.name - // : undefined; - // }, - // }; - // }), }; diff --git a/tests/lib/rules/hook-use-state.js b/tests/lib/rules/hook-use-state.js index 761977bd0b..ce2baa665b 100644 --- a/tests/lib/rules/hook-use-state.js +++ b/tests/lib/rules/hook-use-state.js @@ -41,7 +41,7 @@ const tests = { }`, }, { - code: `import { useState } from 'react'; + code: `import React from 'react'; export default function useColor() { const [color, setColor] = React.useState() return [color, setColor]