eslint-plugin-react-hooks-extra 2.0.0-beta.49 → 2.0.0-beta.53
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 +10 -10
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -29,7 +29,7 @@ const rules = { "react-hooks-extra/no-direct-set-state-in-use-effect": "warn" };
|
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region package.json
|
|
31
31
|
var name = "eslint-plugin-react-hooks-extra";
|
|
32
|
-
var version = "2.0.0-beta.
|
|
32
|
+
var version = "2.0.0-beta.53";
|
|
33
33
|
|
|
34
34
|
//#endregion
|
|
35
35
|
//#region src/rules-hooks/use-no-direct-set-state-in-use-effect.ts
|
|
@@ -78,7 +78,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
78
78
|
}
|
|
79
79
|
function isIdFromUseStateCall(topLevelId, at) {
|
|
80
80
|
const variable = VAR.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
|
|
81
|
-
const variableNode = VAR.
|
|
81
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
82
82
|
if (variableNode == null) return false;
|
|
83
83
|
if (variableNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
84
84
|
if (!ER.isReactHookCallWithNameAlias(context, "useState", hooks.useState)(variableNode)) return false;
|
|
@@ -182,7 +182,7 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
182
182
|
},
|
|
183
183
|
"Program:exit"() {
|
|
184
184
|
const getSetStateCalls = (id, initialScope) => {
|
|
185
|
-
const node = VAR.
|
|
185
|
+
const node = VAR.getVariableDefinitionNode(VAR.findVariable(id, initialScope), 0);
|
|
186
186
|
switch (node?.type) {
|
|
187
187
|
case AST_NODE_TYPES.ArrowFunctionExpression:
|
|
188
188
|
case AST_NODE_TYPES.FunctionDeclaration:
|
|
@@ -344,7 +344,7 @@ function create$3(context) {
|
|
|
344
344
|
if (arg0 == null || arg1 == null) return;
|
|
345
345
|
const hasEmptyDeps = match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
346
346
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
347
|
-
const variableNode = VAR.
|
|
347
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
348
348
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
349
349
|
return variableNode.elements.length === 0;
|
|
350
350
|
}).otherwise(() => false);
|
|
@@ -354,13 +354,13 @@ function create$3(context) {
|
|
|
354
354
|
return n;
|
|
355
355
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
356
356
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
357
|
-
const variableNode = VAR.
|
|
357
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
358
358
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
359
359
|
return variableNode;
|
|
360
360
|
}).otherwise(() => null);
|
|
361
361
|
if (arg0Node == null) return;
|
|
362
362
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
363
|
-
const arg0NodeReferences = VAR.
|
|
363
|
+
const arg0NodeReferences = VAR.getChildScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
364
364
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
365
365
|
if (!isReferencedToComponentScope) context.report({
|
|
366
366
|
messageId: "noUnnecessaryUseCallback",
|
|
@@ -428,7 +428,7 @@ function create$2(context) {
|
|
|
428
428
|
if (hasCallInArg0) return;
|
|
429
429
|
const hasEmptyDeps = match(arg1).with({ type: AST_NODE_TYPES.ArrayExpression }, (n) => n.elements.length === 0).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
430
430
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
431
|
-
const variableNode = VAR.
|
|
431
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
432
432
|
if (variableNode?.type !== AST_NODE_TYPES.ArrayExpression) return false;
|
|
433
433
|
return variableNode.elements.length === 0;
|
|
434
434
|
}).otherwise(() => false);
|
|
@@ -438,13 +438,13 @@ function create$2(context) {
|
|
|
438
438
|
return n;
|
|
439
439
|
}).with({ type: AST_NODE_TYPES.FunctionExpression }, identity).with({ type: AST_NODE_TYPES.Identifier }, (n) => {
|
|
440
440
|
const variable = VAR.findVariable(n.name, initialScope);
|
|
441
|
-
const variableNode = VAR.
|
|
441
|
+
const variableNode = VAR.getVariableDefinitionNode(variable, 0);
|
|
442
442
|
if (variableNode?.type !== AST_NODE_TYPES.ArrowFunctionExpression && variableNode?.type !== AST_NODE_TYPES.FunctionExpression) return null;
|
|
443
443
|
return variableNode;
|
|
444
444
|
}).otherwise(() => null);
|
|
445
445
|
if (arg0Node == null) return;
|
|
446
446
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
447
|
-
const arg0NodeReferences = VAR.
|
|
447
|
+
const arg0NodeReferences = VAR.getChildScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
448
448
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
449
449
|
if (!isReferencedToComponentScope) context.report({
|
|
450
450
|
messageId: "noUnnecessaryUseMemo",
|
|
@@ -507,7 +507,7 @@ function create$1(context) {
|
|
|
507
507
|
const allHooks = ctx.getAllHooks(program);
|
|
508
508
|
for (const { id, name: name$2, node, hookCalls } of allHooks.values()) {
|
|
509
509
|
if (WELL_KNOWN_HOOKS.includes(name$2)) continue;
|
|
510
|
-
if (AST.
|
|
510
|
+
if (AST.isFunctionEmpty(node)) continue;
|
|
511
511
|
if (hookCalls.length > 0) continue;
|
|
512
512
|
if (containsUseComments(context, node)) continue;
|
|
513
513
|
if (id != null) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.53",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
"@typescript-eslint/utils": "^8.41.0",
|
|
43
43
|
"string-ts": "^2.2.1",
|
|
44
44
|
"ts-pattern": "^5.8.0",
|
|
45
|
-
"@eslint-react/ast": "2.0.0-beta.
|
|
46
|
-
"@eslint-react/core": "2.0.0-beta.
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/shared": "2.0.0-beta.
|
|
50
|
-
"@eslint-react/
|
|
45
|
+
"@eslint-react/ast": "2.0.0-beta.53",
|
|
46
|
+
"@eslint-react/core": "2.0.0-beta.53",
|
|
47
|
+
"@eslint-react/kit": "2.0.0-beta.53",
|
|
48
|
+
"@eslint-react/var": "2.0.0-beta.53",
|
|
49
|
+
"@eslint-react/shared": "2.0.0-beta.53",
|
|
50
|
+
"@eslint-react/eff": "2.0.0-beta.53"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@types/react": "^19.1.
|
|
53
|
+
"@types/react": "^19.1.12",
|
|
54
54
|
"@types/react-dom": "^19.1.8",
|
|
55
55
|
"tsdown": "^0.14.2",
|
|
56
56
|
"@local/configs": "0.0.0"
|