eslint-plugin-react-hooks-extra 1.6.1-next.2 → 1.7.0-beta.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 +31 -14
- package/dist/index.mjs +12 -15
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -6,10 +6,31 @@ var ast = require('@eslint-react/ast');
|
|
|
6
6
|
var tools = require('@eslint-react/tools');
|
|
7
7
|
var _var = require('@eslint-react/var');
|
|
8
8
|
var astUtils = require('@typescript-eslint/utils/ast-utils');
|
|
9
|
+
var R = require('remeda');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n.default = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var R__namespace = /*#__PURE__*/_interopNamespace(R);
|
|
9
30
|
|
|
10
31
|
// package.json
|
|
11
32
|
var name = "eslint-plugin-react-hooks-extra";
|
|
12
|
-
var version = "1.
|
|
33
|
+
var version = "1.7.0-beta.2";
|
|
13
34
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
14
35
|
function isFromUseStateCall(context, useStateAlias) {
|
|
15
36
|
return (topLevelId) => {
|
|
@@ -239,11 +260,7 @@ function isSetStateCall(context, useStateAlias) {
|
|
|
239
260
|
};
|
|
240
261
|
}
|
|
241
262
|
function isThenCall(node) {
|
|
242
|
-
|
|
243
|
-
return a({
|
|
244
|
-
type: ast.NodeType.Identifier,
|
|
245
|
-
name: "then"
|
|
246
|
-
}, node.callee.property);
|
|
263
|
+
return node.callee.type === ast.NodeType.MemberExpression && node.callee.property.type === ast.NodeType.Identifier && node.callee.property.name === "then";
|
|
247
264
|
}
|
|
248
265
|
|
|
249
266
|
// src/rules/ensure-custom-hooks-using-other-hooks.ts
|
|
@@ -462,7 +479,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
462
479
|
create(context) {
|
|
463
480
|
const settings = shared.decodeSettings(context.settings);
|
|
464
481
|
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
465
|
-
const functionStack =
|
|
482
|
+
const functionStack = [];
|
|
466
483
|
const effectFunctionRef = tools.MutRef.make(null);
|
|
467
484
|
const effectFunctionIdentifiers = [];
|
|
468
485
|
const indirectFunctionCalls = [];
|
|
@@ -476,18 +493,18 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
476
493
|
return {
|
|
477
494
|
":function"(node) {
|
|
478
495
|
const functionKind = getFunctionKind(node, context, useEffectAlias);
|
|
479
|
-
|
|
496
|
+
functionStack.push([node, functionKind]);
|
|
480
497
|
$(functionKind).with("effect", () => {
|
|
481
498
|
onEffectFunctionEnter(node);
|
|
482
499
|
}).otherwise(tools.F.constVoid);
|
|
483
500
|
},
|
|
484
501
|
":function:exit"(node) {
|
|
485
502
|
onEffectFunctionExit(node);
|
|
486
|
-
|
|
503
|
+
functionStack.pop();
|
|
487
504
|
},
|
|
488
505
|
CallExpression(node) {
|
|
489
506
|
const effectFn = tools.MutRef.get(effectFunctionRef);
|
|
490
|
-
const [parentFn, parentFnKind] =
|
|
507
|
+
const [parentFn, parentFnKind] = R__namespace.last(functionStack) ?? [];
|
|
491
508
|
if (parentFn?.async) return;
|
|
492
509
|
const callKind = getCallKind(node, context, useStateAlias, useEffectAlias);
|
|
493
510
|
$(callKind).with("setState", () => {
|
|
@@ -573,7 +590,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
573
590
|
create(context) {
|
|
574
591
|
const settings = shared.decodeSettings(context.settings);
|
|
575
592
|
const { useLayoutEffect: useLayoutEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
576
|
-
const functionStack =
|
|
593
|
+
const functionStack = [];
|
|
577
594
|
const effectFunctionRef = tools.MutRef.make(null);
|
|
578
595
|
const effectFunctionIdentifiers = [];
|
|
579
596
|
const indirectFunctionCalls = [];
|
|
@@ -587,18 +604,18 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
587
604
|
return {
|
|
588
605
|
":function"(node) {
|
|
589
606
|
const functionKind = getFunctionKind2(node, context, useLayoutEffectAlias);
|
|
590
|
-
|
|
607
|
+
functionStack.push([node, functionKind]);
|
|
591
608
|
$(functionKind).with("effect", () => {
|
|
592
609
|
onEffectFunctionEnter(node);
|
|
593
610
|
}).otherwise(tools.F.constVoid);
|
|
594
611
|
},
|
|
595
612
|
":function:exit"(node) {
|
|
596
613
|
onEffectFunctionExit(node);
|
|
597
|
-
|
|
614
|
+
functionStack.pop();
|
|
598
615
|
},
|
|
599
616
|
CallExpression(node) {
|
|
600
617
|
const effectFn = tools.MutRef.get(effectFunctionRef);
|
|
601
|
-
const [parentFn, parentFnKind] =
|
|
618
|
+
const [parentFn, parentFnKind] = R__namespace.last(functionStack) ?? [];
|
|
602
619
|
if (parentFn?.async) return;
|
|
603
620
|
const callKind = getCallKind2(node, context, useStateAlias, useLayoutEffectAlias);
|
|
604
621
|
$(callKind).with("setState", () => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { useHookCollector, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, isUseStateCall, isReactHookCallWithNameAlias } from '@eslint-react/core';
|
|
2
2
|
import { createRuleForPlugin, decodeSettings } from '@eslint-react/shared';
|
|
3
3
|
import { isFunction, NodeType, is, getNestedIdentifiers, getNestedCallExpressions, isIIFE } from '@eslint-react/ast';
|
|
4
|
-
import { F, O,
|
|
4
|
+
import { F, O, MutRef } from '@eslint-react/tools';
|
|
5
5
|
import { findVariable, getVariableNode } from '@eslint-react/var';
|
|
6
6
|
import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
|
|
7
|
+
import * as R from 'remeda';
|
|
7
8
|
|
|
8
9
|
// package.json
|
|
9
10
|
var name = "eslint-plugin-react-hooks-extra";
|
|
10
|
-
var version = "1.
|
|
11
|
+
var version = "1.7.0-beta.2";
|
|
11
12
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
12
13
|
function isFromUseStateCall(context, useStateAlias) {
|
|
13
14
|
return (topLevelId) => {
|
|
@@ -237,11 +238,7 @@ function isSetStateCall(context, useStateAlias) {
|
|
|
237
238
|
};
|
|
238
239
|
}
|
|
239
240
|
function isThenCall(node) {
|
|
240
|
-
|
|
241
|
-
return a({
|
|
242
|
-
type: NodeType.Identifier,
|
|
243
|
-
name: "then"
|
|
244
|
-
}, node.callee.property);
|
|
241
|
+
return node.callee.type === NodeType.MemberExpression && node.callee.property.type === NodeType.Identifier && node.callee.property.name === "then";
|
|
245
242
|
}
|
|
246
243
|
|
|
247
244
|
// src/rules/ensure-custom-hooks-using-other-hooks.ts
|
|
@@ -460,7 +457,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
460
457
|
create(context) {
|
|
461
458
|
const settings = decodeSettings(context.settings);
|
|
462
459
|
const { useEffect: useEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
463
|
-
const functionStack =
|
|
460
|
+
const functionStack = [];
|
|
464
461
|
const effectFunctionRef = MutRef.make(null);
|
|
465
462
|
const effectFunctionIdentifiers = [];
|
|
466
463
|
const indirectFunctionCalls = [];
|
|
@@ -474,18 +471,18 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
474
471
|
return {
|
|
475
472
|
":function"(node) {
|
|
476
473
|
const functionKind = getFunctionKind(node, context, useEffectAlias);
|
|
477
|
-
|
|
474
|
+
functionStack.push([node, functionKind]);
|
|
478
475
|
$(functionKind).with("effect", () => {
|
|
479
476
|
onEffectFunctionEnter(node);
|
|
480
477
|
}).otherwise(F.constVoid);
|
|
481
478
|
},
|
|
482
479
|
":function:exit"(node) {
|
|
483
480
|
onEffectFunctionExit(node);
|
|
484
|
-
|
|
481
|
+
functionStack.pop();
|
|
485
482
|
},
|
|
486
483
|
CallExpression(node) {
|
|
487
484
|
const effectFn = MutRef.get(effectFunctionRef);
|
|
488
|
-
const [parentFn, parentFnKind] =
|
|
485
|
+
const [parentFn, parentFnKind] = R.last(functionStack) ?? [];
|
|
489
486
|
if (parentFn?.async) return;
|
|
490
487
|
const callKind = getCallKind(node, context, useStateAlias, useEffectAlias);
|
|
491
488
|
$(callKind).with("setState", () => {
|
|
@@ -571,7 +568,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
571
568
|
create(context) {
|
|
572
569
|
const settings = decodeSettings(context.settings);
|
|
573
570
|
const { useLayoutEffect: useLayoutEffectAlias = [], useState: useStateAlias = [] } = settings.additionalHooks ?? {};
|
|
574
|
-
const functionStack =
|
|
571
|
+
const functionStack = [];
|
|
575
572
|
const effectFunctionRef = MutRef.make(null);
|
|
576
573
|
const effectFunctionIdentifiers = [];
|
|
577
574
|
const indirectFunctionCalls = [];
|
|
@@ -585,18 +582,18 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
585
582
|
return {
|
|
586
583
|
":function"(node) {
|
|
587
584
|
const functionKind = getFunctionKind2(node, context, useLayoutEffectAlias);
|
|
588
|
-
|
|
585
|
+
functionStack.push([node, functionKind]);
|
|
589
586
|
$(functionKind).with("effect", () => {
|
|
590
587
|
onEffectFunctionEnter(node);
|
|
591
588
|
}).otherwise(F.constVoid);
|
|
592
589
|
},
|
|
593
590
|
":function:exit"(node) {
|
|
594
591
|
onEffectFunctionExit(node);
|
|
595
|
-
|
|
592
|
+
functionStack.pop();
|
|
596
593
|
},
|
|
597
594
|
CallExpression(node) {
|
|
598
595
|
const effectFn = MutRef.get(effectFunctionRef);
|
|
599
|
-
const [parentFn, parentFnKind] =
|
|
596
|
+
const [parentFn, parentFnKind] = R.last(functionStack) ?? [];
|
|
600
597
|
if (parentFn?.async) return;
|
|
601
598
|
const callKind = getCallKind2(node, context, useStateAlias, useLayoutEffectAlias);
|
|
602
599
|
$(callKind).with("setState", () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-beta.2",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -35,17 +35,18 @@
|
|
|
35
35
|
"./package.json"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@typescript-eslint/scope-manager": "^7.
|
|
39
|
-
"@typescript-eslint/type-utils": "^7.
|
|
40
|
-
"@typescript-eslint/types": "^7.
|
|
41
|
-
"@typescript-eslint/utils": "^7.
|
|
42
|
-
"
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
38
|
+
"@typescript-eslint/scope-manager": "^7.18.0",
|
|
39
|
+
"@typescript-eslint/type-utils": "^7.18.0",
|
|
40
|
+
"@typescript-eslint/types": "^7.18.0",
|
|
41
|
+
"@typescript-eslint/utils": "^7.18.0",
|
|
42
|
+
"remeda": "^2.6.0",
|
|
43
|
+
"@eslint-react/shared": "1.7.0-beta.2",
|
|
44
|
+
"@eslint-react/jsx": "1.7.0-beta.2",
|
|
45
|
+
"@eslint-react/ast": "1.7.0-beta.2",
|
|
46
|
+
"@eslint-react/tools": "1.7.0-beta.2",
|
|
47
|
+
"@eslint-react/types": "1.7.0-beta.2",
|
|
48
|
+
"@eslint-react/var": "1.7.0-beta.2",
|
|
49
|
+
"@eslint-react/core": "1.7.0-beta.2"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/react": "^18.3.3",
|