eslint-plugin-react-hooks-extra 1.22.2 → 1.23.0-beta.1
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 +27 -45
- package/dist/index.mjs +27 -45
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var VAR5__namespace = /*#__PURE__*/_interopNamespace(VAR5);
|
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
33
|
var name = "eslint-plugin-react-hooks-extra";
|
|
34
|
-
var version = "1.
|
|
34
|
+
var version = "1.23.0-beta.1";
|
|
35
35
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
36
36
|
function isFromHookCall(name2, context, settings, predicate = eff.F.constTrue) {
|
|
37
37
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -503,16 +503,10 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
503
503
|
const scope = context.sourceCode.getScope(node);
|
|
504
504
|
const component = scope.block;
|
|
505
505
|
if (!AST2__namespace.isFunction(component)) return;
|
|
506
|
-
const [
|
|
507
|
-
if (!
|
|
508
|
-
context.report({
|
|
509
|
-
messageId: "noUnnecessaryUseCallback",
|
|
510
|
-
node
|
|
511
|
-
});
|
|
512
|
-
return;
|
|
513
|
-
}
|
|
506
|
+
const [arg0, arg1] = node.arguments;
|
|
507
|
+
if (!arg0 || !arg1) return;
|
|
514
508
|
const hasEmptyDeps = eff.F.pipe(
|
|
515
|
-
tsPattern.match(
|
|
509
|
+
tsPattern.match(arg1).with({ type: types.AST_NODE_TYPES.ArrayExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
516
510
|
return eff.F.pipe(
|
|
517
511
|
VAR5__namespace.findVariable(n.name, initialScope),
|
|
518
512
|
eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
@@ -522,15 +516,8 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
522
516
|
eff.O.exists((x) => x.elements.length === 0)
|
|
523
517
|
);
|
|
524
518
|
if (!hasEmptyDeps) return;
|
|
525
|
-
if (!cb) {
|
|
526
|
-
context.report({
|
|
527
|
-
messageId: "noUnnecessaryUseCallback",
|
|
528
|
-
node
|
|
529
|
-
});
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
519
|
const isReferencedToComponentScope = eff.F.pipe(
|
|
533
|
-
tsPattern.match(
|
|
520
|
+
tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
534
521
|
if (n.body.type === types.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
535
522
|
return eff.O.some(n.body);
|
|
536
523
|
}
|
|
@@ -546,11 +533,12 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
546
533
|
eff.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
|
|
547
534
|
eff.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
548
535
|
);
|
|
549
|
-
if (isReferencedToComponentScope)
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
536
|
+
if (!isReferencedToComponentScope) {
|
|
537
|
+
context.report({
|
|
538
|
+
messageId: "noUnnecessaryUseCallback",
|
|
539
|
+
node
|
|
540
|
+
});
|
|
541
|
+
}
|
|
554
542
|
}
|
|
555
543
|
};
|
|
556
544
|
},
|
|
@@ -584,16 +572,16 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
584
572
|
const scope = context.sourceCode.getScope(node);
|
|
585
573
|
const component = scope.block;
|
|
586
574
|
if (!AST2__namespace.isFunction(component)) return;
|
|
587
|
-
const [
|
|
588
|
-
if (!
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
575
|
+
const [arg0, arg1] = node.arguments;
|
|
576
|
+
if (!arg0 || !arg1) return;
|
|
577
|
+
const hasCallInArg0 = eff.F.pipe(
|
|
578
|
+
eff.O.some(arg0),
|
|
579
|
+
eff.O.filter((n) => AST2__namespace.isFunction(n)),
|
|
580
|
+
eff.O.exists((n) => [...AST2__namespace.getNestedCallExpressions(n.body), ...AST2__namespace.getNestedNewExpressions(n.body)].length > 0)
|
|
581
|
+
);
|
|
582
|
+
if (hasCallInArg0) return;
|
|
595
583
|
const hasEmptyDeps = eff.F.pipe(
|
|
596
|
-
tsPattern.match(
|
|
584
|
+
tsPattern.match(arg1).with({ type: types.AST_NODE_TYPES.ArrayExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
597
585
|
return eff.F.pipe(
|
|
598
586
|
VAR5__namespace.findVariable(n.name, initialScope),
|
|
599
587
|
eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
@@ -603,15 +591,8 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
603
591
|
eff.O.exists((x) => x.elements.length === 0)
|
|
604
592
|
);
|
|
605
593
|
if (!hasEmptyDeps) return;
|
|
606
|
-
if (!cb) {
|
|
607
|
-
context.report({
|
|
608
|
-
messageId: "noUnnecessaryUseMemo",
|
|
609
|
-
node
|
|
610
|
-
});
|
|
611
|
-
return;
|
|
612
|
-
}
|
|
613
594
|
const isReferencedToComponentScope = eff.F.pipe(
|
|
614
|
-
tsPattern.match(
|
|
595
|
+
tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
615
596
|
if (n.body.type === types.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
616
597
|
return eff.O.some(n.body);
|
|
617
598
|
}
|
|
@@ -627,11 +608,12 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
627
608
|
eff.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
|
|
628
609
|
eff.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
629
610
|
);
|
|
630
|
-
if (isReferencedToComponentScope)
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
611
|
+
if (!isReferencedToComponentScope) {
|
|
612
|
+
context.report({
|
|
613
|
+
messageId: "noUnnecessaryUseMemo",
|
|
614
|
+
node
|
|
615
|
+
});
|
|
616
|
+
}
|
|
635
617
|
}
|
|
636
618
|
};
|
|
637
619
|
},
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { match, isMatching } from 'ts-pattern';
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "eslint-plugin-react-hooks-extra";
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.23.0-beta.1";
|
|
12
12
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
13
13
|
function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
|
|
14
14
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -480,16 +480,10 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
480
480
|
const scope = context.sourceCode.getScope(node);
|
|
481
481
|
const component = scope.block;
|
|
482
482
|
if (!AST2.isFunction(component)) return;
|
|
483
|
-
const [
|
|
484
|
-
if (!
|
|
485
|
-
context.report({
|
|
486
|
-
messageId: "noUnnecessaryUseCallback",
|
|
487
|
-
node
|
|
488
|
-
});
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
483
|
+
const [arg0, arg1] = node.arguments;
|
|
484
|
+
if (!arg0 || !arg1) return;
|
|
491
485
|
const hasEmptyDeps = F.pipe(
|
|
492
|
-
match(
|
|
486
|
+
match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
493
487
|
return F.pipe(
|
|
494
488
|
VAR5.findVariable(n.name, initialScope),
|
|
495
489
|
O.flatMap(VAR5.getVariableNode(0)),
|
|
@@ -499,15 +493,8 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
499
493
|
O.exists((x) => x.elements.length === 0)
|
|
500
494
|
);
|
|
501
495
|
if (!hasEmptyDeps) return;
|
|
502
|
-
if (!cb) {
|
|
503
|
-
context.report({
|
|
504
|
-
messageId: "noUnnecessaryUseCallback",
|
|
505
|
-
node
|
|
506
|
-
});
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
496
|
const isReferencedToComponentScope = F.pipe(
|
|
510
|
-
match(
|
|
497
|
+
match(arg0).with({ type: AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
511
498
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
512
499
|
return O.some(n.body);
|
|
513
500
|
}
|
|
@@ -523,11 +510,12 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
523
510
|
O.map((s) => VAR5.getChidScopes(s).flatMap((x) => x.references)),
|
|
524
511
|
O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
525
512
|
);
|
|
526
|
-
if (isReferencedToComponentScope)
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
513
|
+
if (!isReferencedToComponentScope) {
|
|
514
|
+
context.report({
|
|
515
|
+
messageId: "noUnnecessaryUseCallback",
|
|
516
|
+
node
|
|
517
|
+
});
|
|
518
|
+
}
|
|
531
519
|
}
|
|
532
520
|
};
|
|
533
521
|
},
|
|
@@ -561,16 +549,16 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
561
549
|
const scope = context.sourceCode.getScope(node);
|
|
562
550
|
const component = scope.block;
|
|
563
551
|
if (!AST2.isFunction(component)) return;
|
|
564
|
-
const [
|
|
565
|
-
if (!
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
552
|
+
const [arg0, arg1] = node.arguments;
|
|
553
|
+
if (!arg0 || !arg1) return;
|
|
554
|
+
const hasCallInArg0 = F.pipe(
|
|
555
|
+
O.some(arg0),
|
|
556
|
+
O.filter((n) => AST2.isFunction(n)),
|
|
557
|
+
O.exists((n) => [...AST2.getNestedCallExpressions(n.body), ...AST2.getNestedNewExpressions(n.body)].length > 0)
|
|
558
|
+
);
|
|
559
|
+
if (hasCallInArg0) return;
|
|
572
560
|
const hasEmptyDeps = F.pipe(
|
|
573
|
-
match(
|
|
561
|
+
match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
574
562
|
return F.pipe(
|
|
575
563
|
VAR5.findVariable(n.name, initialScope),
|
|
576
564
|
O.flatMap(VAR5.getVariableNode(0)),
|
|
@@ -580,15 +568,8 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
580
568
|
O.exists((x) => x.elements.length === 0)
|
|
581
569
|
);
|
|
582
570
|
if (!hasEmptyDeps) return;
|
|
583
|
-
if (!cb) {
|
|
584
|
-
context.report({
|
|
585
|
-
messageId: "noUnnecessaryUseMemo",
|
|
586
|
-
node
|
|
587
|
-
});
|
|
588
|
-
return;
|
|
589
|
-
}
|
|
590
571
|
const isReferencedToComponentScope = F.pipe(
|
|
591
|
-
match(
|
|
572
|
+
match(arg0).with({ type: AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
592
573
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
593
574
|
return O.some(n.body);
|
|
594
575
|
}
|
|
@@ -604,11 +585,12 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
604
585
|
O.map((s) => VAR5.getChidScopes(s).flatMap((x) => x.references)),
|
|
605
586
|
O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
606
587
|
);
|
|
607
|
-
if (isReferencedToComponentScope)
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
588
|
+
if (!isReferencedToComponentScope) {
|
|
589
|
+
context.report({
|
|
590
|
+
messageId: "noUnnecessaryUseMemo",
|
|
591
|
+
node
|
|
592
|
+
});
|
|
593
|
+
}
|
|
612
594
|
}
|
|
613
595
|
};
|
|
614
596
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.23.0-beta.1",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,19 +42,19 @@
|
|
|
42
42
|
"./package.json"
|
|
43
43
|
],
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
46
|
-
"@typescript-eslint/type-utils": "^8.
|
|
47
|
-
"@typescript-eslint/types": "^8.
|
|
48
|
-
"@typescript-eslint/utils": "^8.
|
|
45
|
+
"@typescript-eslint/scope-manager": "^8.19.0",
|
|
46
|
+
"@typescript-eslint/type-utils": "^8.19.0",
|
|
47
|
+
"@typescript-eslint/types": "^8.19.0",
|
|
48
|
+
"@typescript-eslint/utils": "^8.19.0",
|
|
49
49
|
"string-ts": "^2.2.0",
|
|
50
50
|
"ts-pattern": "^5.6.0",
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/jsx": "1.
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
51
|
+
"@eslint-react/ast": "1.23.0-beta.1",
|
|
52
|
+
"@eslint-react/core": "1.23.0-beta.1",
|
|
53
|
+
"@eslint-react/shared": "1.23.0-beta.1",
|
|
54
|
+
"@eslint-react/jsx": "1.23.0-beta.1",
|
|
55
|
+
"@eslint-react/var": "1.23.0-beta.1",
|
|
56
|
+
"@eslint-react/eff": "1.23.0-beta.1",
|
|
57
|
+
"@eslint-react/types": "1.23.0-beta.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/react": "^19.0.2",
|