eslint-plugin-react-hooks-extra 1.20.1 → 1.20.2-beta.3

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
@@ -2,8 +2,8 @@
2
2
 
3
3
  var AST2 = require('@eslint-react/ast');
4
4
  var core = require('@eslint-react/core');
5
+ var eff = require('@eslint-react/eff');
5
6
  var shared = require('@eslint-react/shared');
6
- var tools = require('@eslint-react/tools');
7
7
  var VAR5 = require('@eslint-react/var');
8
8
  var types = require('@typescript-eslint/types');
9
9
  var tsPattern = require('ts-pattern');
@@ -31,16 +31,16 @@ var VAR5__namespace = /*#__PURE__*/_interopNamespace(VAR5);
31
31
 
32
32
  // package.json
33
33
  var name = "eslint-plugin-react-hooks-extra";
34
- var version = "1.20.1";
34
+ var version = "1.20.2-beta.3";
35
35
  var createRule = shared.createRuleForPlugin("hooks-extra");
36
- function isFromHookCall(name2, context, settings, predicate = tools.F.constTrue) {
36
+ function isFromHookCall(name2, context, settings, predicate = eff.F.constTrue) {
37
37
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
38
- return (topLevelId) => tools.F.pipe(
38
+ return (topLevelId) => eff.F.pipe(
39
39
  VAR5__namespace.findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
40
- tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
41
- tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.CallExpression)),
42
- tools.O.filter(core.isReactHookCallWithNameAlias(name2, context, hookAlias)),
43
- tools.O.exists((call) => predicate(topLevelId, call))
40
+ eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
41
+ eff.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.CallExpression)),
42
+ eff.O.filter(core.isReactHookCallWithNameAlias(name2, context, hookAlias)),
43
+ eff.O.exists((call) => predicate(topLevelId, call))
44
44
  );
45
45
  }
