eslint-plugin-react-hooks-extra 1.37.1-next.3 → 1.37.1-next.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 CHANGED
@@ -49,7 +49,7 @@ var rules = {
49
49
 
50
50
  // package.json
51
51
  var name2 = "eslint-plugin-react-hooks-extra";
52
- var version = "1.37.1-next.3";
52
+ var version = "1.37.1-next.5";
53
53
  var createRule = shared.createRuleForPlugin("hooks-extra");
54
54
  function isFromHookCall(context, name3, settings, predicate = eff.constTrue) {
55
55
  const hookAlias = settings.additionalHooks[name3] ?? [];
@@ -319,7 +319,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
319
319
  meta: {
320
320
  type: "problem",
321
321
  docs: {
322
- description: "disallow direct calls to the 'set' function of 'useState' in 'useEffect'",
322
+ description: "Disallow direct calls to the `set` function of `useState` in `useEffect`.",
323
323
  [Symbol.for("rule_features")]: RULE_FEATURES
324
324
  },
325
325
  messages: {
@@ -348,7 +348,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
348
348
  meta: {
349
349
  type: "problem",
350
350
  docs: {
351
- description: "disallow direct calls to the 'set' function of 'useState' in 'useLayoutEffect'",
351
+ description: "Disallow direct calls to the `set` function of `useState` in `useLayoutEffect`.",
352
352
  [Symbol.for("rule_features")]: RULE_FEATURES2
353
353
  },
354
354
  messages: {
@@ -375,7 +375,7 @@ var no_unnecessary_use_callback_default = createRule({
375
375
  meta: {
376
376
  type: "problem",
377
377
  docs: {
378
- description: "disallow unnecessary usage of 'useCallback'",
378
+ description: "Disallow unnecessary usage of `useCallback`.",
379
379
  [Symbol.for("rule_features")]: RULE_FEATURES3
380
380
  },
381
381
  messages: {
@@ -451,7 +451,7 @@ var no_unnecessary_use_memo_default = createRule({
451
451
  meta: {
452
452
  type: "problem",
453
453
  docs: {
454
- description: "disallow unnecessary usage of 'useMemo'",
454
+ description: "Disallow unnecessary usage of `useMemo`.",
455
455
  [Symbol.for("rule_features")]: RULE_FEATURES4
456
456
  },
457
457
  messages: {
@@ -534,7 +534,7 @@ var no_unnecessary_use_prefix_default = createRule({
534
534
  meta: {
535
535
  type: "problem",
536
536
  docs: {
537
- description: "enforce that a function with the 'use' prefix should use at least one Hook inside of it",
537
+ description: "Enforces that a function with the `use` prefix should use at least one Hook inside of it.",
538
538
  [Symbol.for("rule_features")]: RULE_FEATURES5
539
539
  },
540
540
  messages: {
@@ -580,14 +580,11 @@ var ALLOW_LIST = [
580
580
  "String",
581
581
  "Number"
582
582
  ];
583
- function isAllowedName(name3) {
584
- return ALLOW_LIST.includes(name3) || core.isReactHookName(name3);
585
- }
586
583
  var prefer_use_state_lazy_initialization_default = createRule({
587
584
  meta: {
588
585
  type: "problem",
589
586
  docs: {
590
- description: "disallow function calls in 'useState' that aren't wrapped in an initializer function",
587
+ description: "Enforces function calls made inside `useState` to be wrapped in an `initializer function`.",
591
588
  [Symbol.for("rule_features")]: RULE_FEATURES6
592
589
  },
593
590
  messages: {
@@ -614,20 +611,25 @@ function create6(context) {
614
611
  if (useStateInput == null) {
615
612
  return;
616
613
  }
617
- const nestedCallExpressions = AST__namespace.getNestedCallExpressions(useStateInput);
618
- const hasFunctionCall = nestedCallExpressions.some((n) => {
619
- return "name" in n.callee && !isAllowedName(n.callee.name);
620
- });
621
- const hasNewCall = AST__namespace.getNestedNewExpressions(useStateInput).some((n) => {
622
- return "name" in n.callee && !isAllowedName(n.callee.name);
623
- });
624
- if (!hasFunctionCall && !hasNewCall) {
625
- return;
614
+ for (const expr of AST__namespace.getNestedNewExpressions(useStateInput)) {
615
+ if (!("name" in expr.callee)) continue;
616
+ if (ALLOW_LIST.includes(expr.callee.name)) continue;
617
+ if (AST__namespace.findParentNode(expr, (n) => core.isUseCall(context, n)) != null) continue;
618
+ context.report({
619
+ messageId: "preferUseStateLazyInitialization",
620
+ node: expr
621
+ });
622
+ }
623
+ for (const expr of AST__namespace.getNestedCallExpressions(useStateInput)) {
624
+ if (!("name" in expr.callee)) continue;
625
+ if (core.isReactHookNameLoose(expr.callee.name)) continue;
626
+ if (ALLOW_LIST.includes(expr.callee.name)) continue;
627
+ if (AST__namespace.findParentNode(expr, (n) => core.isUseCall(context, n)) != null) continue;
628
+ context.report({
629
+ messageId: "preferUseStateLazyInitialization",
630
+ node: expr
631
+ });
626
632
  }
627
- context.report({
628
- messageId: "preferUseStateLazyInitialization",
629
- node: useStateInput
630
- });
631
633
  }
632
634
  };
633
635
  }
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as AST from '@eslint-react/ast';
2
- import { isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, useHookCollector, isUseStateCall, isReactHookCallWithNameAlias, isReactHookName } from '@eslint-react/core';
2
+ import { isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, useHookCollector, isUseStateCall, isUseCall, isReactHookNameLoose, isReactHookCallWithNameAlias, isReactHookName } from '@eslint-react/core';
3
3
  import { identity, _, getOrUpdate, constTrue } from '@eslint-react/eff';
4
4
  import { createRuleForPlugin, getSettingsFromContext } from '@eslint-react/shared';
5
5
  import * as VAR4 from '@eslint-react/var';
@@ -26,7 +26,7 @@ var rules = {
26
26
 
27
27
  // package.json
28
28
  var name2 = "eslint-plugin-react-hooks-extra";
29
- var version = "1.37.1-next.3";
29
+ var version = "1.37.1-next.5";
30
30
  var createRule = createRuleForPlugin("hooks-extra");
31
31
  function isFromHookCall(context, name3, settings, predicate = constTrue) {
32
32
  const hookAlias = settings.additionalHooks[name3] ?? [];
@@ -296,7 +296,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
296
296
  meta: {
297
297
  type: "problem",
298
298
  docs: {
299
- description: "disallow direct calls to the 'set' function of 'useState' in 'useEffect'",
299
+ description: "Disallow direct calls to the `set` function of `useState` in `useEffect`.",
300
300
  [Symbol.for("rule_features")]: RULE_FEATURES
301
301
  },
302
302
  messages: {
@@ -325,7 +325,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
325
325
  meta: {
326
326
  type: "problem",
327
327
  docs: {
328
- description: "disallow direct calls to the 'set' function of 'useState' in 'useLayoutEffect'",
328
+ description: "Disallow direct calls to the `set` function of `useState` in `useLayoutEffect`.",
329
329
  [Symbol.for("rule_features")]: RULE_FEATURES2
330
330
  },
331
331
  messages: {
@@ -352,7 +352,7 @@ var no_unnecessary_use_callback_default = createRule({
352
352
  meta: {
353
353
  type: "problem",
354
354
  docs: {
355
- description: "disallow unnecessary usage of 'useCallback'",
355
+ description: "Disallow unnecessary usage of `useCallback`.",
356
356
  [Symbol.for("rule_features")]: RULE_FEATURES3
357
357
  },
358
358
  messages: {
@@ -428,7 +428,7 @@ var no_unnecessary_use_memo_default = createRule({
428
428
  meta: {
429
429
  type: "problem",
430
430
  docs: {
431
- description: "disallow unnecessary usage of 'useMemo'",
431
+ description: "Disallow unnecessary usage of `useMemo`.",
432
432
  [Symbol.for("rule_features")]: RULE_FEATURES4
433
433
  },
434
434
  messages: {
@@ -511,7 +511,7 @@ var no_unnecessary_use_prefix_default = createRule({
511
511
  meta: {
512
512
  type: "problem",
513
513
  docs: {
514
- description: "enforce that a function with the 'use' prefix should use at least one Hook inside of it",
514
+ description: "Enforces that a function with the `use` prefix should use at least one Hook inside of it.",
515
515
  [Symbol.for("rule_features")]: RULE_FEATURES5
516
516
  },
517
517
  messages: {
@@ -557,14 +557,11 @@ var ALLOW_LIST = [
557
557
  "String",
558
558
  "Number"
559
559
  ];
560
- function isAllowedName(name3) {
561
- return ALLOW_LIST.includes(name3) || isReactHookName(name3);
562
- }
563
560
  var prefer_use_state_lazy_initialization_default = createRule({
564
561
  meta: {
565
562
  type: "problem",
566
563
  docs: {
567
- description: "disallow function calls in 'useState' that aren't wrapped in an initializer function",
564
+ description: "Enforces function calls made inside `useState` to be wrapped in an `initializer function`.",
568
565
  [Symbol.for("rule_features")]: RULE_FEATURES6
569
566
  },
570
567
  messages: {
@@ -591,20 +588,25 @@ function create6(context) {
591
588
  if (useStateInput == null) {
592
589
  return;
593
590
  }
594
- const nestedCallExpressions = AST.getNestedCallExpressions(useStateInput);
595
- const hasFunctionCall = nestedCallExpressions.some((n) => {
596
- return "name" in n.callee && !isAllowedName(n.callee.name);
597
- });
598
- const hasNewCall = AST.getNestedNewExpressions(useStateInput).some((n) => {
599
- return "name" in n.callee && !isAllowedName(n.callee.name);
600
- });
601
- if (!hasFunctionCall && !hasNewCall) {
602
- return;
591
+ for (const expr of AST.getNestedNewExpressions(useStateInput)) {
592
+ if (!("name" in expr.callee)) continue;
593
+ if (ALLOW_LIST.includes(expr.callee.name)) continue;
594
+ if (AST.findParentNode(expr, (n) => isUseCall(context, n)) != null) continue;
595
+ context.report({
596
+ messageId: "preferUseStateLazyInitialization",
597
+ node: expr
598
+ });
599
+ }
600
+ for (const expr of AST.getNestedCallExpressions(useStateInput)) {
601
+ if (!("name" in expr.callee)) continue;
602
+ if (isReactHookNameLoose(expr.callee.name)) continue;
603
+ if (ALLOW_LIST.includes(expr.callee.name)) continue;
604
+ if (AST.findParentNode(expr, (n) => isUseCall(context, n)) != null) continue;
605
+ context.report({
606
+ messageId: "preferUseStateLazyInitialization",
607
+ node: expr
608
+ });
603
609
  }
604
- context.report({
605
- messageId: "preferUseStateLazyInitialization",
606
- node: useStateInput
607
- });
608
610
  }
609
611
  };
610
612
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.37.1-next.3",
3
+ "version": "1.37.1-next.5",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -50,12 +50,12 @@
50
50
  "@typescript-eslint/utils": "^8.27.0",
51
51
  "string-ts": "^2.2.1",
52
52
  "ts-pattern": "^5.6.2",
53
- "@eslint-react/ast": "1.37.1-next.3",
54
- "@eslint-react/core": "1.37.1-next.3",
55
- "@eslint-react/eff": "1.37.1-next.3",
56
- "@eslint-react/jsx": "1.37.1-next.3",
57
- "@eslint-react/shared": "1.37.1-next.3",
58
- "@eslint-react/var": "1.37.1-next.3"
53
+ "@eslint-react/ast": "1.37.1-next.5",
54
+ "@eslint-react/core": "1.37.1-next.5",
55
+ "@eslint-react/eff": "1.37.1-next.5",
56
+ "@eslint-react/jsx": "1.37.1-next.5",
57
+ "@eslint-react/shared": "1.37.1-next.5",
58
+ "@eslint-react/var": "1.37.1-next.5"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/react": "^19.0.12",