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