eslint-plugin-react-hooks-extra 2.0.0-next.34 → 2.0.0-next.35

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -35
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as AST from '@eslint-react/ast';
2
2
  import * as ER from '@eslint-react/core';
3
- import { getOrElseUpdate, constVoid } from '@eslint-react/eff';
3
+ import { getOrElseUpdate, constVoid, not } from '@eslint-react/eff';
4
4
  import { getDocsUrl, getSettingsFromContext } from '@eslint-react/shared';
5
5
  import * as VAR from '@eslint-react/var';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
@@ -27,39 +27,7 @@ var rules = {
27
27
 
28
28
  // package.json
29
29
  var name2 = "eslint-plugin-react-hooks-extra";
30
- var version = "2.0.0-next.34";
31
- var createRule = ESLintUtils.RuleCreator(getDocsUrl("hooks-extra"));
32
-
33
- // src/rules/no-direct-set-state-in-use-effect.ts
34
- var RULE_NAME = "no-direct-set-state-in-use-effect";
35
- var RULE_FEATURES = [
36
- "EXP"
37
- ];
38
- var no_direct_set_state_in_use_effect_default = createRule({
39
- meta: {
40
- type: "problem",
41
- docs: {
42
- description: "Disallow direct calls to the `set` function of `useState` in `useEffect`.",
43
- [Symbol.for("rule_features")]: RULE_FEATURES
44
- },
45
- messages: {
46
- noDirectSetStateInUseEffect: "Do not call the 'set' function '{{name}}' of 'useState' directly in 'useEffect'."
47
- },
48
- schema: []
49
- },
50
- name: RULE_NAME,
51
- create,
52
- defaultOptions: []
53
- });
54
- function create(context) {
55
- if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
56
- return useNoDirectSetStateInUseEffect(context, {
57
- onViolation(ctx, node, data) {
58
- ctx.report({ messageId: "noDirectSetStateInUseEffect", node, data });
59
- },
60
- useEffectKind: "useEffect"
61
- });
62
- }
30
+ var version = "2.0.0-next.35";
63
31
  function useNoDirectSetStateInUseEffect(context, options) {
64
32
  const { onViolation, useEffectKind } = options;
65
33
  const settings = getSettingsFromContext(context);
@@ -98,7 +66,18 @@ function useNoDirectSetStateInUseEffect(context, options) {
98
66
  return match(node).when(isUseStateCall, () => "useState").when(isUseEffectLikeCall, () => useEffectKind).when(isSetStateCall, () => "setState").when(AST.isThenCall, () => "then").otherwise(() => "other");
99
67
  }
100
68
  function getFunctionKind(node) {
101
- return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST.isImmediatelyInvokedFunction, () => "immediate").otherwise(() => "other");
69
+ const parent = AST.findParentNode(node, not(AST.isTypeExpression)) ?? node.parent;
70
+ switch (true) {
71
+ case node.async:
72
+ case (parent.type === AST_NODE_TYPES.CallExpression && AST.isThenCall(parent)):
73
+ return "deferred";
74
+ case (node.type !== AST_NODE_TYPES.FunctionDeclaration && parent.type === AST_NODE_TYPES.CallExpression && parent.callee === node):
75
+ return "immediate";
76
+ case isFunctionOfUseEffectSetup(node):
77
+ return "setup";
78
+ default:
79
+ return "other";
80
+ }
102
81
  }
103
82
  function isIdFromUseStateCall(topLevelId, at) {
104
83
  const variable = VAR.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
@@ -302,6 +281,38 @@ function isVariableDeclaratorFromHookCall(node) {
302
281
  if (node.id.type !== AST_NODE_TYPES.Identifier) return false;
303
282
  return isInitFromHookCall(node.init);
304
283
  }
284
+ var createRule = ESLintUtils.RuleCreator(getDocsUrl("hooks-extra"));
285
+
286
+ // src/rules/no-direct-set-state-in-use-effect.ts
287
+ var RULE_NAME = "no-direct-set-state-in-use-effect";
288
+ var RULE_FEATURES = [
289
+ "EXP"
290
+ ];
291
+ var no_direct_set_state_in_use_effect_default = createRule({
292
+ meta: {
293
+ type: "problem",
294
+ docs: {
295
+ description: "Disallow direct calls to the `set` function of `useState` in `useEffect`.",
296
+ [Symbol.for("rule_features")]: RULE_FEATURES
297
+ },
298
+ messages: {
299
+ noDirectSetStateInUseEffect: "Do not call the 'set' function '{{name}}' of 'useState' directly in 'useEffect'."
300
+ },
301
+ schema: []
302
+ },
303
+ name: RULE_NAME,
304
+ create,
305
+ defaultOptions: []
306
+ });
307
+ function create(context) {
308
+ if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
309
+ return useNoDirectSetStateInUseEffect(context, {
310
+ onViolation(ctx, node, data) {
311
+ ctx.report({ messageId: "noDirectSetStateInUseEffect", node, data });
312
+ },
313
+ useEffectKind: "useEffect"
314
+ });
315
+ }
305
316
 
306
317
  // src/rules/no-direct-set-state-in-use-layout-effect.ts
307
318
  var RULE_NAME2 = "no-direct-set-state-in-use-layout-effect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "2.0.0-next.34",
3
+ "version": "2.0.0-next.35",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -42,12 +42,12 @@
42
42
  "@typescript-eslint/utils": "^8.33.1",
43
43
  "string-ts": "^2.2.1",
44
44
  "ts-pattern": "^5.7.1",
45
- "@eslint-react/core": "2.0.0-next.34",
46
- "@eslint-react/ast": "2.0.0-next.34",
47
- "@eslint-react/eff": "2.0.0-next.34",
48
- "@eslint-react/kit": "2.0.0-next.34",
49
- "@eslint-react/shared": "2.0.0-next.34",
50
- "@eslint-react/var": "2.0.0-next.34"
45
+ "@eslint-react/ast": "2.0.0-next.35",
46
+ "@eslint-react/kit": "2.0.0-next.35",
47
+ "@eslint-react/eff": "2.0.0-next.35",
48
+ "@eslint-react/shared": "2.0.0-next.35",
49
+ "@eslint-react/core": "2.0.0-next.35",
50
+ "@eslint-react/var": "2.0.0-next.35"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/react": "^19.1.6",