Skip to content

Commit

Permalink
fixup! [New] Symmetric useState hook variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanbeevers committed Nov 26, 2021
1 parent e7ad6d2 commit 0f13a4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
39 changes: 3 additions & 36 deletions lib/rules/hook-use-state.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
// },
// };
// }),
};
2 changes: 1 addition & 1 deletion tests/lib/rules/hook-use-state.js
Expand Up @@ -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]
Expand Down

0 comments on commit 0f13a4e

Please sign in to comment.