Skip to content

Commit 0f13a4e

Browse files
committed
fixup! [New] Symmetric useState hook variable names
1 parent e7ad6d2 commit 0f13a4e

File tree

2 files changed

+4
-37
lines changed

2 files changed

+4
-37
lines changed

lib/rules/hook-use-state.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ module.exports = {
3333
create: Components.detect((context, components) => ({
3434
CallExpression(node) {
3535
const defaultReactImport = components.getDefaultReactImport();
36-
const defaultReactImportName = defaultReactImport ? defaultReactImport.local.name : undefined;
3736
const namedReactImports = components.getNamedReactImports();
37+
const defaultReactImportName = defaultReactImport
38+
? defaultReactImport.local.name
39+
: undefined;
3840
const useStateReactImportSpecifier = namedReactImports
3941
? namedReactImports.find((specifier) => specifier.imported.name === 'useState')
4042
: undefined;
@@ -119,39 +121,4 @@ module.exports = {
119121
}
120122
},
121123
})),
122-
// create: ReactImport.detect((context) => {
123-
// // context.foo = 'foo';
124-
// // const result = WithReactImport((reactLocalName, context) => {
125-
// // return {
126-
// // CallExpression(node) {
127-
128-
// // }
129-
// // }
130-
// // })
131-
// let reactImportLocalName;
132-
// let reactUseStateLocalName;
133-
134-
// return {
135-
// // Program
136-
137-
// ImportDeclaration(node) {
138-
// const isReactImported = node.source.type === 'Literal' && node.source.value === 'react';
139-
// const reactDefaultSpecifier = node.specifiers.find((specifier) => specifier.type === 'ImportDefaultSpecifier');
140-
// reactImportLocalName = reactDefaultSpecifier ? reactDefaultSpecifier.local.name : undefined;
141-
142-
// const reactUseStateSpecifier = isReactImported
143-
// ? node.specifiers.find(
144-
// (specifier) => (
145-
// specifier.type === 'ImportSpecifier'
146-
// && specifier.imported.name === 'useState'
147-
// )
148-
// )
149-
// : undefined;
150-
151-
// reactUseStateLocalName = reactUseStateSpecifier
152-
// ? reactUseStateSpecifier.local.name
153-
// : undefined;
154-
// },
155-
// };
156-
// }),
157124
};

tests/lib/rules/hook-use-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const tests = {
4141
}`,
4242
},
4343
{
44-
code: `import { useState } from 'react';
44+
code: `import React from 'react';
4545
export default function useColor() {
4646
const [color, setColor] = React.useState()
4747
return [color, setColor]

0 commit comments

Comments
 (0)