eslint-plugin-react-hooks-extra 1.50.1-beta.1 → 1.50.1-beta.7

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 CHANGED
@@ -52,7 +52,7 @@ var rules = {
52
52
 
53
53
  // package.json
54
54
  var name2 = "eslint-plugin-react-hooks-extra";
55
- var version = "1.50.1-beta.1";
55
+ var version = "1.50.1-beta.7";
56
56
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("hooks-extra"));
57
57
  function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
58
58
  const hookAlias = settings.additionalHooks[name3] ?? [];
@@ -75,9 +75,6 @@ function isFromUseStateCall(context, settings) {
75
75
  };
76
76
  return isFromHookCall(context, "useState", settings, predicate);
77
77
  }
78
- function isFunctionOfImmediatelyInvoked(node) {
79
- return node.type !== types.AST_NODE_TYPES.FunctionDeclaration && node.parent.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee === node;
80
- }
81
78
  function isSetFunctionCall(context, settings) {
82
79
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
83
80
  return (node) => {
@@ -195,7 +192,18 @@ function useNoDirectSetStateInUseEffect(context, options) {
195
192
  return tsPattern.match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
196
193
  }
197
194
  function getFunctionKind(node) {
198
- return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
195
+ const parent = AST__namespace.findParentNode(node, eff.not(AST__namespace.isTypeExpression)) ?? node.parent;
196
+ switch (true) {
197
+ case node.async:
198
+ case (parent.type === types.AST_NODE_TYPES.CallExpression && isThenCall(parent)):
199
+ return "deferred";
200
+ case (node.type !== types.AST_NODE_TYPES.FunctionDeclaration && parent.type === types.AST_NODE_TYPES.CallExpression && parent.callee === node):
201
+ return "immediate";
202
+ case isFunctionOfUseEffectSetup(node):
203
+ return "setup";
204
+ default:
205
+ return "other";
206
+ }
199
207
  }
200
208
  return {
201
209
  ":function"(node) {
@@ -220,6 +228,10 @@ function useNoDirectSetStateInUseEffect(context, options) {
220
228
  }
221
229
  tsPattern.match(getCallKind(node)).with("setState", () => {
222
230
  switch (true) {
231
+ case pEntry.kind === "deferred":
232
+ case pEntry.node.async: {
233
+ break;
234
+ }
223
235
  case pEntry.node === setupFunction:
224
236
  case (pEntry.kind === "immediate" && AST__namespace.findParentNode(pEntry.node, AST__namespace.isFunction) === setupFunction): {
225
237
  onViolation(context, node, {
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as AST from '@eslint-react/ast';
2
2
  import * as ER7 from '@eslint-react/core';
3
- import { identity, getOrElseUpdate, constVoid, constTrue } from '@eslint-react/eff';
3
+ import { identity, getOrElseUpdate, constVoid, constTrue, not } from '@eslint-react/eff';
4
4
  import { getDocsUrl, getSettingsFromContext } from '@eslint-react/shared';
5
5
  import * as VAR4 from '@eslint-react/var';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
@@ -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.50.1-beta.1";
31
+ var version = "1.50.1-beta.7";
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] ?? [];
@@ -51,9 +51,6 @@ function isFromUseStateCall(context, settings) {
51
51
  };
52
52
  return isFromHookCall(context, "useState", settings, predicate);
53
53
  }
54
- function isFunctionOfImmediatelyInvoked(node) {
55
- return node.type !== AST_NODE_TYPES.FunctionDeclaration && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee === node;
56
- }
57
54
  function isSetFunctionCall(context, settings) {
58
55
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
59
56
  return (node) => {
@@ -171,7 +168,18 @@ function useNoDirectSetStateInUseEffect(context, options) {
171
168
  return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
172
169
  }
173
170
  function getFunctionKind(node) {
174
- return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
171
+ const parent = AST.findParentNode(node, not(AST.isTypeExpression)) ?? node.parent;
172
+ switch (true) {
173
+ case node.async:
174
+ case (parent.type === AST_NODE_TYPES.CallExpression && isThenCall(parent)):
175
+ return "deferred";
176
+ case (node.type !== AST_NODE_TYPES.FunctionDeclaration && parent.type === AST_NODE_TYPES.CallExpression && parent.callee === node):
177
+ return "immediate";
178
+ case isFunctionOfUseEffectSetup(node):
179
+ return "setup";
180
+ default:
181
+ return "other";
182
+ }
175
183
  }
176
184
  return {
177
185
  ":function"(node) {
@@ -196,6 +204,10 @@ function useNoDirectSetStateInUseEffect(context, options) {
196
204
  }
197
205
  match(getCallKind(node)).with("setState", () => {
198
206
  switch (true) {
207
+ case pEntry.kind === "deferred":
208
+ case pEntry.node.async: {
209
+ break;
210
+ }
199
211
  case pEntry.node === setupFunction:
200
212
  case (pEntry.kind === "immediate" && AST.findParentNode(pEntry.node, AST.isFunction) === setupFunction): {
201
213
  onViolation(context, node, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.50.1-beta.1",
3
+ "version": "1.50.1-beta.7",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -44,18 +44,18 @@
44
44
  "./package.json"
45
45
  ],
46
46
  "dependencies": {
47
- "@typescript-eslint/scope-manager": "^8.33.0",
48
- "@typescript-eslint/type-utils": "^8.33.0",
49
- "@typescript-eslint/types": "^8.33.0",
50
- "@typescript-eslint/utils": "^8.33.0",
47
+ "@typescript-eslint/scope-manager": "^8.33.1",
48
+ "@typescript-eslint/type-utils": "^8.33.1",
49
+ "@typescript-eslint/types": "^8.33.1",
50
+ "@typescript-eslint/utils": "^8.33.1",
51
51
  "string-ts": "^2.2.1",
52
52
  "ts-pattern": "^5.7.1",
53
- "@eslint-react/ast": "1.50.1-beta.1",
54
- "@eslint-react/core": "1.50.1-beta.1",
55
- "@eslint-react/eff": "1.50.1-beta.1",
56
- "@eslint-react/kit": "1.50.1-beta.1",
57
- "@eslint-react/var": "1.50.1-beta.1",
58
- "@eslint-react/shared": "1.50.1-beta.1"
53
+ "@eslint-react/ast": "1.50.1-beta.7",
54
+ "@eslint-react/eff": "1.50.1-beta.7",
55
+ "@eslint-react/core": "1.50.1-beta.7",
56
+ "@eslint-react/kit": "1.50.1-beta.7",
57
+ "@eslint-react/shared": "1.50.1-beta.7",
58
+ "@eslint-react/var": "1.50.1-beta.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/react": "^19.1.6",