46
46
  function isFromUseStateCall(context, settings) {
@@ -71,7 +71,7 @@ function isSetFunctionCall(context, settings) {
71
71
  const [index] = node.callee.arguments;
72
72
  if (!isAt || !index) return false;
73
73
  const initialScope = context.sourceCode.getScope(node);
74
- return tools.O.exists(VAR5__namespace.getStaticValue(index, initialScope), (v) => v === 1) && isIdFromUseStateCall(callee.object);
74
+ return eff.O.exists(VAR5__namespace.getStaticValue(index, initialScope), (v) => v === 1) && isIdFromUseStateCall(callee.object);
75
75
  }
76
76
  // const [data, setData] = useState();
77
77
  // setData();
@@ -83,7 +83,7 @@ function isSetFunctionCall(context, settings) {
83
83
  case types.AST_NODE_TYPES.MemberExpression: {
84
84
  if (!("name" in node.callee.object)) return false;
85
85
  const initialScope = context.sourceCode.getScope(node);
86
- return tools.O.exists(VAR5__namespace.getStaticValue(node.callee.property, initialScope), (v) => v === 1) && isIdFromUseStateCall(node.callee.object);
86
+ return eff.O.exists(VAR5__namespace.getStaticValue(node.callee.property, initialScope), (v) => v === 1) && isIdFromUseStateCall(node.callee.object);
87
87
  }
88
88
  default: {
89
89
  return false;
@@ -137,7 +137,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
137
137
  const isSetStateCall = isSetFunctionCall(context, settings);
138
138
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
139
139
  const functionStack = [];
140
- const setupFunctionRef = tools.MutRef.make(null);
140
+ const setupFunctionRef = eff.MutRef.make(null);
141
141
  const setupFunctionIdentifiers = [];
142
142
  const indirectFunctionCalls = [];
143
143
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
@@ -145,10 +145,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
145
145
  const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
146
146
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
147
147
  const onSetupFunctionEnter = (node) => {
148
- tools.MutRef.set(setupFunctionRef, node);
148
+ eff.MutRef.set(setupFunctionRef, node);
149
149
  };
150
150
  const onSetupFunctionExit = (node) => {
151
- tools.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
151
+ eff.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
152
152
  };
153
153
  function isSetupFunction(node) {
154
154
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
@@ -171,14 +171,14 @@ var no_direct_set_state_in_use_effect_default = createRule({
171
171
  if (functionKind === "setup") onSetupFunctionExit(node);
172
172
  },
173
173
  CallExpression(node) {
174
- const effectFn = tools.MutRef.get(setupFunctionRef);
174
+ const effectFn = eff.MutRef.get(setupFunctionRef);
175
175
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
176
176
  if (parentFn?.async) return;
177
177
  tsPattern.match(getCallKind(node)).with("setState", () => {
178
178
  if (!parentFn) return;
179
179
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
180
180
  const maybeVd = AST2__namespace.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
181
- if (tools.O.isSome(maybeVd)) {
181
+ if (eff.O.isSome(maybeVd)) {
182
182
  const vd = maybeVd.value;
183
183
  const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
184
184
  indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
@@ -202,7 +202,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
202
202
  const isInSetupFunction = effectFn === parentFn;
203
203
  if (!isInSetupFunction) return;
204
204
  indirectFunctionCalls.push(node);
205
- }).otherwise(tools.F.constVoid);
205
+ }).otherwise(eff.F.constVoid);
206
206
  },
207
207
  Identifier(node) {
208
208
  if (node.parent.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee === node) return;
@@ -213,7 +213,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
213
213
  if (parent.type !== types.AST_NODE_TYPES.CallExpression) break;
214
214
  if (!isUseMemoCall2(parent)) break;
215
215
  const maybeVd = AST2__namespace.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
216
- if (tools.O.isNone(maybeVd)) break;
216
+ if (eff.O.isNone(maybeVd)) break;
217
217
  const vd = maybeVd.value;
218
218
  const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
219
219
  indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
@@ -224,7 +224,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
224
224
  if (node !== firstArg) break;
225
225
  if (isUseCallbackCall2(node.parent)) {
226
226
  const maybeVd = AST2__namespace.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
227
- if (tools.O.isNone(maybeVd)) break;
227
+ if (eff.O.isNone(maybeVd)) break;
228
228
  const vd = maybeVd.value;
229
229
  const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
230
230
  indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
@@ -239,7 +239,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
239
239
  },
240
240
  "Program:exit"() {
241
241
  const getSetStateCalls = (id, initialScope) => {
242
- const node = tools.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(tools.O.getOrNull);
242
+ const node = eff.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(eff.O.getOrNull);
243
243
  switch (node?.type) {
244
244
  case types.AST_NODE_TYPES.ArrowFunctionExpression:
245
245
  case types.AST_NODE_TYPES.FunctionDeclaration:
@@ -322,7 +322,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
322
322
  const isSetStateCall = isSetFunctionCall(context, settings);
323
323
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
324
324
  const functionStack = [];
325
- const setupFunctionRef = tools.MutRef.make(null);
325
+ const setupFunctionRef = eff.MutRef.make(null);
326
326
  const setupFunctionIdentifiers = [];
327
327
  const indirectFunctionCalls = [];
328
328
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
@@ -330,10 +330,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
330
330
  const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
331
331
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
332
332
  const onSetupFunctionEnter = (node) => {
333
- tools.MutRef.set(setupFunctionRef, node);
333
+ eff.MutRef.set(setupFunctionRef, node);
334
334
  };
335
335
  const onSetupFunctionExit = (node) => {
336
- tools.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
336
+ eff.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
337
337
  };
338
338
  function isSetupFunction(node) {
339
339
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
@@ -356,14 +356,14 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
356
356
  if (functionKind === "setup") onSetupFunctionExit(node);
357
357
  },
358
358
  CallExpression(node) {
359
- const effectFn = tools.MutRef.get(setupFunctionRef);
359
+ const effectFn = eff.MutRef.get(setupFunctionRef);
360
360
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
361
361
  if (parentFn?.async) return;
362
362
  tsPattern.match(getCallKind(node)).with("setState", () => {
363
363
  if (!parentFn) return;
364
364
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
365
365
  const maybeVd = AST2__namespace.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
366
- if (tools.O.isSome(maybeVd)) {
366
+ if (eff.O.isSome(maybeVd)) {
367
367
  const vd = maybeVd.value;
368
368
  const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
369
369
  indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
@@ -387,7 +387,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
387
387
  const isInSetupFunction = effectFn === parentFn;
388
388
  if (!isInSetupFunction) return;
389
389
  indirectFunctionCalls.push(node);
390
- }).otherwise(tools.F.constVoid);
390
+ }).otherwise(eff.F.constVoid);
391
391
  },
392
392
  Identifier(node) {
393
393
  if (node.parent.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee === node) return;
@@ -398,7 +398,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
398
398
  if (parent.type !== types.AST_NODE_TYPES.CallExpression) break;
399
399
  if (!isUseMemoCall2(parent)) break;
400
400
  const maybeVd = AST2__namespace.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
401
- if (tools.O.isNone(maybeVd)) break;
401
+ if (eff.O.isNone(maybeVd)) break;
402
402
  const vd = maybeVd.value;
403
403
  const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
404
404
  indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
@@ -409,7 +409,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
409
409
  if (node !== firstArg) break;
410
410
  if (isUseCallbackCall2(node.parent)) {
411
411
  const maybeVd = AST2__namespace.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
412
- if (tools.O.isNone(maybeVd)) break;
412
+ if (eff.O.isNone(maybeVd)) break;
413
413
  const vd = maybeVd.value;
414
414
  const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
415
415
  indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
@@ -424,7 +424,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
424
424
  },
425
425
  "Program:exit"() {
426
426
  const getSetStateCalls = (id, initialScope) => {
427
- const node = tools.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(tools.O.getOrNull);
427
+ const node = eff.O.flatMap(VAR5__namespace.findVariable(id, initialScope), VAR5__namespace.getVariableNode(0)).pipe(eff.O.getOrNull);
428
428
  switch (node?.type) {
429
429
  case types.AST_NODE_TYPES.ArrowFunctionExpression:
430
430
  case types.AST_NODE_TYPES.FunctionDeclaration:
@@ -552,15 +552,15 @@ var no_unnecessary_use_callback_default = createRule({
552
552
  });
553
553
  return;
554
554
  }
555
- const hasEmptyDeps = tools.F.pipe(
556
- tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
557
- return tools.F.pipe(
555
+ const hasEmptyDeps = eff.F.pipe(
556
+ tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
557
+ return eff.F.pipe(
558
558
  VAR5__namespace.findVariable(n.name, initialScope),
559
- tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
560
- tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
559
+ eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
560
+ eff.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
561
561
  );
562
- }).otherwise(tools.O.none),
563
- tools.O.exists((x) => x.elements.length === 0)
562
+ }).otherwise(eff.O.none),
563
+ eff.O.exists((x) => x.elements.length === 0)
564
564
  );
565
565
  if (!hasEmptyDeps) return;
566
566
  if (!cb) {
@@ -570,22 +570,22 @@ var no_unnecessary_use_callback_default = createRule({
570
570
  });
571
571
  return;
572
572
  }
573
- const isReferencedToComponentScope = tools.F.pipe(
573
+ const isReferencedToComponentScope = eff.F.pipe(
574
574
  tsPattern.match(cb).with({ type: types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
575
575
  if (n.body.type === types.AST_NODE_TYPES.ArrowFunctionExpression) {
576
- return tools.O.some(n.body);
576
+ return eff.O.some(n.body);
577
577
  }
578
- return tools.O.some(n);
579
- }).with({ type: types.AST_NODE_TYPES.FunctionExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
580
- return tools.F.pipe(
578
+ return eff.O.some(n);
579
+ }).with({ type: types.AST_NODE_TYPES.FunctionExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
580
+ return eff.F.pipe(
581
581
  VAR5__namespace.findVariable(n.name, initialScope),
582
- tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
583
- tools.O.filter(AST2__namespace.isFunction)
582
+ eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
583
+ eff.O.filter(AST2__namespace.isFunction)
584
584
  );
585
- }).otherwise(tools.O.none),
586
- tools.O.map((n) => context.sourceCode.getScope(n)),
587
- tools.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
588
- tools.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
585
+ }).otherwise(eff.O.none),
586
+ eff.O.map((n) => context.sourceCode.getScope(n)),
587
+ eff.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
588
+ eff.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
589
589
  );
590
590
  if (isReferencedToComponentScope) return;
591
591
  context.report({
@@ -635,15 +635,15 @@ var no_unnecessary_use_memo_default = createRule({
635
635
  });
636
636
  return;
637
637
  }
638
- const hasEmptyDeps = tools.F.pipe(
639
- tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
640
- return tools.F.pipe(
638
+ const hasEmptyDeps = eff.F.pipe(
639
+ tsPattern.match(deps).with({ type: types.AST_NODE_TYPES.ArrayExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
640
+ return eff.F.pipe(
641
641
  VAR5__namespace.findVariable(n.name, initialScope),
642
- tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
643
- tools.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
642
+ eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
643
+ eff.O.filter(AST2__namespace.is(types.AST_NODE_TYPES.ArrayExpression))
644
644
  );
645
- }).otherwise(tools.O.none),
646
- tools.O.exists((x) => x.elements.length === 0)
645
+ }).otherwise(eff.O.none),
646
+ eff.O.exists((x) => x.elements.length === 0)
647
647
  );
648
648
  if (!hasEmptyDeps) return;
649
649
  if (!cb) {
@@ -653,22 +653,22 @@ var no_unnecessary_use_memo_default = createRule({
653
653
  });
654
654
  return;
655
655
  }
656
- const isReferencedToComponentScope = tools.F.pipe(
656
+ const isReferencedToComponentScope = eff.F.pipe(
657
657
  tsPattern.match(cb).with({ type: types.AST_NODE_TYPES.ArrowFunctionExpression }, (n) => {
658
658
  if (n.body.type === types.AST_NODE_TYPES.ArrowFunctionExpression) {
659
- return tools.O.some(n.body);
659
+ return eff.O.some(n.body);
660
660
  }
661
- return tools.O.some(n);
662
- }).with({ type: types.AST_NODE_TYPES.FunctionExpression }, tools.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
663
- return tools.F.pipe(
661
+ return eff.O.some(n);
662
+ }).with({ type: types.AST_NODE_TYPES.FunctionExpression }, eff.O.some).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => {
663
+ return eff.F.pipe(
664
664
  VAR5__namespace.findVariable(n.name, initialScope),
665
- tools.O.flatMap(VAR5__namespace.getVariableNode(0)),
666
- tools.O.filter(AST2__namespace.isFunction)
665
+ eff.O.flatMap(VAR5__namespace.getVariableNode(0)),
666
+ eff.O.filter(AST2__namespace.isFunction)
667
667
  );
668
- }).otherwise(tools.O.none),
669
- tools.O.map((n) => context.sourceCode.getScope(n)),
670
- tools.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
671
- tools.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
668
+ }).otherwise(eff.O.none),
669
+ eff.O.map((n) => context.sourceCode.getScope(n)),
670
+ eff.O.map((s) => VAR5__namespace.getChidScopes(s).flatMap((x) => x.references)),
671
+ eff.O.exists((refs) => refs.some((x) => x.resolved?.scope.block === component))
672
672
  );
673
673
  if (isReferencedToComponentScope) return;
674
674
  context.report({
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as AST2 from '@eslint-react/ast';
2
2
  import { isReactHookCallWithNameAlias, useHookCollector, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, isUseStateCall, isReactHookName } from '@eslint-react/core';
3
+ import { MutRef, O, F } from '@eslint-react/eff';
3
4
  import { createRuleForPlugin, decodeSettings } from '@eslint-react/shared';
4
- import { MutRef, O, F } from '@eslint-react/tools';
5
5
  import * as VAR5 from '@eslint-react/var';
6
6
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
7
7
  import { match, isMatching } from 'ts-pattern';
8
8
 
9
9
  // package.json
10
10
  var name = "eslint-plugin-react-hooks-extra";
11
- var version = "1.20.1";
11
+ var version = "1.20.2-beta.3";
12
12
  var createRule = createRuleForPlugin("hooks-extra");
13
13
  function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
14
14
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.20.1",
3
+ "version": "1.20.2-beta.3",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -49,16 +49,16 @@
49
49
  "@typescript-eslint/types": "^8.18.1",
50
50
  "@typescript-eslint/utils": "^8.18.1",
51
51
  "ts-pattern": "^5.6.0",
52
- "@eslint-react/ast": "1.20.1",
53
- "@eslint-react/jsx": "1.20.1",
54
- "@eslint-react/core": "1.20.1",
55
- "@eslint-react/shared": "1.20.1",
56
- "@eslint-react/tools": "1.20.1",
57
- "@eslint-react/var": "1.20.1",
58
- "@eslint-react/types": "1.20.1"
52
+ "@eslint-react/ast": "1.20.2-beta.3",
53
+ "@eslint-react/core": "1.20.2-beta.3",
54
+ "@eslint-react/eff": "1.20.2-beta.3",
55
+ "@eslint-react/shared": "1.20.2-beta.3",
56
+ "@eslint-react/jsx": "1.20.2-beta.3",
57
+ "@eslint-react/types": "1.20.2-beta.3",
58
+ "@eslint-react/var": "1.20.2-beta.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@types/react": "^19.0.1",
61
+ "@types/react": "^19.0.2",
62
62
  "@types/react-dom": "^19.0.2",
63
63
  "string-ts": "^2.2.0",
64
64
  "tsup": "^8.3.5",