eslint-plugin-react-hooks-extra 1.17.4-beta.2 → 1.17.4-beta.7
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 -24
- package/dist/index.mjs +18 -23
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -4,10 +4,9 @@ var AST2 = require('@eslint-react/ast');
|
|
|
4
4
|
var core = require('@eslint-react/core');
|
|
5
5
|
var shared = require('@eslint-react/shared');
|
|
6
6
|
var tools = require('@eslint-react/tools');
|
|
7
|
-
var
|
|
7
|
+
var VAR5 = require('@eslint-react/var');
|
|
8
8
|
var types = require('@typescript-eslint/types');
|
|
9
9
|
var tsPattern = require('ts-pattern');
|
|
10
|
-
var astUtils = require('@typescript-eslint/utils/ast-utils');
|
|
11
10
|
|
|
12
11
|
function _interopNamespace(e) {
|
|
13
12
|
if (e && e.__esModule) return e;
|
|
@@ -28,17 +27,17 @@ function _interopNamespace(e) {
|
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
var AST2__namespace = /*#__PURE__*/_interopNamespace(AST2);
|
|
31
|
-
var
|
|
30
|
+
var VAR5__namespace = /*#__PURE__*/_interopNamespace(VAR5);
|
|
32
31
|
|
|
33
32
|
// package.json
|
|
34
33
|
var name = "eslint-plugin-react-hooks-extra";
|
|
35
|
-
var version = "1.17.4-beta.
|
|
34
|
+
var version = "1.17.4-beta.7";
|
|
36
35
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
37
36
|
function isFromHookCall(name2, context, settings, predicate = tools.F.constTrue) {
|
|
38
37
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
39
38
|
return (topLevelId) => tools.F.pipe(
|
|
40
|
-
|
|
41
|
-
tools.O.flatMap(
|
|
39
|
+
VAR5__namespace.findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
|
|
40
|
+
tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
42
41
|
tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.CallExpression)),
|
|
43
42
|
tools.O.filter(core.isReactHookCallWithNameAlias(name2, context, hookAlias)),
|
|
44
43
|
tools.O.exists((call) => predicate(topLevelId, call))
|
|
@@ -72,9 +71,7 @@ function isSetFunctionCall(context, settings) {
|
|
|
72
71
|
const [index] = node.callee.arguments;
|
|
73
72
|
if (!isAt || !index) return false;
|
|
74
73
|
const initialScope = context.sourceCode.getScope(node);
|
|
75
|
-
|
|
76
|
-
if (value?.value === 1) return isIdFromUseStateCall(callee.object);
|
|
77
|
-
return false;
|
|
74
|
+
return tools.O.exists(VAR5__namespace.getStaticValue(index, initialScope), (v) => v === 1) && isIdFromUseStateCall(callee.object);
|
|
78
75
|
}
|
|
79
76
|
// const [data, setData] = useState();
|
|
80
77
|
// setData();
|
|
@@ -86,9 +83,7 @@ function isSetFunctionCall(context, settings) {
|
|
|
86
83
|
case types.AST_NODE_TYPES.MemberExpression: {
|
|
87
84
|
if (!("name" in node.callee.object)) return false;
|
|
88
85
|
const initialScope = context.sourceCode.getScope(node);
|
|
89
|
-
|
|
90
|
-
if (property?.value === 1) return isIdFromUseStateCall(node.callee.object);
|
|
91
|
-
return false;
|
|
86
|
+
return tools.O.exists(VAR5__namespace.getStaticValue(node.callee.property, initialScope), (v) => v === 1) && isIdFromUseStateCall(node.callee.object);
|
|
92
87
|
}
|
|
93
88
|
default: {
|
|
94
89
|
return false;
|
|
@@ -240,7 +235,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
240
235
|
},
|
|
241
236
|
"Program:exit"() {
|
|
242
237
|
const getSetStateCalls = (id, initialScope) => {
|
|
243
|
-
const node = tools.O.flatMap(
|
|
238
|
+
const node = tools.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(tools.O.getOrNull);
|
|
244
239
|
switch (node?.type) {
|
|
245
240
|
case types.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
246
241
|
case types.AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -421,7 +416,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
421
416
|
},
|
|
422
417
|
"Program:exit"() {
|
|
423
418
|
const getSetStateCalls = (id, initialScope) => {
|
|
424
|
-
const node = tools.O.flatMap(
|
|
419
|
+
const node = tools.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(tools.O.getOrNull);
|
|
425
420
|
switch (node?.type) {
|
|
426
421
|
case types.AST_NODE_TYPES.ArrowFunctionExpression:
|
|
427
422
|
case types.AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -544,8 +539,8 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
544
539
|
const hasEmptyDeps = tools.F.pipe(
|
|
545
540
|
tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
546
541
|
return tools.F.pipe(
|
|
547
|
-
|
|
548
|
-
tools.O.flatMap(
|
|
542
|
+
VAR5__namespace.findVariable(n.name, initialScope),
|
|
543
|
+
tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
549
544
|
tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
|
|
550
545
|
);
|
|
551
546
|
}).otherwise(tools.O.none),
|
|
@@ -567,13 +562,13 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
567
562
|
return tools.O.some(n);
|
|
568
563
|
}).with({ type: types.AST_NODE_TYPES.FunctionExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
569
564
|
return tools.F.pipe(
|
|
570
|
-
|
|
571
|
-
tools.O.flatMap(
|
|
565
|
+
VAR5__namespace.findVariable(n.name, initialScope),
|
|
566
|
+
tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
572
567
|
tools.O.filter(AST2__namespace.isFunction)
|
|
573
568
|
);
|
|
574
569
|
}).otherwise(tools.O.none),
|
|
575
570
|
tools.O.map((n) => context.sourceCode.getScope(n)),
|
|
576
|
-
tools.O.map((s) =>
|
|
571
|
+
tools.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
|
|
577
572
|
tools.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
578
573
|
);
|
|
579
574
|
if (isReferencedToComponentScope) return;
|
|
@@ -623,8 +618,8 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
623
618
|
const hasEmptyDeps = tools.F.pipe(
|
|
624
619
|
tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
625
620
|
return tools.F.pipe(
|
|
626
|
-
|
|
627
|
-
tools.O.flatMap(
|
|
621
|
+
VAR5__namespace.findVariable(n.name, initialScope),
|
|
622
|
+
tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
628
623
|
tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
|
|
629
624
|
);
|
|
630
625
|
}).otherwise(tools.O.none),
|
|
@@ -646,13 +641,13 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
646
641
|
return tools.O.some(n);
|
|
647
642
|
}).with({ type: types.AST_NODE_TYPES.FunctionExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
648
643
|
return tools.F.pipe(
|
|
649
|
-
|
|
650
|
-
tools.O.flatMap(
|
|
644
|
+
VAR5__namespace.findVariable(n.name, initialScope),
|
|
645
|
+
tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
|
|
651
646
|
tools.O.filter(AST2__namespace.isFunction)
|
|
652
647
|
);
|
|
653
648
|
}).otherwise(tools.O.none),
|
|
654
649
|
tools.O.map((n) => context.sourceCode.getScope(n)),
|
|
655
|
-
tools.O.map((s) =>
|
|
650
|
+
tools.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
|
|
656
651
|
tools.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
657
652
|
);
|
|
658
653
|
if (isReferencedToComponentScope) return;
|
package/dist/index.mjs
CHANGED
|
@@ -2,20 +2,19 @@ import * as AST2 from '@eslint-react/ast';
|
|
|
2
2
|
import { isReactHookCallWithNameAlias, useHookCollector, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, isUseStateCall, isReactHookName } from '@eslint-react/core';
|
|
3
3
|
import { createRuleForPlugin, decodeSettings } from '@eslint-react/shared';
|
|
4
4
|
import { MutRef, O, F } from '@eslint-react/tools';
|
|
5
|
-
import * as
|
|
5
|
+
import * as VAR5 from '@eslint-react/var';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
7
7
|
import { match, isMatching } from 'ts-pattern';
|
|
8
|
-
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
9
8
|
|
|
10
9
|
// package.json
|
|
11
10
|
var name = "eslint-plugin-react-hooks-extra";
|
|
12
|
-
var version = "1.17.4-beta.
|
|
11
|
+
var version = "1.17.4-beta.7";
|
|
13
12
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
14
13
|
function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
|
|
15
14
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
16
15
|
return (topLevelId) => F.pipe(
|
|
17
|
-
|
|
18
|
-
O.flatMap(
|
|
16
|
+
VAR5.findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
|
|
17
|
+
O.flatMap(VAR5.getVariableNode(0)),
|
|
19
18
|
O.filter(AST2.is(AST_NODE_TYPES.CallExpression)),
|
|
20
19
|
O.filter(isReactHookCallWithNameAlias(name2, context, hookAlias)),
|
|
21
20
|
O.exists((call) => predicate(topLevelId, call))
|
|
@@ -49,9 +48,7 @@ function isSetFunctionCall(context, settings) {
|
|
|
49
48
|
const [index] = node.callee.arguments;
|
|
50
49
|
if (!isAt || !index) return false;
|
|
51
50
|
const initialScope = context.sourceCode.getScope(node);
|
|
52
|
-
|
|
53
|
-
if (value?.value === 1) return isIdFromUseStateCall(callee.object);
|
|
54
|
-
return false;
|
|
51
|
+
return O.exists(VAR5.getStaticValue(index, initialScope), (v) => v === 1) && isIdFromUseStateCall(callee.object);
|
|
55
52
|
}
|
|
56
53
|
// const [data, setData] = useState();
|
|
57
54
|
// setData();
|
|
@@ -63,9 +60,7 @@ function isSetFunctionCall(context, settings) {
|
|
|
63
60
|
case AST_NODE_TYPES.MemberExpression: {
|
|
64
61
|
if (!("name" in node.callee.object)) return false;
|
|
65
62
|
const initialScope = context.sourceCode.getScope(node);
|
|
66
|
-
|
|
67
|
-
if (property?.value === 1) return isIdFromUseStateCall(node.callee.object);
|
|
68
|
-
return false;
|
|
63
|
+
return O.exists(VAR5.getStaticValue(node.callee.property, initialScope), (v) => v === 1) && isIdFromUseStateCall(node.callee.object);
|
|
69
64
|
}
|
|
70
65
|
default: {
|
|
71
66
|
return false;
|
|
@@ -217,7 +212,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
217
212
|
},
|
|
218
213
|
"Program:exit"() {
|
|
219
214
|
const getSetStateCalls = (id, initialScope) => {
|
|
220
|
-
const node = O.flatMap(
|
|
215
|
+
const node = O.flatMap(VAR5.findVariable(id, initialScope), VAR5.getVariableNode(0)).pipe(O.getOrNull);
|
|
221
216
|
switch (node?.type) {
|
|
222
217
|
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
223
218
|
case AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -398,7 +393,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
398
393
|
},
|
|
399
394
|
"Program:exit"() {
|
|
400
395
|
const getSetStateCalls = (id, initialScope) => {
|
|
401
|
-
const node = O.flatMap(
|
|
396
|
+
const node = O.flatMap(VAR5.findVariable(id, initialScope), VAR5.getVariableNode(0)).pipe(O.getOrNull);
|
|
402
397
|
switch (node?.type) {
|
|
403
398
|
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
404
399
|
case AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -521,8 +516,8 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
521
516
|
const hasEmptyDeps = F.pipe(
|
|
522
517
|
match(deps).with({ type: AST_NODE_TYPES.ArrayExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
523
518
|
return F.pipe(
|
|
524
|
-
|
|
525
|
-
O.flatMap(
|
|
519
|
+
VAR5.findVariable(n.name, initialScope),
|
|
520
|
+
O.flatMap(VAR5.getVariableNode(0)),
|
|
526
521
|
O.filter(AST2.is(AST_NODE_TYPES.ArrayExpression))
|
|
527
522
|
);
|
|
528
523
|
}).otherwise(O.none),
|
|
@@ -544,13 +539,13 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
544
539
|
return O.some(n);
|
|
545
540
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
546
541
|
return F.pipe(
|
|
547
|
-
|
|
548
|
-
O.flatMap(
|
|
542
|
+
VAR5.findVariable(n.name, initialScope),
|
|
543
|
+
O.flatMap(VAR5.getVariableNode(0)),
|
|
549
544
|
O.filter(AST2.isFunction)
|
|
550
545
|
);
|
|
551
546
|
}).otherwise(O.none),
|
|
552
547
|
O.map((n) => context.sourceCode.getScope(n)),
|
|
553
|
-
O.map((s) =>
|
|
548
|
+
O.map((s) => VAR5.getChidScopes(s).flatMap((x) => x.references)),
|
|
554
549
|
O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
555
550
|
);
|
|
556
551
|
if (isReferencedToComponentScope) return;
|
|
@@ -600,8 +595,8 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
600
595
|
const hasEmptyDeps = F.pipe(
|
|
601
596
|
match(deps).with({ type: AST_NODE_TYPES.ArrayExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
602
597
|
return F.pipe(
|
|
603
|
-
|
|
604
|
-
O.flatMap(
|
|
598
|
+
VAR5.findVariable(n.name, initialScope),
|
|
599
|
+
O.flatMap(VAR5.getVariableNode(0)),
|
|
605
600
|
O.filter(AST2.is(AST_NODE_TYPES.ArrayExpression))
|
|
606
601
|
);
|
|
607
602
|
}).otherwise(O.none),
|
|
@@ -623,13 +618,13 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
623
618
|
return O.some(n);
|
|
624
619
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, O.some).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
625
620
|
return F.pipe(
|
|
626
|
-
|
|
627
|
-
O.flatMap(
|
|
621
|
+
VAR5.findVariable(n.name, initialScope),
|
|
622
|
+
O.flatMap(VAR5.getVariableNode(0)),
|
|
628
623
|
O.filter(AST2.isFunction)
|
|
629
624
|
);
|
|
630
625
|
}).otherwise(O.none),
|
|
631
626
|
O.map((n) => context.sourceCode.getScope(n)),
|
|
632
|
-
O.map((s) =>
|
|
627
|
+
O.map((s) => VAR5.getChidScopes(s).flatMap((x) => x.references)),
|
|
633
628
|
O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
|
|
634
629
|
);
|
|
635
630
|
if (isReferencedToComponentScope) return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.17.4-beta.
|
|
3
|
+
"version": "1.17.4-beta.7",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
"@typescript-eslint/types": "^8.17.0",
|
|
47
47
|
"@typescript-eslint/utils": "^8.17.0",
|
|
48
48
|
"ts-pattern": "^5.5.0",
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/types": "1.17.4-beta.
|
|
55
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/jsx": "1.17.4-beta.7",
|
|
50
|
+
"@eslint-react/core": "1.17.4-beta.7",
|
|
51
|
+
"@eslint-react/ast": "1.17.4-beta.7",
|
|
52
|
+
"@eslint-react/shared": "1.17.4-beta.7",
|
|
53
|
+
"@eslint-react/var": "1.17.4-beta.7",
|
|
54
|
+
"@eslint-react/types": "1.17.4-beta.7",
|
|
55
|
+
"@eslint-react/tools": "1.17.4-beta.7"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@types/react": "^18.3.
|
|
58
|
+
"@types/react": "^18.3.13",
|
|
59
59
|
"@types/react-dom": "^18.3.1",
|
|
60
60
|
"string-ts": "^2.2.0",
|
|
61
61
|
"tsup": "^8.3.5"
|