eslint-plugin-react-hooks-extra 1.5.29-beta.2 → 1.5.29-beta.3
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 +19 -21
- package/dist/index.mjs +20 -22
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var astUtils = require('@typescript-eslint/utils/ast-utils');
|
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
11
|
var name = "eslint-plugin-react-hooks-extra";
|
|
12
|
-
var version = "1.5.29-beta.
|
|
12
|
+
var version = "1.5.29-beta.3";
|
|
13
13
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
14
14
|
|
|
15
15
|
// src/rules/ensure-custom-hooks-using-other-hooks.ts
|
|
@@ -402,8 +402,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
402
402
|
},
|
|
403
403
|
name: RULE_NAME4,
|
|
404
404
|
create(context) {
|
|
405
|
-
const settings = shared.parseESLintSettings(context.settings)["react-x"];
|
|
406
|
-
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings
|
|
405
|
+
const settings = shared.parseESLintSettings(context.settings)["react-x"] ?? {};
|
|
406
|
+
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
407
407
|
function isUseEffectCallWithAlias(node) {
|
|
408
408
|
return core.isUseEffectCall(node, context) || useEffectAlias.some(tools.F.flip(core.isReactHookCallWithNameLoose)(node));
|
|
409
409
|
}
|
|
@@ -468,8 +468,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
468
468
|
}
|
|
469
469
|
const functionStack = tools.MutList.make();
|
|
470
470
|
const effectFunctionRef = tools.MutRef.make(null);
|
|
471
|
-
const effectFunctionIdentifiers =
|
|
472
|
-
const indirectFunctionCalls =
|
|
471
|
+
const effectFunctionIdentifiers = [];
|
|
472
|
+
const indirectFunctionCalls = [];
|
|
473
473
|
const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
|
|
474
474
|
const onEffectFunctionEnter = (node) => {
|
|
475
475
|
tools.MutRef.set(effectFunctionRef, node);
|
|
@@ -497,8 +497,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
497
497
|
$(callKind).with("setState", () => {
|
|
498
498
|
if (!parentFn) return;
|
|
499
499
|
if (parentFn !== effectFn && parentFnKind !== "immediate") {
|
|
500
|
-
const calls = indirectSetStateCalls.get(parentFn) ??
|
|
501
|
-
indirectSetStateCalls.set(parentFn,
|
|
500
|
+
const calls = indirectSetStateCalls.get(parentFn) ?? [];
|
|
501
|
+
indirectSetStateCalls.set(parentFn, [...calls, node]);
|
|
502
502
|
return;
|
|
503
503
|
}
|
|
504
504
|
context.report({
|
|
@@ -508,11 +508,11 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
508
508
|
}).with("useEffect", () => {
|
|
509
509
|
if (node.arguments.every(ast.isFunction)) return;
|
|
510
510
|
const identifiers = ast.getNestedIdentifiers(node);
|
|
511
|
-
|
|
511
|
+
effectFunctionIdentifiers.push(...identifiers);
|
|
512
512
|
}).with("other", () => {
|
|
513
513
|
const isInEffectFunction = effectFn === parentFn;
|
|
514
514
|
if (!isInEffectFunction) return;
|
|
515
|
-
|
|
515
|
+
indirectFunctionCalls.push(node);
|
|
516
516
|
}).otherwise(tools.F.constVoid);
|
|
517
517
|
},
|
|
518
518
|
"Program:exit"() {
|
|
@@ -522,11 +522,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
522
522
|
tools.O.flatMap(_var.getVariableNode(0)),
|
|
523
523
|
tools.O.filter(ast.isFunction),
|
|
524
524
|
tools.O.flatMapNullable((fn) => indirectSetStateCalls.get(fn)),
|
|
525
|
-
tools.O.map(tools.Chunk.toReadonlyArray),
|
|
526
525
|
tools.O.getOrElse(() => [])
|
|
527
526
|
);
|
|
528
527
|
};
|
|
529
|
-
for (const { callee } of
|
|
528
|
+
for (const { callee } of indirectFunctionCalls) {
|
|
530
529
|
if (!("name" in callee)) continue;
|
|
531
530
|
const { name: name2 } = callee;
|
|
532
531
|
const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
|
|
@@ -538,7 +537,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
538
537
|
});
|
|
539
538
|
}
|
|
540
539
|
}
|
|
541
|
-
for (const id of
|
|
540
|
+
for (const id of effectFunctionIdentifiers) {
|
|
542
541
|
const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
|
|
543
542
|
for (const setStateCall of setStateCalls) {
|
|
544
543
|
context.report({
|
|
@@ -633,8 +632,8 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
633
632
|
}
|
|
634
633
|
const functionStack = tools.MutList.make();
|
|
635
634
|
const effectFunctionRef = tools.MutRef.make(null);
|
|
636
|
-
const effectFunctionIdentifiers =
|
|
637
|
-
const indirectFunctionCalls =
|
|
635
|
+
const effectFunctionIdentifiers = [];
|
|
636
|
+
const indirectFunctionCalls = [];
|
|
638
637
|
const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
|
|
639
638
|
const onEffectFunctionEnter = (node) => {
|
|
640
639
|
tools.MutRef.set(effectFunctionRef, node);
|
|
@@ -662,8 +661,8 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
662
661
|
$(callKind).with("setState", () => {
|
|
663
662
|
if (!parentFn) return;
|
|
664
663
|
if (parentFn !== effectFn && parentFnKind !== "immediate") {
|
|
665
|
-
const calls = indirectSetStateCalls.get(parentFn) ??
|
|
666
|
-
indirectSetStateCalls.set(parentFn,
|
|
664
|
+
const calls = indirectSetStateCalls.get(parentFn) ?? [];
|
|
665
|
+
indirectSetStateCalls.set(parentFn, [...calls, node]);
|
|
667
666
|
return;
|
|
668
667
|
}
|
|
669
668
|
context.report({
|
|
@@ -673,11 +672,11 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
673
672
|
}).with("useLayoutEffect", () => {
|
|
674
673
|
if (node.arguments.every(ast.isFunction)) return;
|
|
675
674
|
const identifiers = ast.getNestedIdentifiers(node);
|
|
676
|
-
|
|
675
|
+
effectFunctionIdentifiers.push(...identifiers);
|
|
677
676
|
}).with("other", () => {
|
|
678
677
|
const isInEffectFunction = effectFn === parentFn;
|
|
679
678
|
if (!isInEffectFunction) return;
|
|
680
|
-
|
|
679
|
+
indirectFunctionCalls.push(node);
|
|
681
680
|
}).otherwise(tools.F.constVoid);
|
|
682
681
|
},
|
|
683
682
|
"Program:exit"() {
|
|
@@ -687,11 +686,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
687
686
|
tools.O.flatMap(_var.getVariableNode(0)),
|
|
688
687
|
tools.O.filter(ast.isFunction),
|
|
689
688
|
tools.O.flatMapNullable((fn) => indirectSetStateCalls.get(fn)),
|
|
690
|
-
tools.O.map(tools.Chunk.toReadonlyArray),
|
|
691
689
|
tools.O.getOrElse(() => [])
|
|
692
690
|
);
|
|
693
691
|
};
|
|
694
|
-
for (const { callee } of
|
|
692
|
+
for (const { callee } of indirectFunctionCalls) {
|
|
695
693
|
if (!("name" in callee)) continue;
|
|
696
694
|
const { name: name2 } = callee;
|
|
697
695
|
const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
|
|
@@ -703,7 +701,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
703
701
|
});
|
|
704
702
|
}
|
|
705
703
|
}
|
|
706
|
-
for (const id of
|
|
704
|
+
for (const id of effectFunctionIdentifiers) {
|
|
707
705
|
const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
|
|
708
706
|
for (const setStateCall of setStateCalls) {
|
|
709
707
|
context.report({
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useHookCollector, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, isUseStateCall, isUseEffectCall, isUseLayoutEffectCall } from '@eslint-react/core';
|
|
2
2
|
import { createRuleForPlugin, parseESLintSettings } from '@eslint-react/shared';
|
|
3
3
|
import { isFunction, NodeType, is, getNestedIdentifiers, getNestedCallExpressions, isIIFE } from '@eslint-react/ast';
|
|
4
|
-
import { F, O, MutList, MutRef
|
|
4
|
+
import { F, O, MutList, MutRef } from '@eslint-react/tools';
|
|
5
5
|
import { findVariable, getVariableNode } from '@eslint-react/var';
|
|
6
6
|
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
7
7
|
|
|
8
8
|
// package.json
|
|
9
9
|
var name = "eslint-plugin-react-hooks-extra";
|
|
10
|
-
var version = "1.5.29-beta.
|
|
10
|
+
var version = "1.5.29-beta.3";
|
|
11
11
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
12
12
|
|
|
13
13
|
// src/rules/ensure-custom-hooks-using-other-hooks.ts
|
|
@@ -400,8 +400,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
400
400
|
},
|
|
401
401
|
name: RULE_NAME4,
|
|
402
402
|
create(context) {
|
|
403
|
-
const settings = parseESLintSettings(context.settings)["react-x"];
|
|
404
|
-
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings
|
|
403
|
+
const settings = parseESLintSettings(context.settings)["react-x"] ?? {};
|
|
404
|
+
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
405
405
|
function isUseEffectCallWithAlias(node) {
|
|
406
406
|
return isUseEffectCall(node, context) || useEffectAlias.some(F.flip(isReactHookCallWithNameLoose)(node));
|
|
407
407
|
}
|
|
@@ -466,8 +466,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
466
466
|
}
|
|
467
467
|
const functionStack = MutList.make();
|
|
468
468
|
const effectFunctionRef = MutRef.make(null);
|
|
469
|
-
const effectFunctionIdentifiers =
|
|
470
|
-
const indirectFunctionCalls =
|
|
469
|
+
const effectFunctionIdentifiers = [];
|
|
470
|
+
const indirectFunctionCalls = [];
|
|
471
471
|
const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
|
|
472
472
|
const onEffectFunctionEnter = (node) => {
|
|
473
473
|
MutRef.set(effectFunctionRef, node);
|
|
@@ -495,8 +495,8 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
495
495
|
$(callKind).with("setState", () => {
|
|
496
496
|
if (!parentFn) return;
|
|
497
497
|
if (parentFn !== effectFn && parentFnKind !== "immediate") {
|
|
498
|
-
const calls = indirectSetStateCalls.get(parentFn) ??
|
|
499
|
-
indirectSetStateCalls.set(parentFn,
|
|
498
|
+
const calls = indirectSetStateCalls.get(parentFn) ?? [];
|
|
499
|
+
indirectSetStateCalls.set(parentFn, [...calls, node]);
|
|
500
500
|
return;
|
|
501
501
|
}
|
|
502
502
|
context.report({
|
|
@@ -506,11 +506,11 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
506
506
|
}).with("useEffect", () => {
|
|
507
507
|
if (node.arguments.every(isFunction)) return;
|
|
508
508
|
const identifiers = getNestedIdentifiers(node);
|
|
509
|
-
|
|
509
|
+
effectFunctionIdentifiers.push(...identifiers);
|
|
510
510
|
}).with("other", () => {
|
|
511
511
|
const isInEffectFunction = effectFn === parentFn;
|
|
512
512
|
if (!isInEffectFunction) return;
|
|
513
|
-
|
|
513
|
+
indirectFunctionCalls.push(node);
|
|
514
514
|
}).otherwise(F.constVoid);
|
|
515
515
|
},
|
|
516
516
|
"Program:exit"() {
|
|
@@ -520,11 +520,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
520
520
|
O.flatMap(getVariableNode(0)),
|
|
521
521
|
O.filter(isFunction),
|
|
522
522
|
O.flatMapNullable((fn) => indirectSetStateCalls.get(fn)),
|
|
523
|
-
O.map(Chunk.toReadonlyArray),
|
|
524
523
|
O.getOrElse(() => [])
|
|
525
524
|
);
|
|
526
525
|
};
|
|
527
|
-
for (const { callee } of
|
|
526
|
+
for (const { callee } of indirectFunctionCalls) {
|
|
528
527
|
if (!("name" in callee)) continue;
|
|
529
528
|
const { name: name2 } = callee;
|
|
530
529
|
const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
|
|
@@ -536,7 +535,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
536
535
|
});
|
|
537
536
|
}
|
|
538
537
|
}
|
|
539
|
-
for (const id of
|
|
538
|
+
for (const id of effectFunctionIdentifiers) {
|
|
540
539
|
const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
|
|
541
540
|
for (const setStateCall of setStateCalls) {
|
|
542
541
|
context.report({
|
|
@@ -631,8 +630,8 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
631
630
|
}
|
|
632
631
|
const functionStack = MutList.make();
|
|
633
632
|
const effectFunctionRef = MutRef.make(null);
|
|
634
|
-
const effectFunctionIdentifiers =
|
|
635
|
-
const indirectFunctionCalls =
|
|
633
|
+
const effectFunctionIdentifiers = [];
|
|
634
|
+
const indirectFunctionCalls = [];
|
|
636
635
|
const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
|
|
637
636
|
const onEffectFunctionEnter = (node) => {
|
|
638
637
|
MutRef.set(effectFunctionRef, node);
|
|
@@ -660,8 +659,8 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
660
659
|
$(callKind).with("setState", () => {
|
|
661
660
|
if (!parentFn) return;
|
|
662
661
|
if (parentFn !== effectFn && parentFnKind !== "immediate") {
|
|
663
|
-
const calls = indirectSetStateCalls.get(parentFn) ??
|
|
664
|
-
indirectSetStateCalls.set(parentFn,
|
|
662
|
+
const calls = indirectSetStateCalls.get(parentFn) ?? [];
|
|
663
|
+
indirectSetStateCalls.set(parentFn, [...calls, node]);
|
|
665
664
|
return;
|
|
666
665
|
}
|
|
667
666
|
context.report({
|
|
@@ -671,11 +670,11 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
671
670
|
}).with("useLayoutEffect", () => {
|
|
672
671
|
if (node.arguments.every(isFunction)) return;
|
|
673
672
|
const identifiers = getNestedIdentifiers(node);
|
|
674
|
-
|
|
673
|
+
effectFunctionIdentifiers.push(...identifiers);
|
|
675
674
|
}).with("other", () => {
|
|
676
675
|
const isInEffectFunction = effectFn === parentFn;
|
|
677
676
|
if (!isInEffectFunction) return;
|
|
678
|
-
|
|
677
|
+
indirectFunctionCalls.push(node);
|
|
679
678
|
}).otherwise(F.constVoid);
|
|
680
679
|
},
|
|
681
680
|
"Program:exit"() {
|
|
@@ -685,11 +684,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
685
684
|
O.flatMap(getVariableNode(0)),
|
|
686
685
|
O.filter(isFunction),
|
|
687
686
|
O.flatMapNullable((fn) => indirectSetStateCalls.get(fn)),
|
|
688
|
-
O.map(Chunk.toReadonlyArray),
|
|
689
687
|
O.getOrElse(() => [])
|
|
690
688
|
);
|
|
691
689
|
};
|
|
692
|
-
for (const { callee } of
|
|
690
|
+
for (const { callee } of indirectFunctionCalls) {
|
|
693
691
|
if (!("name" in callee)) continue;
|
|
694
692
|
const { name: name2 } = callee;
|
|
695
693
|
const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
|
|
@@ -701,7 +699,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
701
699
|
});
|
|
702
700
|
}
|
|
703
701
|
}
|
|
704
|
-
for (const id of
|
|
702
|
+
for (const id of effectFunctionIdentifiers) {
|
|
705
703
|
const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
|
|
706
704
|
for (const setStateCall of setStateCalls) {
|
|
707
705
|
context.report({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.5.29-beta.
|
|
3
|
+
"version": "1.5.29-beta.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"@typescript-eslint/type-utils": "^7.16.1 || ^rc-v8",
|
|
40
40
|
"@typescript-eslint/types": "^7.16.1 || ^rc-v8",
|
|
41
41
|
"@typescript-eslint/utils": "^7.16.1 || ^rc-v8",
|
|
42
|
-
"@eslint-react/
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/shared": "1.5.29-beta.
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
42
|
+
"@eslint-react/core": "1.5.29-beta.3",
|
|
43
|
+
"@eslint-react/tools": "1.5.29-beta.3",
|
|
44
|
+
"@eslint-react/ast": "1.5.29-beta.3",
|
|
45
|
+
"@eslint-react/shared": "1.5.29-beta.3",
|
|
46
|
+
"@eslint-react/types": "1.5.29-beta.3",
|
|
47
|
+
"@eslint-react/var": "1.5.29-beta.3",
|
|
48
|
+
"@eslint-react/jsx": "1.5.29-beta.3"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"string-ts": "2.2.0",
|