eslint-plugin-react-hooks-extra 1.53.1-next.0 → 1.53.1-next.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 +30 -33
- package/dist/index.mjs +14 -25
- package/package.json +12 -12
package/dist/index.js
CHANGED
|
@@ -27,14 +27,22 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
}) : target, mod));
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
let __eslint_react_shared = require("@eslint-react/shared");
|
|
31
|
+
__eslint_react_shared = __toESM(__eslint_react_shared);
|
|
32
|
+
let __eslint_react_ast = require("@eslint-react/ast");
|
|
33
|
+
__eslint_react_ast = __toESM(__eslint_react_ast);
|
|
34
|
+
let __eslint_react_core = require("@eslint-react/core");
|
|
35
|
+
__eslint_react_core = __toESM(__eslint_react_core);
|
|
36
|
+
let __eslint_react_eff = require("@eslint-react/eff");
|
|
37
|
+
__eslint_react_eff = __toESM(__eslint_react_eff);
|
|
38
|
+
let __eslint_react_var = require("@eslint-react/var");
|
|
39
|
+
__eslint_react_var = __toESM(__eslint_react_var);
|
|
40
|
+
let __typescript_eslint_types = require("@typescript-eslint/types");
|
|
41
|
+
__typescript_eslint_types = __toESM(__typescript_eslint_types);
|
|
42
|
+
let ts_pattern = require("ts-pattern");
|
|
43
|
+
ts_pattern = __toESM(ts_pattern);
|
|
44
|
+
let __typescript_eslint_utils = require("@typescript-eslint/utils");
|
|
45
|
+
__typescript_eslint_utils = __toESM(__typescript_eslint_utils);
|
|
38
46
|
|
|
39
47
|
//#region src/configs/recommended.ts
|
|
40
48
|
var recommended_exports = {};
|
|
@@ -52,7 +60,7 @@ const rules = {
|
|
|
52
60
|
//#endregion
|
|
53
61
|
//#region package.json
|
|
54
62
|
var name = "eslint-plugin-react-hooks-extra";
|
|
55
|
-
var version = "1.53.1-next.
|
|
63
|
+
var version = "1.53.1-next.1";
|
|
56
64
|
|
|
57
65
|
//#endregion
|
|
58
66
|
//#region src/utils/create-rule.ts
|
|
@@ -97,24 +105,22 @@ function isSetFunctionCall(context, settings) {
|
|
|
97
105
|
const [index] = node.callee.arguments;
|
|
98
106
|
if (!isAt || index == null) return false;
|
|
99
107
|
const indexScope = context.sourceCode.getScope(node);
|
|
100
|
-
|
|
108
|
+
return __eslint_react_var.toStaticValue({
|
|
101
109
|
kind: "lazy",
|
|
102
110
|
node: index,
|
|
103
111
|
initialScope: indexScope
|
|
104
|
-
}).value;
|
|
105
|
-
return indexValue === 1 && isIdFromUseStateCall(callee.object);
|
|
112
|
+
}).value === 1 && isIdFromUseStateCall(callee.object);
|
|
106
113
|
}
|
|
107
114
|
case __typescript_eslint_types.AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(node.callee);
|
|
108
115
|
case __typescript_eslint_types.AST_NODE_TYPES.MemberExpression: {
|
|
109
116
|
if (!("name" in node.callee.object)) return false;
|
|
110
117
|
const property = node.callee.property;
|
|
111
118
|
const propertyScope = context.sourceCode.getScope(node);
|
|
112
|
-
|
|
119
|
+
return __eslint_react_var.toStaticValue({
|
|
113
120
|
kind: "lazy",
|
|
114
121
|
node: property,
|
|
115
122
|
initialScope: propertyScope
|
|
116
|
-
}).value;
|
|
117
|
-
return propertyValue === 1 && isIdFromUseStateCall(node.callee.object);
|
|
123
|
+
}).value === 1 && isIdFromUseStateCall(node.callee.object);
|
|
118
124
|
}
|
|
119
125
|
default: return false;
|
|
120
126
|
}
|
|
@@ -365,18 +371,16 @@ function create$3(context) {
|
|
|
365
371
|
if (!__eslint_react_core.isReactHookCall(node)) return;
|
|
366
372
|
const initialScope = context.sourceCode.getScope(node);
|
|
367
373
|
if (!isUseCallbackCall(node)) return;
|
|
368
|
-
const
|
|
369
|
-
const component = scope.block;
|
|
374
|
+
const component = context.sourceCode.getScope(node).block;
|
|
370
375
|
if (!__eslint_react_ast.isFunction(component)) return;
|
|
371
376
|
const [arg0, arg1] = node.arguments;
|
|
372
377
|
if (arg0 == null || arg1 == null) return;
|
|
373
|
-
|
|
378
|
+
if (!(0, ts_pattern.match)(arg1).with({ type: __typescript_eslint_types.AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: __typescript_eslint_types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
374
379
|
const variable = __eslint_react_var.findVariable(n.name, initialScope);
|
|
375
380
|
const variableNode = __eslint_react_var.getVariableInitNode(variable, 0);
|
|
376
381
|
if (variableNode?.type !== __typescript_eslint_types.AST_NODE_TYPES.ArrayExpression) return false;
|
|
377
382
|
return variableNode.elements.length === 0;
|
|
378
|
-
}).otherwise(() => false);
|
|
379
|
-
if (!hasEmptyDeps) return;
|
|
383
|
+
}).otherwise(() => false)) return;
|
|
380
384
|
const arg0Node = (0, ts_pattern.match)(arg0).with({ type: __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
381
385
|
if (n.body.type === __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
382
386
|
return n;
|
|
@@ -388,9 +392,7 @@ function create$3(context) {
|
|
|
388
392
|
}).otherwise(() => null);
|
|
389
393
|
if (arg0Node == null) return;
|
|
390
394
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
391
|
-
|
|
392
|
-
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
393
|
-
if (!isReferencedToComponentScope) context.report({
|
|
395
|
+
if (!__eslint_react_var.getChidScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
394
396
|
messageId: "noUnnecessaryUseCallback",
|
|
395
397
|
node
|
|
396
398
|
});
|
|
@@ -423,20 +425,17 @@ function create$2(context) {
|
|
|
423
425
|
if (!__eslint_react_core.isReactHookCall(node)) return;
|
|
424
426
|
const initialScope = context.sourceCode.getScope(node);
|
|
425
427
|
if (!isUseMemoCall(node)) return;
|
|
426
|
-
const
|
|
427
|
-
const component = scope.block;
|
|
428
|
+
const component = context.sourceCode.getScope(node).block;
|
|
428
429
|
if (!__eslint_react_ast.isFunction(component)) return;
|
|
429
430
|
const [arg0, arg1] = node.arguments;
|
|
430
431
|
if (arg0 == null || arg1 == null) return;
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
const hasEmptyDeps = (0, ts_pattern.match)(arg1).with({ type: __typescript_eslint_types.AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: __typescript_eslint_types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
432
|
+
if (__eslint_react_ast.isFunction(arg0) && [...__eslint_react_ast.getNestedCallExpressions(arg0.body), ...__eslint_react_ast.getNestedNewExpressions(arg0.body)].length > 0) return;
|
|
433
|
+
if (!(0, ts_pattern.match)(arg1).with({ type: __typescript_eslint_types.AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: __typescript_eslint_types.AST_NODE_TYPES.Identifier }, (n) => {
|
|
434
434
|
const variable = __eslint_react_var.findVariable(n.name, initialScope);
|
|
435
435
|
const variableNode = __eslint_react_var.getVariableInitNode(variable, 0);
|
|
436
436
|
if (variableNode?.type !== __typescript_eslint_types.AST_NODE_TYPES.ArrayExpression) return false;
|
|
437
437
|
return variableNode.elements.length === 0;
|
|
438
|
-
}).otherwise(() => false);
|
|
439
|
-
if (!hasEmptyDeps) return;
|
|
438
|
+
}).otherwise(() => false)) return;
|
|
440
439
|
const arg0Node = (0, ts_pattern.match)(arg0).with({ type: __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
441
440
|
if (n.body.type === __typescript_eslint_types.AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
442
441
|
return n;
|
|
@@ -448,9 +447,7 @@ function create$2(context) {
|
|
|
448
447
|
}).otherwise(() => null);
|
|
449
448
|
if (arg0Node == null) return;
|
|
450
449
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
451
|
-
|
|
452
|
-
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
453
|
-
if (!isReferencedToComponentScope) context.report({
|
|
450
|
+
if (!__eslint_react_var.getChidScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
454
451
|
messageId: "noUnnecessaryUseMemo",
|
|
455
452
|
node
|
|
456
453
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ const rules = {
|
|
|
33
33
|
//#endregion
|
|
34
34
|
//#region package.json
|
|
35
35
|
var name = "eslint-plugin-react-hooks-extra";
|
|
36
|
-
var version = "1.53.1-next.
|
|
36
|
+
var version = "1.53.1-next.1";
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/utils/create-rule.ts
|
|
@@ -78,24 +78,22 @@ function isSetFunctionCall(context, settings) {
|
|
|
78
78
|
const [index] = node.callee.arguments;
|
|
79
79
|
if (!isAt || index == null) return false;
|
|
80
80
|
const indexScope = context.sourceCode.getScope(node);
|
|
81
|
-
|
|
81
|
+
return VAR.toStaticValue({
|
|
82
82
|
kind: "lazy",
|
|
83
83
|
node: index,
|
|
84
84
|
initialScope: indexScope
|
|
85
|
-
}).value;
|
|
86
|
-
return indexValue === 1 && isIdFromUseStateCall(callee.object);
|
|
85
|
+
}).value === 1 && isIdFromUseStateCall(callee.object);
|
|
87
86
|
}
|
|
88
87
|
case AST_NODE_TYPES.Identifier: return isIdFromUseStateCall(node.callee);
|
|
89
88
|
case AST_NODE_TYPES.MemberExpression: {
|
|
90
89
|
if (!("name" in node.callee.object)) return false;
|
|
91
90
|
const property = node.callee.property;
|
|
92
91
|
const propertyScope = context.sourceCode.getScope(node);
|
|
93
|
-
|
|
92
|
+
return VAR.toStaticValue({
|
|
94
93
|
kind: "lazy",
|
|
95
94
|
node: property,
|
|
96
95
|
initialScope: propertyScope
|
|
97
|
-
}).value;
|
|
98
|
-
return propertyValue === 1 && isIdFromUseStateCall(node.callee.object);
|
|
96
|
+
}).value === 1 && isIdFromUseStateCall(node.callee.object);
|
|
99
97
|
}
|
|
100
98
|
default: return false;
|
|
101
99
|
}
|
|
@@ -346,18 +344,16 @@ function create$3(context) {
|
|
|
346
344
|
if (!ER.isReactHookCall(node)) return;
|
|
347
345
|
const initialScope = context.sourceCode.getScope(node);
|
|
348
346
|
if (!isUseCallbackCall(node)) return;
|
|
349
|
-
const
|
|
350
|
-
const component = scope.block;
|
|
347
|
+
const component = context.sourceCode.getScope(node).block;
|
|
351
348
|
if (!AST.isFunction(component)) return;
|
|
352
349
|
const [arg0, arg1] = node.arguments;
|
|
353
350
|
if (arg0 == null || arg1 == null) return;
|
|
354
|
-
|
|
351
|
+
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
355
352
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
356
353
|
const variableNode = VAR.getVariableInitNode(variable, 0);
|
|
357
354
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
358
355
|
return variableNode.elements.length === 0;
|
|
359
|
-
}).otherwise(() => false);
|
|
360
|
-
if (!hasEmptyDeps) return;
|
|
356
|
+
}).otherwise(() => false)) return;
|
|
361
357
|
const arg0Node = match(arg0).with({ type: AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
362
358
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
363
359
|
return n;
|
|
@@ -369,9 +365,7 @@ function create$3(context) {
|
|
|
369
365
|
}).otherwise(() => null);
|
|
370
366
|
if (arg0Node == null) return;
|
|
371
367
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
372
|
-
|
|
373
|
-
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
374
|
-
if (!isReferencedToComponentScope) context.report({
|
|
368
|
+
if (!VAR.getChidScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
375
369
|
messageId: "noUnnecessaryUseCallback",
|
|
376
370
|
node
|
|
377
371
|
});
|
|
@@ -404,20 +398,17 @@ function create$2(context) {
|
|
|
404
398
|
if (!ER.isReactHookCall(node)) return;
|
|
405
399
|
const initialScope = context.sourceCode.getScope(node);
|
|
406
400
|
if (!isUseMemoCall(node)) return;
|
|
407
|
-
const
|
|
408
|
-
const component = scope.block;
|
|
401
|
+
const component = context.sourceCode.getScope(node).block;
|
|
409
402
|
if (!AST.isFunction(component)) return;
|
|
410
403
|
const [arg0, arg1] = node.arguments;
|
|
411
404
|
if (arg0 == null || arg1 == null) return;
|
|
412
|
-
|
|
413
|
-
if (
|
|
414
|
-
const hasEmptyDeps = match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
405
|
+
if (AST.isFunction(arg0) && [...AST.getNestedCallExpressions(arg0.body), ...AST.getNestedNewExpressions(arg0.body)].length > 0) return;
|
|
406
|
+
if (!match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
415
407
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
416
408
|
const variableNode = VAR.getVariableInitNode(variable, 0);
|
|
417
409
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
418
410
|
return variableNode.elements.length === 0;
|
|
419
|
-
}).otherwise(() => false);
|
|
420
|
-
if (!hasEmptyDeps) return;
|
|
411
|
+
}).otherwise(() => false)) return;
|
|
421
412
|
const arg0Node = match(arg0).with({ type: AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
|
|
422
413
|
if (n.body.type === AST_NODE_TYPES.ArrowFunctionExpression) return n.body;
|
|
423
414
|
return n;
|
|
@@ -429,9 +420,7 @@ function create$2(context) {
|
|
|
429
420
|
}).otherwise(() => null);
|
|
430
421
|
if (arg0Node == null) return;
|
|
431
422
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
432
|
-
|
|
433
|
-
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
434
|
-
if (!isReferencedToComponentScope) context.report({
|
|
423
|
+
if (!VAR.getChidScopes(arg0NodeScope).flatMap((x) => x.references).some((x) => x.resolved?.scope.block === component)) context.report({
|
|
435
424
|
messageId: "noUnnecessaryUseMemo",
|
|
436
425
|
node
|
|
437
426
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.53.1-next.
|
|
3
|
+
"version": "1.53.1-next.1",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -44,23 +44,23 @@
|
|
|
44
44
|
"./package.json"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@typescript-eslint/scope-manager": "^8.
|
|
48
|
-
"@typescript-eslint/type-utils": "^8.
|
|
49
|
-
"@typescript-eslint/types": "^8.
|
|
50
|
-
"@typescript-eslint/utils": "^8.
|
|
47
|
+
"@typescript-eslint/scope-manager": "^8.43.0",
|
|
48
|
+
"@typescript-eslint/type-utils": "^8.43.0",
|
|
49
|
+
"@typescript-eslint/types": "^8.43.0",
|
|
50
|
+
"@typescript-eslint/utils": "^8.43.0",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.8.0",
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
58
|
-
"@eslint-react/
|
|
53
|
+
"@eslint-react/core": "1.53.1-next.1",
|
|
54
|
+
"@eslint-react/eff": "1.53.1-next.1",
|
|
55
|
+
"@eslint-react/ast": "1.53.1-next.1",
|
|
56
|
+
"@eslint-react/shared": "1.53.1-next.1",
|
|
57
|
+
"@eslint-react/var": "1.53.1-next.1",
|
|
58
|
+
"@eslint-react/kit": "1.53.1-next.1"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/react": "^19.1.12",
|
|
62
62
|
"@types/react-dom": "^19.1.9",
|
|
63
|
-
"tsdown": "^0.
|
|
63
|
+
"tsdown": "^0.15.0",
|
|
64
64
|
"@local/configs": "0.0.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|