eslint-plugin-react-hooks-extra 1.47.1 → 1.47.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +15 -13
- package/dist/index.mjs +15 -13
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -52,7 +52,7 @@ var rules = {
|
|
|
52
52
|
|
|
53
53
|
// package.json
|
|
54
54
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
55
|
-
var version = "1.47.
|
|
55
|
+
var version = "1.47.2-beta.0";
|
|
56
56
|
var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("hooks-extra"));
|
|
57
57
|
function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
|
|
58
58
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
@@ -160,9 +160,9 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
160
160
|
const settings = shared.getSettingsFromContext(context);
|
|
161
161
|
const additionalHooks = settings.additionalHooks;
|
|
162
162
|
const isUseEffectLikeCall = ER7__namespace.isReactHookCallWithNameAlias(context, useEffectKind, additionalHooks[useEffectKind]);
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
163
|
+
const isUseStateCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState);
|
|
164
|
+
const isUseMemoCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo);
|
|
165
|
+
const isUseCallbackCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback);
|
|
166
166
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
167
167
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
168
168
|
const functionEntries = [];
|
|
@@ -185,7 +185,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
185
185
|
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
|
|
186
186
|
}
|
|
187
187
|
function getCallKind(node) {
|
|
188
|
-
return tsPattern.match(node).when(
|
|
188
|
+
return tsPattern.match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
189
189
|
}
|
|
190
190
|
function getFunctionKind(node) {
|
|
191
191
|
return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
@@ -247,7 +247,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
247
247
|
if (parent.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
248
248
|
break;
|
|
249
249
|
}
|
|
250
|
-
if (!
|
|
250
|
+
if (!isUseMemoCall(parent)) {
|
|
251
251
|
break;
|
|
252
252
|
}
|
|
253
253
|
const vd = AST__namespace.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
@@ -260,7 +260,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
260
260
|
if (node !== node.parent.arguments.at(0)) {
|
|
261
261
|
break;
|
|
262
262
|
}
|
|
263
|
-
if (
|
|
263
|
+
if (isUseCallbackCall(node.parent)) {
|
|
264
264
|
const vd = AST__namespace.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
265
265
|
if (vd != null) {
|
|
266
266
|
eff.getOrElseUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
@@ -399,13 +399,14 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
399
399
|
function create3(context) {
|
|
400
400
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
401
401
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
402
|
+
const isUseCallbackCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useCallback", alias);
|
|
402
403
|
return {
|
|
403
404
|
CallExpression(node) {
|
|
404
405
|
if (!ER7__namespace.isReactHookCall(node)) {
|
|
405
406
|
return;
|
|
406
407
|
}
|
|
407
408
|
const initialScope = context.sourceCode.getScope(node);
|
|
408
|
-
if (!
|
|
409
|
+
if (!isUseCallbackCall(node)) {
|
|
409
410
|
return;
|
|
410
411
|
}
|
|
411
412
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -477,13 +478,14 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
477
478
|
function create4(context) {
|
|
478
479
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
479
480
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
481
|
+
const isUseMemoCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useMemo", alias);
|
|
480
482
|
return {
|
|
481
483
|
CallExpression(node) {
|
|
482
484
|
if (!ER7__namespace.isReactHookCall(node)) {
|
|
483
485
|
return;
|
|
484
486
|
}
|
|
485
487
|
const initialScope = context.sourceCode.getScope(node);
|
|
486
|
-
if (!
|
|
488
|
+
if (!isUseMemoCall(node)) {
|
|
487
489
|
return;
|
|
488
490
|
}
|
|
489
491
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -563,7 +565,7 @@ function create5(context) {
|
|
|
563
565
|
...listeners,
|
|
564
566
|
"Program:exit"(program) {
|
|
565
567
|
const allHooks = ctx.getAllHooks(program);
|
|
566
|
-
for (const { name: name3, node, hookCalls } of allHooks.values()) {
|
|
568
|
+
for (const { id, name: name3, node, hookCalls } of allHooks.values()) {
|
|
567
569
|
if (AST__namespace.isEmptyFunction(node)) {
|
|
568
570
|
continue;
|
|
569
571
|
}
|
|
@@ -575,7 +577,7 @@ function create5(context) {
|
|
|
575
577
|
}
|
|
576
578
|
context.report({
|
|
577
579
|
messageId: "noUnnecessaryUsePrefix",
|
|
578
|
-
node,
|
|
580
|
+
node: id ?? node,
|
|
579
581
|
data: {
|
|
580
582
|
name: name3
|
|
581
583
|
}
|
|
@@ -610,14 +612,14 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
610
612
|
defaultOptions: []
|
|
611
613
|
});
|
|
612
614
|
function create6(context) {
|
|
613
|
-
if (!context.sourceCode.text.includes("use")) return {};
|
|
614
615
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
616
|
+
const isUseStateCall = ER7__namespace.isReactHookCallWithNameAlias(context, "useState", alias);
|
|
615
617
|
return {
|
|
616
618
|
CallExpression(node) {
|
|
617
619
|
if (!ER7__namespace.isReactHookCall(node)) {
|
|
618
620
|
return;
|
|
619
621
|
}
|
|
620
|
-
if (!
|
|
622
|
+
if (!isUseStateCall(node)) {
|
|
621
623
|
return;
|
|
622
624
|
}
|
|
623
625
|
const [useStateInput] = node.arguments;
|
package/dist/index.mjs
CHANGED
|
@@ -28,7 +28,7 @@ var rules = {
|
|
|
28
28
|
|
|
29
29
|
// package.json
|
|
30
30
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
31
|
-
var version = "1.47.
|
|
31
|
+
var version = "1.47.2-beta.0";
|
|
32
32
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("hooks-extra"));
|
|
33
33
|
function isFromHookCall(context, name3, settings, predicate = constTrue) {
|
|
34
34
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
@@ -136,9 +136,9 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
136
136
|
const settings = getSettingsFromContext(context);
|
|
137
137
|
const additionalHooks = settings.additionalHooks;
|
|
138
138
|
const isUseEffectLikeCall = ER7.isReactHookCallWithNameAlias(context, useEffectKind, additionalHooks[useEffectKind]);
|
|
139
|
-
const
|
|
140
|
-
const
|
|
141
|
-
const
|
|
139
|
+
const isUseStateCall = ER7.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState);
|
|
140
|
+
const isUseMemoCall = ER7.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo);
|
|
141
|
+
const isUseCallbackCall = ER7.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback);
|
|
142
142
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
143
143
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
144
144
|
const functionEntries = [];
|
|
@@ -161,7 +161,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
161
161
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
|
|
162
162
|
}
|
|
163
163
|
function getCallKind(node) {
|
|
164
|
-
return match(node).when(
|
|
164
|
+
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
165
165
|
}
|
|
166
166
|
function getFunctionKind(node) {
|
|
167
167
|
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
@@ -223,7 +223,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
223
223
|
if (parent.type !== AST_NODE_TYPES.CallExpression) {
|
|
224
224
|
break;
|
|
225
225
|
}
|
|
226
|
-
if (!
|
|
226
|
+
if (!isUseMemoCall(parent)) {
|
|
227
227
|
break;
|
|
228
228
|
}
|
|
229
229
|
const vd = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
@@ -236,7 +236,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
236
236
|
if (node !== node.parent.arguments.at(0)) {
|
|
237
237
|
break;
|
|
238
238
|
}
|
|
239
|
-
if (
|
|
239
|
+
if (isUseCallbackCall(node.parent)) {
|
|
240
240
|
const vd = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
241
241
|
if (vd != null) {
|
|
242
242
|
getOrElseUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
@@ -375,13 +375,14 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
375
375
|
function create3(context) {
|
|
376
376
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
377
377
|
const alias = getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
378
|
+
const isUseCallbackCall = ER7.isReactHookCallWithNameAlias(context, "useCallback", alias);
|
|
378
379
|
return {
|
|
379
380
|
CallExpression(node) {
|
|
380
381
|
if (!ER7.isReactHookCall(node)) {
|
|
381
382
|
return;
|
|
382
383
|
}
|
|
383
384
|
const initialScope = context.sourceCode.getScope(node);
|
|
384
|
-
if (!
|
|
385
|
+
if (!isUseCallbackCall(node)) {
|
|
385
386
|
return;
|
|
386
387
|
}
|
|
387
388
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -453,13 +454,14 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
453
454
|
function create4(context) {
|
|
454
455
|
if (!context.sourceCode.text.includes("use")) return {};
|
|
455
456
|
const alias = getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
457
|
+
const isUseMemoCall = ER7.isReactHookCallWithNameAlias(context, "useMemo", alias);
|
|
456
458
|
return {
|
|
457
459
|
CallExpression(node) {
|
|
458
460
|
if (!ER7.isReactHookCall(node)) {
|
|
459
461
|
return;
|
|
460
462
|
}
|
|
461
463
|
const initialScope = context.sourceCode.getScope(node);
|
|
462
|
-
if (!
|
|
464
|
+
if (!isUseMemoCall(node)) {
|
|
463
465
|
return;
|
|
464
466
|
}
|
|
465
467
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -539,7 +541,7 @@ function create5(context) {
|
|
|
539
541
|
...listeners,
|
|
540
542
|
"Program:exit"(program) {
|
|
541
543
|
const allHooks = ctx.getAllHooks(program);
|
|
542
|
-
for (const { name: name3, node, hookCalls } of allHooks.values()) {
|
|
544
|
+
for (const { id, name: name3, node, hookCalls } of allHooks.values()) {
|
|
543
545
|
if (AST.isEmptyFunction(node)) {
|
|
544
546
|
continue;
|
|
545
547
|
}
|
|
@@ -551,7 +553,7 @@ function create5(context) {
|
|
|
551
553
|
}
|
|
552
554
|
context.report({
|
|
553
555
|
messageId: "noUnnecessaryUsePrefix",
|
|
554
|
-
node,
|
|
556
|
+
node: id ?? node,
|
|
555
557
|
data: {
|
|
556
558
|
name: name3
|
|
557
559
|
}
|
|
@@ -586,14 +588,14 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
586
588
|
defaultOptions: []
|
|
587
589
|
});
|
|
588
590
|
function create6(context) {
|
|
589
|
-
if (!context.sourceCode.text.includes("use")) return {};
|
|
590
591
|
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
592
|
+
const isUseStateCall = ER7.isReactHookCallWithNameAlias(context, "useState", alias);
|
|
591
593
|
return {
|
|
592
594
|
CallExpression(node) {
|
|
593
595
|
if (!ER7.isReactHookCall(node)) {
|
|
594
596
|
return;
|
|
595
597
|
}
|
|
596
|
-
if (!
|
|
598
|
+
if (!isUseStateCall(node)) {
|
|
597
599
|
return;
|
|
598
600
|
}
|
|
599
601
|
const [useStateInput] = node.arguments;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.47.
|
|
3
|
+
"version": "1.47.2-beta.0",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,12 +50,12 @@
|
|
|
50
50
|
"@typescript-eslint/utils": "^8.29.1",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.7.0",
|
|
53
|
-
"@eslint-react/ast": "1.47.
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/kit": "1.47.
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
58
|
-
"@eslint-react/
|
|
53
|
+
"@eslint-react/ast": "1.47.2-beta.0",
|
|
54
|
+
"@eslint-react/core": "1.47.2-beta.0",
|
|
55
|
+
"@eslint-react/kit": "1.47.2-beta.0",
|
|
56
|
+
"@eslint-react/eff": "1.47.2-beta.0",
|
|
57
|
+
"@eslint-react/var": "1.47.2-beta.0",
|
|
58
|
+
"@eslint-react/shared": "1.47.2-beta.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.1.1",
|