Skip to content

Commit eaed6b8

Browse files
committed
fixup! [New] Symmetric useState hook variable names
1 parent 19156ad commit eaed6b8

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

lib/rules/hook-use-state.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ module.exports = {
3232

3333
create: Components.detect((context, components) => ({
3434
CallExpression(node) {
35+
const isImmediateReturn = node.parent
36+
&& node.parent.type === 'ReturnStatement';
37+
38+
if (isImmediateReturn) {
39+
return;
40+
}
41+
3542
const defaultReactImport = components.getDefaultReactImport();
3643
const namedReactImports = components.getNamedReactImports();
3744
const defaultReactImportName = defaultReactImport
@@ -64,15 +71,9 @@ module.exports = {
6471
return;
6572
}
6673

67-
const isImmediateReturn = node.parent && node.parent.type === 'ReturnStatement';
68-
if (isImmediateReturn) {
69-
return;
70-
}
71-
72-
const isDestructuringDeclarator = (
73-
node.parent.type === 'VariableDeclarator'
74-
&& node.parent.id.type === 'ArrayPattern'
75-
);
74+
const isDestructuringDeclarator = node.parent
75+
&& node.parent.type === 'VariableDeclarator'
76+
&& node.parent.id.type === 'ArrayPattern';
7677

7778
if (!isDestructuringDeclarator) {
7879
report(
@@ -100,12 +101,12 @@ module.exports = {
100101
`set${valueVariableName.charAt(0).toUpperCase()}${valueVariableName.slice(1)}`
101102
) : undefined;
102103

103-
if (
104-
!valueVariable
105-
|| !setterVariable
106-
|| setterVariableName !== expectedSetterVariableName
107-
|| variableNodes.length !== 2
108-
) {
104+
const isSymmetricGetterSetterPair = valueVariable
105+
&& setterVariable
106+
&& setterVariableName === expectedSetterVariableName
107+
&& variableNodes.length === 2;
108+
109+
if (!isSymmetricGetterSetterPair) {
109110
report(
110111
context,
111112
messages.useStateErrorMessage,

0 commit comments

Comments
 (0)