eslint-plugin-react-hooks-extra 1.38.5-next.2 → 1.39.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 +20 -19
- package/dist/index.mjs +19 -19
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var AST = require('@eslint-react/ast');
|
|
4
|
-
var
|
|
4
|
+
var ER7 = require('@eslint-react/core');
|
|
5
5
|
var eff = require('@eslint-react/eff');
|
|
6
6
|
var shared = require('@eslint-react/shared');
|
|
7
7
|
var VAR4 = require('@eslint-react/var');
|
|
@@ -28,6 +28,7 @@ function _interopNamespace(e) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
|
|
31
|
+
var ER7__namespace = /*#__PURE__*/_interopNamespace(ER7);
|
|
31
32
|
var VAR4__namespace = /*#__PURE__*/_interopNamespace(VAR4);
|
|
32
33
|
|
|
33
34
|
var __defProp = Object.defineProperty;
|
|
@@ -51,7 +52,7 @@ var rules = {
|
|
|
51
52
|
|
|
52
53
|
// package.json
|
|
53
54
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
54
|
-
var version = "1.
|
|
55
|
+
var version = "1.39.0-beta.1";
|
|
55
56
|
var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("hooks-extra"));
|
|
56
57
|
function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
|
|
57
58
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
@@ -60,7 +61,7 @@ function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
|
|
|
60
61
|
const variableNode = VAR4__namespace.getVariableInitNode(variable, 0);
|
|
61
62
|
if (variableNode == null) return false;
|
|
62
63
|
if (variableNode.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
63
|
-
if (!
|
|
64
|
+
if (!ER7__namespace.isReactHookCallWithNameAlias(context, name3, hookAlias)(variableNode)) return false;
|
|
64
65
|
return predicate(topLevelId, variableNode);
|
|
65
66
|
};
|
|
66
67
|
}
|
|
@@ -145,9 +146,9 @@ function isVariableDeclaratorFromHookCall(node) {
|
|
|
145
146
|
}
|
|
146
147
|
switch (node.init.callee.type) {
|
|
147
148
|
case types.AST_NODE_TYPES.Identifier:
|
|
148
|
-
return
|
|
149
|
+
return ER7__namespace.isReactHookName(node.init.callee.name);
|
|
149
150
|
case types.AST_NODE_TYPES.MemberExpression:
|
|
150
|
-
return node.init.callee.property.type === types.AST_NODE_TYPES.Identifier &&
|
|
151
|
+
return node.init.callee.property.type === types.AST_NODE_TYPES.Identifier && ER7__namespace.isReactHookName(node.init.callee.property.name);
|
|
151
152
|
default:
|
|
152
153
|
return false;
|
|
153
154
|
}
|
|
@@ -158,10 +159,10 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
158
159
|
const { onViolation, useEffectKind } = options;
|
|
159
160
|
const settings = shared.getSettingsFromContext(context);
|
|
160
161
|
const additionalHooks = settings.additionalHooks;
|
|
161
|
-
const isUseEffectLikeCall =
|
|
162
|
-
const isUseStateCall2 =
|
|
163
|
-
const isUseMemoCall2 =
|
|
164
|
-
const isUseCallbackCall2 =
|
|
162
|
+
const isUseEffectLikeCall = ER7__namespace.isReactHookCallWithNameAlias(context, useEffectKind, additionalHooks[useEffectKind]);
|
|
163
|
+
const isUseStateCall2 = ER7__namespace.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState);
|
|
164
|
+
const isUseMemoCall2 = ER7__namespace.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo);
|
|
165
|
+
const isUseCallbackCall2 = ER7__namespace.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback);
|
|
165
166
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
166
167
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
167
168
|
const functionEntries = [];
|
|
@@ -400,11 +401,11 @@ function create3(context) {
|
|
|
400
401
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
401
402
|
return {
|
|
402
403
|
CallExpression(node) {
|
|
403
|
-
if (!
|
|
404
|
+
if (!ER7__namespace.isReactHookCall(node)) {
|
|
404
405
|
return;
|
|
405
406
|
}
|
|
406
407
|
const initialScope = context.sourceCode.getScope(node);
|
|
407
|
-
if (!
|
|
408
|
+
if (!ER7__namespace.isUseCallbackCall(context, node) && !alias.some(ER7__namespace.isReactHookCallWithNameLoose(node))) {
|
|
408
409
|
return;
|
|
409
410
|
}
|
|
410
411
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -478,11 +479,11 @@ function create4(context) {
|
|
|
478
479
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
479
480
|
return {
|
|
480
481
|
CallExpression(node) {
|
|
481
|
-
if (!
|
|
482
|
+
if (!ER7__namespace.isReactHookCall(node)) {
|
|
482
483
|
return;
|
|
483
484
|
}
|
|
484
485
|
const initialScope = context.sourceCode.getScope(node);
|
|
485
|
-
if (!
|
|
486
|
+
if (!ER7__namespace.isUseMemoCall(context, node) && !alias.some(ER7__namespace.isReactHookCallWithNameLoose(node))) {
|
|
486
487
|
return;
|
|
487
488
|
}
|
|
488
489
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -557,7 +558,7 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
557
558
|
defaultOptions: []
|
|
558
559
|
});
|
|
559
560
|
function create5(context) {
|
|
560
|
-
const { ctx, listeners } =
|
|
561
|
+
const { ctx, listeners } = ER7__namespace.useHookCollector();
|
|
561
562
|
return {
|
|
562
563
|
...listeners,
|
|
563
564
|
"Program:exit"(node) {
|
|
@@ -613,10 +614,10 @@ function create6(context) {
|
|
|
613
614
|
const alias = shared.getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
614
615
|
return {
|
|
615
616
|
CallExpression(node) {
|
|
616
|
-
if (!
|
|
617
|
+
if (!ER7__namespace.isReactHookCall(node)) {
|
|
617
618
|
return;
|
|
618
619
|
}
|
|
619
|
-
if (!
|
|
620
|
+
if (!ER7__namespace.isUseStateCall(context, node) && !alias.some(ER7__namespace.isReactHookCallWithNameLoose(node))) {
|
|
620
621
|
return;
|
|
621
622
|
}
|
|
622
623
|
const [useStateInput] = node.arguments;
|
|
@@ -626,7 +627,7 @@ function create6(context) {
|
|
|
626
627
|
for (const expr of AST__namespace.getNestedNewExpressions(useStateInput)) {
|
|
627
628
|
if (!("name" in expr.callee)) continue;
|
|
628
629
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
629
|
-
if (AST__namespace.findParentNode(expr, (n) =>
|
|
630
|
+
if (AST__namespace.findParentNode(expr, (n) => ER7__namespace.isUseCall(context, n)) != null) continue;
|
|
630
631
|
context.report({
|
|
631
632
|
messageId: "preferUseStateLazyInitialization",
|
|
632
633
|
node: expr
|
|
@@ -634,9 +635,9 @@ function create6(context) {
|
|
|
634
635
|
}
|
|
635
636
|
for (const expr of AST__namespace.getNestedCallExpressions(useStateInput)) {
|
|
636
637
|
if (!("name" in expr.callee)) continue;
|
|
637
|
-
if (
|
|
638
|
+
if (ER7__namespace.isReactHookNameLoose(expr.callee.name)) continue;
|
|
638
639
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
639
|
-
if (AST__namespace.findParentNode(expr, (n) =>
|
|
640
|
+
if (AST__namespace.findParentNode(expr, (n) => ER7__namespace.isUseCall(context, n)) != null) continue;
|
|
640
641
|
context.report({
|
|
641
642
|
messageId: "preferUseStateLazyInitialization",
|
|
642
643
|
node: expr
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
|
-
import
|
|
2
|
+
import * as ER7 from '@eslint-react/core';
|
|
3
3
|
import { identity, _, getOrUpdate, constTrue } from '@eslint-react/eff';
|
|
4
4
|
import { getDocsUrl, getSettingsFromContext } from '@eslint-react/shared';
|
|
5
5
|
import * as VAR4 from '@eslint-react/var';
|
|
@@ -28,7 +28,7 @@ var rules = {
|
|
|
28
28
|
|
|
29
29
|
// package.json
|
|
30
30
|
var name2 = "eslint-plugin-react-hooks-extra";
|
|
31
|
-
var version = "1.
|
|
31
|
+
var version = "1.39.0-beta.1";
|
|
32
32
|
var createRule = ESLintUtils.RuleCreator(getDocsUrl("hooks-extra"));
|
|
33
33
|
function isFromHookCall(context, name3, settings, predicate = constTrue) {
|
|
34
34
|
const hookAlias = settings.additionalHooks[name3] ?? [];
|
|
@@ -37,7 +37,7 @@ function isFromHookCall(context, name3, settings, predicate = constTrue) {
|
|
|
37
37
|
const variableNode = VAR4.getVariableInitNode(variable, 0);
|
|
38
38
|
if (variableNode == null) return false;
|
|
39
39
|
if (variableNode.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
40
|
-
if (!isReactHookCallWithNameAlias(context, name3, hookAlias)(variableNode)) return false;
|
|
40
|
+
if (!ER7.isReactHookCallWithNameAlias(context, name3, hookAlias)(variableNode)) return false;
|
|
41
41
|
return predicate(topLevelId, variableNode);
|
|
42
42
|
};
|
|
43
43
|
}
|
|
@@ -122,9 +122,9 @@ function isVariableDeclaratorFromHookCall(node) {
|
|
|
122
122
|
}
|
|
123
123
|
switch (node.init.callee.type) {
|
|
124
124
|
case AST_NODE_TYPES.Identifier:
|
|
125
|
-
return isReactHookName(node.init.callee.name);
|
|
125
|
+
return ER7.isReactHookName(node.init.callee.name);
|
|
126
126
|
case AST_NODE_TYPES.MemberExpression:
|
|
127
|
-
return node.init.callee.property.type === AST_NODE_TYPES.Identifier && isReactHookName(node.init.callee.property.name);
|
|
127
|
+
return node.init.callee.property.type === AST_NODE_TYPES.Identifier && ER7.isReactHookName(node.init.callee.property.name);
|
|
128
128
|
default:
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
@@ -135,10 +135,10 @@ function useNoDirectSetStateInUseEffect(context, options) {
|
|
|
135
135
|
const { onViolation, useEffectKind } = options;
|
|
136
136
|
const settings = getSettingsFromContext(context);
|
|
137
137
|
const additionalHooks = settings.additionalHooks;
|
|
138
|
-
const isUseEffectLikeCall = isReactHookCallWithNameAlias(context, useEffectKind, additionalHooks[useEffectKind]);
|
|
139
|
-
const isUseStateCall2 = isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState);
|
|
140
|
-
const isUseMemoCall2 = isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo);
|
|
141
|
-
const isUseCallbackCall2 = isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback);
|
|
138
|
+
const isUseEffectLikeCall = ER7.isReactHookCallWithNameAlias(context, useEffectKind, additionalHooks[useEffectKind]);
|
|
139
|
+
const isUseStateCall2 = ER7.isReactHookCallWithNameAlias(context, "useState", additionalHooks.useState);
|
|
140
|
+
const isUseMemoCall2 = ER7.isReactHookCallWithNameAlias(context, "useMemo", additionalHooks.useMemo);
|
|
141
|
+
const isUseCallbackCall2 = ER7.isReactHookCallWithNameAlias(context, "useCallback", additionalHooks.useCallback);
|
|
142
142
|
const isSetStateCall = isSetFunctionCall(context, settings);
|
|
143
143
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
144
144
|
const functionEntries = [];
|
|
@@ -377,11 +377,11 @@ function create3(context) {
|
|
|
377
377
|
const alias = getSettingsFromContext(context).additionalHooks.useCallback ?? [];
|
|
378
378
|
return {
|
|
379
379
|
CallExpression(node) {
|
|
380
|
-
if (!isReactHookCall(node)) {
|
|
380
|
+
if (!ER7.isReactHookCall(node)) {
|
|
381
381
|
return;
|
|
382
382
|
}
|
|
383
383
|
const initialScope = context.sourceCode.getScope(node);
|
|
384
|
-
if (!isUseCallbackCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
384
|
+
if (!ER7.isUseCallbackCall(context, node) && !alias.some(ER7.isReactHookCallWithNameLoose(node))) {
|
|
385
385
|
return;
|
|
386
386
|
}
|
|
387
387
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -455,11 +455,11 @@ function create4(context) {
|
|
|
455
455
|
const alias = getSettingsFromContext(context).additionalHooks.useMemo ?? [];
|
|
456
456
|
return {
|
|
457
457
|
CallExpression(node) {
|
|
458
|
-
if (!isReactHookCall(node)) {
|
|
458
|
+
if (!ER7.isReactHookCall(node)) {
|
|
459
459
|
return;
|
|
460
460
|
}
|
|
461
461
|
const initialScope = context.sourceCode.getScope(node);
|
|
462
|
-
if (!isUseMemoCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
462
|
+
if (!ER7.isUseMemoCall(context, node) && !alias.some(ER7.isReactHookCallWithNameLoose(node))) {
|
|
463
463
|
return;
|
|
464
464
|
}
|
|
465
465
|
const scope = context.sourceCode.getScope(node);
|
|
@@ -534,7 +534,7 @@ var no_unnecessary_use_prefix_default = createRule({
|
|
|
534
534
|
defaultOptions: []
|
|
535
535
|
});
|
|
536
536
|
function create5(context) {
|
|
537
|
-
const { ctx, listeners } = useHookCollector();
|
|
537
|
+
const { ctx, listeners } = ER7.useHookCollector();
|
|
538
538
|
return {
|
|
539
539
|
...listeners,
|
|
540
540
|
"Program:exit"(node) {
|
|
@@ -590,10 +590,10 @@ function create6(context) {
|
|
|
590
590
|
const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
|
|
591
591
|
return {
|
|
592
592
|
CallExpression(node) {
|
|
593
|
-
if (!isReactHookCall(node)) {
|
|
593
|
+
if (!ER7.isReactHookCall(node)) {
|
|
594
594
|
return;
|
|
595
595
|
}
|
|
596
|
-
if (!isUseStateCall(context, node) && !alias.some(isReactHookCallWithNameLoose(node))) {
|
|
596
|
+
if (!ER7.isUseStateCall(context, node) && !alias.some(ER7.isReactHookCallWithNameLoose(node))) {
|
|
597
597
|
return;
|
|
598
598
|
}
|
|
599
599
|
const [useStateInput] = node.arguments;
|
|
@@ -603,7 +603,7 @@ function create6(context) {
|
|
|
603
603
|
for (const expr of AST.getNestedNewExpressions(useStateInput)) {
|
|
604
604
|
if (!("name" in expr.callee)) continue;
|
|
605
605
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
606
|
-
if (AST.findParentNode(expr, (n) => isUseCall(context, n)) != null) continue;
|
|
606
|
+
if (AST.findParentNode(expr, (n) => ER7.isUseCall(context, n)) != null) continue;
|
|
607
607
|
context.report({
|
|
608
608
|
messageId: "preferUseStateLazyInitialization",
|
|
609
609
|
node: expr
|
|
@@ -611,9 +611,9 @@ function create6(context) {
|
|
|
611
611
|
}
|
|
612
612
|
for (const expr of AST.getNestedCallExpressions(useStateInput)) {
|
|
613
613
|
if (!("name" in expr.callee)) continue;
|
|
614
|
-
if (isReactHookNameLoose(expr.callee.name)) continue;
|
|
614
|
+
if (ER7.isReactHookNameLoose(expr.callee.name)) continue;
|
|
615
615
|
if (ALLOW_LIST.includes(expr.callee.name)) continue;
|
|
616
|
-
if (AST.findParentNode(expr, (n) => isUseCall(context, n)) != null) continue;
|
|
616
|
+
if (AST.findParentNode(expr, (n) => ER7.isUseCall(context, n)) != null) continue;
|
|
617
617
|
context.report({
|
|
618
618
|
messageId: "preferUseStateLazyInitialization",
|
|
619
619
|
node: expr
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.0-beta.1",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"@typescript-eslint/utils": "^8.28.0",
|
|
51
51
|
"string-ts": "^2.2.1",
|
|
52
52
|
"ts-pattern": "^5.7.0",
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/jsx": "1.
|
|
57
|
-
"@eslint-react/shared": "1.
|
|
58
|
-
"@eslint-react/
|
|
59
|
-
"@eslint-react/
|
|
53
|
+
"@eslint-react/ast": "1.39.0-beta.1",
|
|
54
|
+
"@eslint-react/core": "1.39.0-beta.1",
|
|
55
|
+
"@eslint-react/eff": "1.39.0-beta.1",
|
|
56
|
+
"@eslint-react/jsx": "1.39.0-beta.1",
|
|
57
|
+
"@eslint-react/shared": "1.39.0-beta.1",
|
|
58
|
+
"@eslint-react/kit": "1.39.0-beta.1",
|
|
59
|
+
"@eslint-react/var": "1.39.0-beta.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@types/react": "^19.0.12",
|