eslint-plugin-react-hooks-extra 2.4.1-beta.3 → 2.4.1-beta.5
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 +7 -4
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const rules = { "react-hooks-extra/no-direct-set-state-in-use-effect": "warn" };
|
|
|
36
36
|
//#endregion
|
|
37
37
|
//#region package.json
|
|
38
38
|
var name = "eslint-plugin-react-hooks-extra";
|
|
39
|
-
var version = "2.4.1-beta.
|
|
39
|
+
var version = "2.4.1-beta.5";
|
|
40
40
|
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/utils/create-rule.ts
|
|
@@ -67,7 +67,7 @@ const RULE_NAME = "no-direct-set-state-in-use-effect";
|
|
|
67
67
|
var no_direct_set_state_in_use_effect_default = createRule({
|
|
68
68
|
meta: {
|
|
69
69
|
type: "problem",
|
|
70
|
-
docs: { description: "Disallow direct calls to the 'set' function of 'useState' in 'useEffect'." },
|
|
70
|
+
docs: { description: "Disallow **direct** calls to the 'set' function of 'useState' in 'useEffect'." },
|
|
71
71
|
messages: { noDirectSetStateInUseEffect: "Do not call the 'set' function '{{name}}' of 'useState' directly in 'useEffect'." },
|
|
72
72
|
schema: []
|
|
73
73
|
},
|
|
@@ -92,6 +92,9 @@ function create(context) {
|
|
|
92
92
|
const onSetupFunctionExit = (node) => {
|
|
93
93
|
if (setupFnRef.current === node) setupFnRef.current = null;
|
|
94
94
|
};
|
|
95
|
+
function isThenCall(node) {
|
|
96
|
+
return node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "then";
|
|
97
|
+
}
|
|
95
98
|
function isFunctionOfUseEffectSetup(node) {
|
|
96
99
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
|
|
97
100
|
}
|
|
@@ -100,13 +103,13 @@ function create(context) {
|
|
|
100
103
|
return AST.toStringFormat(node, getText);
|
|
101
104
|
}
|
|
102
105
|
function getCallKind(node) {
|
|
103
|
-
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(
|
|
106
|
+
return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
|
|
104
107
|
}
|
|
105
108
|
function getFunctionKind(node) {
|
|
106
109
|
const parent = AST.findParentNode(node, not(AST.isTypeExpression)) ?? node.parent;
|
|
107
110
|
switch (true) {
|
|
108
111
|
case node.async:
|
|
109
|
-
case parent.type === AST_NODE_TYPES.CallExpression &&
|
|
112
|
+
case parent.type === AST_NODE_TYPES.CallExpression && isThenCall(parent): return "deferred";
|
|
110
113
|
case node.type !== AST_NODE_TYPES.FunctionDeclaration && parent.type === AST_NODE_TYPES.CallExpression && parent.callee === node: return "immediate";
|
|
111
114
|
case isFunctionOfUseEffectSetup(node): return "setup";
|
|
112
115
|
default: return "other";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "2.4.1-beta.
|
|
3
|
+
"version": "2.4.1-beta.5",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"@typescript-eslint/utils": "^8.50.1",
|
|
46
46
|
"string-ts": "^2.3.1",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "2.4.1-beta.
|
|
49
|
-
"@eslint-react/eff": "2.4.1-beta.
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/var": "2.4.1-beta.
|
|
52
|
-
"@eslint-react/
|
|
48
|
+
"@eslint-react/ast": "2.4.1-beta.5",
|
|
49
|
+
"@eslint-react/eff": "2.4.1-beta.5",
|
|
50
|
+
"@eslint-react/core": "2.4.1-beta.5",
|
|
51
|
+
"@eslint-react/var": "2.4.1-beta.5",
|
|
52
|
+
"@eslint-react/shared": "2.4.1-beta.5"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.7",
|