eslint-plugin-react-hooks-extra 1.28.0-beta.1 → 1.28.0-beta.6
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 +22 -19
- package/dist/index.mjs +22 -19
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -50,16 +50,16 @@ var rules = {
|
|
|
50
50
|
|
|
51
51
|
// package.json
|
|
52
52
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
53
|
-
var version = "1.28.0-beta.
|
|
53
|
+
var version = "1.28.0-beta.6";
|
|
54
54
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
55
|
-
function isFromHookCall(
|
|
55
|
+
function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
|
|
56
56
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
57
57
|
return (topLevelId) => {
|
|
58
58
|
const variable = VAR5__namespace.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
|
|
59
59
|
const variableNode = VAR5__namespace.getVariableNode(variable, 0);
|
|
60
60
|
if (variableNode == null) return false;
|
|
61
61
|
if (variableNode.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
62
|
-
if (!core.isReactHookCallWithNameAlias(
|
|
62
|
+
if (!core.isReactHookCallWithNameAlias(context, name3, hookAlias)(variableNode)) return false;
|
|
63
63
|
return predicate(topLevelId, variableNode);
|
|
64
64
|
};
|
|
65
65
|
}
|
|
@@ -71,7 +71,10 @@ function isFromUseStateCall(context, settings) {
|
|
|
71
71
|
}
|
|
72
72
|
return parent.id.elements.findIndex((e) => e?.type === types.AST_NODE_TYPES.Identifier && e.name === topLevelId.name) === 1;
|
|
73
73
|
};
|
|
74
|
-
return isFromHookCall("useState",
|
|
74
|
+
return isFromHookCall(context, "useState", settings, predicate);
|
|
75
|
+
}
|
|
76
|
+
function isFunctionOfImmediatelyInvoked(node) {
|
|
77
|
+
return node.type !== types.AST_NODE_TYPES.FunctionDeclaration && node.parent.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
75
78
|
}
|
|
76
79
|
function isSetFunctionCall(context, settings) {
|
|
77
80
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
@@ -173,10 +176,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
173
176
|
}
|
|
174
177
|
const settings = shared.getSettingsFromContext(context);
|
|
175
178
|
const additionalHooks = settings.additionalHooks;
|
|
176
|
-
const isUseEffectLikeCall = core.isReactHookCallWithNameAlias("useEffect",
|
|
177
|
-
const isUseStateCall2 = core.isReactHookCallWithNameAlias("useState",
|
|
178
|
-
const isUseMemoCall2 = core.isReactHookCallWithNameAlias("useMemo",
|
|
179
|
-
const isUseCallbackCall2 = core.isReactHookCallWithNameAlias("useCallback",
|
|
179
|
+
const isUseEffectLikeCall = core.isReactHookCallWithNameAlias(context, "useEffect", additionalHooks.useEffect ?? []);
|
|
180
|
+
const isUseStateCall2 = core.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState ?? []);
|
|
181
|
+
const isUseMemoCall2 = core.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo ?? []);
|
|
182
|
+
const isUseCallbackCall2 = core.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback ?? []);
|
|
180
183
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
181
184
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
182
185
|
const functionEntries = [];
|
|
@@ -202,7 +205,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
202
205
|
return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
203
206
|
}
|
|
204
207
|
function getFunctionKind(node) {
|
|
205
|
-
return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(
|
|
208
|
+
return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
206
209
|
}
|
|
207
210
|
return {
|
|
208
211
|
":function"(node) {
|
|
@@ -369,13 +372,13 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
369
372
|
const settings = shared.getSettingsFromContext(context);
|
|
370
373
|
const additionalHooks = settings.additionalHooks;
|
|
371
374
|
const isUseLayoutEffectLikeCall = core.isReactHookCallWithNameAlias(
|
|
372
|
-
"useLayoutEffect",
|
|
373
375
|
context,
|
|
376
|
+
"useLayoutEffect",
|
|
374
377
|
additionalHooks.useLayoutEffect ?? []
|
|
375
378
|
);
|
|
376
|
-
const isUseStateCall2 = core.isReactHookCallWithNameAlias("useState",
|
|
377
|
-
const isUseMemoCall2 = core.isReactHookCallWithNameAlias("useMemo",
|
|
378
|
-
const isUseCallbackCall2 = core.isReactHookCallWithNameAlias("useCallback",
|
|
379
|
+
const isUseStateCall2 = core.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState ?? []);
|
|
380
|
+
const isUseMemoCall2 = core.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo ?? []);
|
|
381
|
+
const isUseCallbackCall2 = core.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback ?? []);
|
|
379
382
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
380
383
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
381
384
|
const functionEntries = [];
|
|
@@ -401,7 +404,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
401
404
|
return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
402
405
|
}
|
|
403
406
|
function getFunctionKind(node) {
|
|
404
|
-
return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(
|
|
407
|
+
return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
405
408
|
}
|
|
406
409
|
return {
|
|
407
410
|
":function"(node) {
|
|
@@ -572,7 +575,7 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
572
575
|
return;
|
|
573
576
|
}
|
|
574
577
|
const initialScope = context.sourceCode.getScope(node);
|
|
575
|
-
if (!core.isUseCallbackCall(
|
|
578
|
+
if (!core.isUseCallbackCall(context, node) && !alias.some(core.isReactHookCallWithNameLoose(node))) {
|
|
576
579
|
return;
|
|
577
580
|
}
|
|
578
581
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -651,7 +654,7 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
651
654
|
return;
|
|
652
655
|
}
|
|
653
656
|
const initialScope = context.sourceCode.getScope(node);
|
|
654
|
-
if (!core.isUseMemoCall(
|
|
657
|
+
if (!core.isUseMemoCall(context, node) && !alias.some(core.isReactHookCallWithNameLoose(node))) {
|
|
655
658
|
return;
|
|
656
659
|
}
|
|
657
660
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -710,7 +713,7 @@ var RULE_NAME5 = "no-useless-custom-hooks";
|
|
|
710
713
|
var RULE_FEATURES5 = [
|
|
711
714
|
"CHK"
|
|
712
715
|
];
|
|
713
|
-
function isNodeContainsUseCallComments(
|
|
716
|
+
function isNodeContainsUseCallComments(context, node) {
|
|
714
717
|
return context.sourceCode.getCommentsInside(node).some((comment) => /use\w+\(/u.test(comment.value));
|
|
715
718
|
}
|
|
716
719
|
var no_useless_custom_hooks_default = createRule({
|
|
@@ -739,7 +742,7 @@ var no_useless_custom_hooks_default = createRule({
|
|
|
739
742
|
if (hookCalls.length > 0) {
|
|
740
743
|
continue;
|
|
741
744
|
}
|
|
742
|
-
if (isNodeContainsUseCallComments(
|
|
745
|
+
if (isNodeContainsUseCallComments(context, node2)) {
|
|
743
746
|
continue;
|
|
744
747
|
}
|
|
745
748
|
context.report({
|
|
@@ -783,7 +786,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
783
786
|
if (!core.isReactHookCall(node)) {
|
|
784
787
|
return;
|
|
785
788
|
}
|
|
786
|
-
if (!core.isUseStateCall(
|
|
789
|
+
if (!core.isUseStateCall(context, node) && !alias.some(core.isReactHookCallWithNameLoose(node))) {
|
|
787
790
|
return;
|
|
788
791
|
}
|
|
789
792
|
const [useStateInput] = node.arguments;
|
package/dist/index.mjs
CHANGED
|
@@ -27,16 +27,16 @@ var rules = {
|
|
|
27
27
|
|
|
28
28
|
// package.json
|
|
29
29
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
30
|
-
var version = "1.28.0-beta.
|
|
30
|
+
var version = "1.28.0-beta.6";
|
|
31
31
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
32
|
-
function isFromHookCall(
|
|
32
|
+
function isFromHookCall(context, name3, settings, predicate = constTrue) {
|
|
33
33
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
34
34
|
return (topLevelId) => {
|
|
35
35
|
const variable = VAR5.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
|
|
36
36
|
const variableNode = VAR5.getVariableNode(variable, 0);
|
|
37
37
|
if (variableNode == null) return false;
|
|
38
38
|
if (variableNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
39
|
-
if (!isReactHookCallWithNameAlias(
|
|
39
|
+
if (!isReactHookCallWithNameAlias(context, name3, hookAlias)(variableNode)) return false;
|
|
40
40
|
return predicate(topLevelId, variableNode);
|
|
41
41
|
};
|
|
42
42
|
}
|
|
@@ -48,7 +48,10 @@ function isFromUseStateCall(context, settings) {
|
|
|
48
48
|
}
|
|
49
49
|
return parent.id.elements.findIndex((e) => e?.type === AST_NODE_TYPES.Identifier && e.name === topLevelId.name) === 1;
|
|
50
50
|
};
|
|
51
|
-
return isFromHookCall("useState",
|
|
51
|
+
return isFromHookCall(context, "useState", settings, predicate);
|
|
52
|
+
}
|
|
53
|
+
function isFunctionOfImmediatelyInvoked(node) {
|
|
54
|
+
return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
|
|
52
55
|
}
|
|
53
56
|
function isSetFunctionCall(context, settings) {
|
|
54
57
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
@@ -150,10 +153,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
150
153
|
}
|
|
151
154
|
const settings = getSettingsFromContext(context);
|
|
152
155
|
const additionalHooks = settings.additionalHooks;
|
|
153
|
-
const isUseEffectLikeCall = isReactHookCallWithNameAlias("useEffect",
|
|
154
|
-
const isUseStateCall2 = isReactHookCallWithNameAlias("useState",
|
|
155
|
-
const isUseMemoCall2 = isReactHookCallWithNameAlias("useMemo",
|
|
156
|
-
const isUseCallbackCall2 = isReactHookCallWithNameAlias("useCallback",
|
|
156
|
+
const isUseEffectLikeCall = isReactHookCallWithNameAlias(context, "useEffect", additionalHooks.useEffect ?? []);
|
|
157
|
+
const isUseStateCall2 = isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState ?? []);
|
|
158
|
+
const isUseMemoCall2 = isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo ?? []);
|
|
159
|
+
const isUseCallbackCall2 = isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback ?? []);
|
|
157
160
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
158
161
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
159
162
|
const functionEntries = [];
|
|
@@ -179,7 +182,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
179
182
|
return match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
180
183
|
}
|
|
181
184
|
function getFunctionKind(node) {
|
|
182
|
-
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(
|
|
185
|
+
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
183
186
|
}
|
|
184
187
|
return {
|
|
185
188
|
":function"(node) {
|
|
@@ -346,13 +349,13 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
346
349
|
const settings = getSettingsFromContext(context);
|
|
347
350
|
const additionalHooks = settings.additionalHooks;
|
|
348
351
|
const isUseLayoutEffectLikeCall = isReactHookCallWithNameAlias(
|
|
349
|
-
"useLayoutEffect",
|
|
350
352
|
context,
|
|
353
|
+
"useLayoutEffect",
|
|
351
354
|
additionalHooks.useLayoutEffect ?? []
|
|
352
355
|
);
|
|
353
|
-
const isUseStateCall2 = isReactHookCallWithNameAlias("useState",
|
|
354
|
-
const isUseMemoCall2 = isReactHookCallWithNameAlias("useMemo",
|
|
355
|
-
const isUseCallbackCall2 = isReactHookCallWithNameAlias("useCallback",
|
|
356
|
+
const isUseStateCall2 = isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState ?? []);
|
|
357
|
+
const isUseMemoCall2 = isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo ?? []);
|
|
358
|
+
const isUseCallbackCall2 = isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback ?? []);
|
|
356
359
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
357
360
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
358
361
|
const functionEntries = [];
|
|
@@ -378,7 +381,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
378
381
|
return match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
379
382
|
}
|
|
380
383
|
function getFunctionKind(node) {
|
|
381
|
-
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(
|
|
384
|
+
return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
|
|
382
385
|
}
|
|
383
386
|
return {
|
|
384
387
|
":function"(node) {
|
|
@@ -549,7 +552,7 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
549
552
|
return;
|
|
550
553
|
}
|
|
551
554
|
const initialScope = context.sourceCode.getScope(node);
|
|
552
|
-
if (!isUseCallbackCall(
|
|
555
|
+
if (!isUseCallbackCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
553
556
|
return;
|
|
554
557
|
}
|
|
555
558
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -628,7 +631,7 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
628
631
|
return;
|
|
629
632
|
}
|
|
630
633
|
const initialScope = context.sourceCode.getScope(node);
|
|
631
|
-
if (!isUseMemoCall(
|
|
634
|
+
if (!isUseMemoCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
632
635
|
return;
|
|
633
636
|
}
|
|
634
637
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -687,7 +690,7 @@ var RULE_NAME5 = "no-useless-custom-hooks";
|
|
|
687
690
|
var RULE_FEATURES5 = [
|
|
688
691
|
"CHK"
|
|
689
692
|
];
|
|
690
|
-
function isNodeContainsUseCallComments(
|
|
693
|
+
function isNodeContainsUseCallComments(context, node) {
|
|
691
694
|
return context.sourceCode.getCommentsInside(node).some((comment) => /use\w+\(/u.test(comment.value));
|
|
692
695
|
}
|
|
693
696
|
var no_useless_custom_hooks_default = createRule({
|
|
@@ -716,7 +719,7 @@ var no_useless_custom_hooks_default = createRule({
|
|
|
716
719
|
if (hookCalls.length > 0) {
|
|
717
720
|
continue;
|
|
718
721
|
}
|
|
719
|
-
if (isNodeContainsUseCallComments(
|
|
722
|
+
if (isNodeContainsUseCallComments(context, node2)) {
|
|
720
723
|
continue;
|
|
721
724
|
}
|
|
722
725
|
context.report({
|
|
@@ -760,7 +763,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
760
763
|
if (!isReactHookCall(node)) {
|
|
761
764
|
return;
|
|
762
765
|
}
|
|
763
|
-
if (!isUseStateCall(
|
|
766
|
+
if (!isUseStateCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
764
767
|
return;
|
|
765
768
|
}
|
|
766
769
|
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.28.0-beta.
|
|
3
|
+
"version": "1.28.0-beta.6",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
"@typescript-eslint/utils": "^8.25.0",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.6.2",
|
|
53
|
-
"@eslint-react/ast": "1.28.0-beta.
|
|
54
|
-
"@eslint-react/core": "1.28.0-beta.
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/shared": "1.28.0-beta.
|
|
58
|
-
"@eslint-react/var": "1.28.0-beta.
|
|
53
|
+
"@eslint-react/ast": "1.28.0-beta.6",
|
|
54
|
+
"@eslint-react/core": "1.28.0-beta.6",
|
|
55
|
+
"@eslint-react/jsx": "1.28.0-beta.6",
|
|
56
|
+
"@eslint-react/eff": "1.28.0-beta.6",
|
|
57
|
+
"@eslint-react/shared": "1.28.0-beta.6",
|
|
58
|
+
"@eslint-react/var": "1.28.0-beta.6"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.0.10",
|
|
62
62
|
"@types/react-dom": "^19.0.4",
|
|
63
|
-
"tsup": "^8.
|
|
63
|
+
"tsup": "^8.4.0",
|
|
64
64
|
"@local/configs": "0.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|