eslint-plugin-react-hooks-extra 1.23.1 → 1.23.2-beta.6

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 (3) hide show
  1. package/dist/index.js +128 -116
  2. package/dist/index.mjs +129 -117
  3. package/package.json +13 -13
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ 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.23.1";
34
+ var version = "1.23.2-beta.6";
35
35
  var createRule = shared.createRuleForPlugin("hooks-extra");
36
36
  function isFromHookCall(name2, context, settings, predicate = eff.F.constTrue) {
37
37
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
@@ -128,7 +128,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
128
128
  name: RULE_NAME,
129
129
  create(context) {
130
130
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
131
- const settings = shared.decodeSettings(context.settings);
131
+ const settings = shared.getSettingsFromContext(context);
132
132
  const additionalHooks = settings.additionalHooks ?? {};
133
133
  const isUseEffectLikeCall = core.isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
134
134
  const isUseStateCall2 = core.isReactHookCallWithNameAlias("useState", context, additionalHooks.useState ?? []);
@@ -139,11 +139,11 @@ var no_direct_set_state_in_use_effect_default = createRule({
139
139
  const functionStack = [];
140
140
  const setupFunctionRef = { current: eff.O.none() };
141
141
  const setupFunctionIdentifiers = [];
142
- const indirectFunctionCalls = [];
143
- const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
144
- const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
145
- const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
146
- const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
142
+ const indFunctionCalls = [];
143
+ const indSetStateCalls = /* @__PURE__ */ new WeakMap();
144
+ const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new WeakMap();
145
+ const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
146
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
147
147
  const onSetupFunctionEnter = (node) => {
148
148
  setupFunctionRef.current = eff.O.some(node);
149
149
  };
@@ -161,47 +161,54 @@ var no_direct_set_state_in_use_effect_default = createRule({
161
161
  }
162
162
  return {
163
163
  ":function"(node) {
164
- const functionKind = getFunctionKind(node);
165
- functionStack.push([node, functionKind]);
166
- if (functionKind === "setup") onSetupFunctionEnter(node);
164
+ const kind = getFunctionKind(node);
165
+ functionStack.push({ kind, node });
166
+ if (kind === "setup") {
167
+ onSetupFunctionEnter(node);
168
+ }
167
169
  },
168
170
  ":function:exit"(node) {
169
- const [_, functionKind] = functionStack.at(-1) ?? [];
171
+ const { kind } = functionStack.at(-1) ?? {};
172
+ if (kind === "setup") {
173
+ onSetupFunctionExit(node);
174
+ }
170
175
  functionStack.pop();
171
- if (functionKind === "setup") onSetupFunctionExit(node);
172
176
  },
173
177
  CallExpression(node) {
174
- const effectFn = eff.O.getOrNull(setupFunctionRef.current);
175
- const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
176
- if (parentFn?.async) return;
178
+ const setupFunction = eff.O.getOrNull(setupFunctionRef.current);
179
+ const pEntry = functionStack.at(-1);
180
+ if (pEntry?.node.async) return;
177
181
  tsPattern.match(getCallKind(node)).with("setState", () => {
178
- if (!parentFn) return;
179
- if (parentFn !== effectFn && parentFnKind !== "immediate") {
180
- const maybeVd = AST2__namespace.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
181
- if (eff.O.isSome(maybeVd)) {
182
- const vd = maybeVd.value;
183
- const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
184
- indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
182
+ if (!pEntry) return;
183
+ switch (true) {
184
+ case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
185
+ context.report({
186
+ messageId: "noDirectSetStateInUseEffect",
187
+ node,
188
+ data: {
189
+ name: context.sourceCode.getText(node.callee)
190
+ }
191
+ });
185
192
  return;
186
193
  }
187
- const calls = indirectSetStateCalls.get(parentFn) ?? [];
188
- indirectSetStateCalls.set(parentFn, [...calls, node]);
189
- return;
194
+ default: {
195
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
196
+ if (eff.O.isNone(mbVariableDeclarator)) {
197
+ const calls = indSetStateCalls.get(pEntry.node) ?? [];
198
+ indSetStateCalls.set(pEntry.node, [...calls, node]);
199
+ return;
200
+ }
201
+ const vd = mbVariableDeclarator.value;
202
+ const prevs = indSetStateCallsInUseMemoOrCallback.get(vd.init) ?? [];
203
+ indSetStateCallsInUseMemoOrCallback.set(vd.init, [...prevs, node]);
204
+ }
190
205
  }
191
- context.report({
192
- messageId: "noDirectSetStateInUseEffect",
193
- node,
194
- data: { name: context.sourceCode.getText(node.callee) }
195
- });
196
206
  }).with("useEffect", () => {
197
- const [firstArg] = node.arguments;
198
- if (AST2__namespace.isFunction(firstArg)) return;
199
- const identifiers = AST2__namespace.getNestedIdentifiers(node);
200
- setupFunctionIdentifiers.push(...identifiers);
207
+ if (AST2__namespace.isFunction(node.arguments.at(0))) return;
208
+ setupFunctionIdentifiers.push(...AST2__namespace.getNestedIdentifiers(node));
201
209
  }).with("other", () => {
202
- const isInSetupFunction = effectFn === parentFn;
203
- if (!isInSetupFunction) return;
204
- indirectFunctionCalls.push(node);
210
+ if (pEntry?.node !== setupFunction) return;
211
+ indFunctionCalls.push(node);
205
212
  }).otherwise(eff.F.constVoid);
206
213
  },
207
214
  Identifier(node) {
@@ -212,26 +219,25 @@ var no_direct_set_state_in_use_effect_default = createRule({
212
219
  const parent = node.parent.parent;
213
220
  if (parent.type !== types.AST_NODE_TYPES.CallExpression) break;
214
221
  if (!isUseMemoCall2(parent)) break;
215
- const maybeVd = AST2__namespace.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
216
- if (eff.O.isNone(maybeVd)) break;
217
- const vd = maybeVd.value;
218
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
219
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
222
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
223
+ if (eff.O.isNone(mbVariableDeclarator)) break;
224
+ const variableDeclarator = mbVariableDeclarator.value;
225
+ const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
226
+ indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
220
227
  break;
221
228
  }
222
229
  case types.AST_NODE_TYPES.CallExpression: {
223
- const [firstArg] = node.parent.arguments;
224
- if (node !== firstArg) break;
230
+ if (node !== node.parent.arguments.at(0)) break;
225
231
  if (isUseCallbackCall2(node.parent)) {
226
- const maybeVd = AST2__namespace.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
227
- if (eff.O.isNone(maybeVd)) break;
228
- const vd = maybeVd.value;
229
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
230
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
232
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
233
+ if (eff.O.isNone(mbVariableDeclarator)) break;
234
+ const variableDeclarator = mbVariableDeclarator.value;
235
+ const prevs = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
236
+ indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
231
237
  }
232
238
  if (isUseEffectLikeCall(node.parent)) {
233
- const calls = indirectSetStateCallsAsArgs.get(node.parent) ?? [];
234
- indirectSetStateCallsAsSetups.set(node.parent, [...calls, node]);
239
+ const prevs = indSetStateCallsInUseEffectArg0.get(node.parent) ?? [];
240
+ indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
235
241
  }
236
242
  break;
237
243
  }
@@ -244,13 +250,13 @@ var no_direct_set_state_in_use_effect_default = createRule({
244
250
  case types.AST_NODE_TYPES.ArrowFunctionExpression:
245
251
  case types.AST_NODE_TYPES.FunctionDeclaration:
246
252
  case types.AST_NODE_TYPES.FunctionExpression:
247
- return indirectSetStateCalls.get(node) ?? [];
253
+ return indSetStateCalls.get(node) ?? [];
248
254
  case types.AST_NODE_TYPES.CallExpression:
249
- return indirectSetStateCallsInHooks.get(node) ?? indirectSetStateCallsAsArgs.get(node) ?? [];
255
+ return indSetStateCallsInUseMemoOrCallback.get(node) ?? indSetStateCallsInUseEffectArg0.get(node) ?? [];
250
256
  }
251
257
  return [];
252
258
  };
253
- for (const [_, calls] of indirectSetStateCallsAsSetups) {
259
+ for (const [_, calls] of indSetStateCallsInUseEffectSetup) {
254
260
  for (const call of calls) {
255
261
  context.report({
256
262
  messageId: "noDirectSetStateInUseEffect",
@@ -259,7 +265,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
259
265
  });
260
266
  }
261
267
  }
262
- for (const { callee } of indirectFunctionCalls) {
268
+ for (const { callee } of indFunctionCalls) {
263
269
  if (!("name" in callee)) continue;
264
270
  const { name: name2 } = callee;
265
271
  const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
@@ -309,9 +315,9 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
309
315
  name: RULE_NAME2,
310
316
  create(context) {
311
317
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
312
- const settings = shared.decodeSettings(context.settings);
318
+ const settings = shared.getSettingsFromContext(context);
313
319
  const additionalHooks = settings.additionalHooks ?? {};
314
- const isUseEffectLikeCall = core.isReactHookCallWithNameAlias(
320
+ const isUseLayoutEffectLikeCall = core.isReactHookCallWithNameAlias(
315
321
  "useLayoutEffect",
316
322
  context,
317
323
  additionalHooks.useLayoutEffect ?? []
@@ -324,11 +330,11 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
324
330
  const functionStack = [];
325
331
  const setupFunctionRef = { current: eff.O.none() };
326
332
  const setupFunctionIdentifiers = [];
327
- const indirectFunctionCalls = [];
328
- const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
329
- const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
330
- const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
331
- const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
333
+ const indFunctionCalls = [];
334
+ const indSetStateCalls = /* @__PURE__ */ new WeakMap();
335
+ const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new WeakMap();
336
+ const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
337
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
332
338
  const onSetupFunctionEnter = (node) => {
333
339
  setupFunctionRef.current = eff.O.some(node);
334
340
  };
@@ -336,57 +342,64 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
336
342
  setupFunctionRef.current = eff.O.filter(setupFunctionRef.current, (current) => current !== node);
337
343
  };
338
344
  function isSetupFunction(node) {
339
- return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
345
+ return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseLayoutEffectLikeCall(node.parent);
340
346
  }
341
347
  function getCallKind(node) {
342
- return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
348
+ return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
343
349
  }
344
350
  function getFunctionKind(node) {
345
351
  return tsPattern.match(node).when(isSetupFunction, () => "setup").when(AST2__namespace.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
346
352
  }
347
353
  return {
348
354
  ":function"(node) {
349
- const functionKind = getFunctionKind(node);
350
- functionStack.push([node, functionKind]);
351
- if (functionKind === "setup") onSetupFunctionEnter(node);
355
+ const kind = getFunctionKind(node);
356
+ functionStack.push({ kind, node });
357
+ if (kind === "setup") {
358
+ onSetupFunctionEnter(node);
359
+ }
352
360
  },
353
361
  ":function:exit"(node) {
354
- const [_, functionKind] = functionStack.at(-1) ?? [];
362
+ const { kind } = functionStack.at(-1) ?? {};
363
+ if (kind === "setup") {
364
+ onSetupFunctionExit(node);
365
+ }
355
366
  functionStack.pop();
356
- if (functionKind === "setup") onSetupFunctionExit(node);
357
367
  },
358
368
  CallExpression(node) {
359
- const effectFn = eff.O.getOrNull(setupFunctionRef.current);
360
- const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
361
- if (parentFn?.async) return;
369
+ const setupFunction = eff.O.getOrNull(setupFunctionRef.current);
370
+ const pEntry = functionStack.at(-1);
371
+ if (pEntry?.node.async) return;
362
372
  tsPattern.match(getCallKind(node)).with("setState", () => {
363
- if (!parentFn) return;
364
- if (parentFn !== effectFn && parentFnKind !== "immediate") {
365
- const maybeVd = AST2__namespace.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
366
- if (eff.O.isSome(maybeVd)) {
367
- const vd = maybeVd.value;
368
- const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
369
- indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
373
+ if (!pEntry) return;
374
+ switch (true) {
375
+ case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
376
+ context.report({
377
+ messageId: "noDirectSetStateInUseLayoutEffect",
378
+ node,
379
+ data: {
380
+ name: context.sourceCode.getText(node.callee)
381
+ }
382
+ });
370
383
  return;
371
384
  }
372
- const calls = indirectSetStateCalls.get(parentFn) ?? [];
373
- indirectSetStateCalls.set(parentFn, [...calls, node]);
374
- return;
385
+ default: {
386
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
387
+ if (eff.O.isNone(mbVariableDeclarator)) {
388
+ const calls = indSetStateCalls.get(pEntry.node) ?? [];
389
+ indSetStateCalls.set(pEntry.node, [...calls, node]);
390
+ return;
391
+ }
392
+ const vd = mbVariableDeclarator.value;
393
+ const prevs = indSetStateCallsInUseMemoOrCallback.get(vd.init) ?? [];
394
+ indSetStateCallsInUseMemoOrCallback.set(vd.init, [...prevs, node]);
395
+ }
375
396
  }
376
- context.report({
377
- messageId: "noDirectSetStateInUseLayoutEffect",
378
- node,
379
- data: { name: context.sourceCode.getText(node.callee) }
380
- });
381
397
  }).with("useLayoutEffect", () => {
382
- const [firstArg] = node.arguments;
383
- if (AST2__namespace.isFunction(firstArg)) return;
384
- const identifiers = AST2__namespace.getNestedIdentifiers(node);
385
- setupFunctionIdentifiers.push(...identifiers);
398
+ if (AST2__namespace.isFunction(node.arguments.at(0))) return;
399
+ setupFunctionIdentifiers.push(...AST2__namespace.getNestedIdentifiers(node));
386
400
  }).with("other", () => {
387
- const isInSetupFunction = effectFn === parentFn;
388
- if (!isInSetupFunction) return;
389
- indirectFunctionCalls.push(node);
401
+ if (pEntry?.node !== setupFunction) return;
402
+ indFunctionCalls.push(node);
390
403
  }).otherwise(eff.F.constVoid);
391
404
  },
392
405
  Identifier(node) {
@@ -397,26 +410,25 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
397
410
  const parent = node.parent.parent;
398
411
  if (parent.type !== types.AST_NODE_TYPES.CallExpression) break;
399
412
  if (!isUseMemoCall2(parent)) break;
400
- const maybeVd = AST2__namespace.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
401
- if (eff.O.isNone(maybeVd)) break;
402
- const vd = maybeVd.value;
403
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
404
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
413
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
414
+ if (eff.O.isNone(mbVariableDeclarator)) break;
415
+ const variableDeclarator = mbVariableDeclarator.value;
416
+ const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
417
+ indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
405
418
  break;
406
419
  }
407
420
  case types.AST_NODE_TYPES.CallExpression: {
408
- const [firstArg] = node.parent.arguments;
409
- if (node !== firstArg) break;
421
+ if (node !== node.parent.arguments.at(0)) break;
410
422
  if (isUseCallbackCall2(node.parent)) {
411
- const maybeVd = AST2__namespace.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
412
- if (eff.O.isNone(maybeVd)) break;
413
- const vd = maybeVd.value;
414
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
415
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
423
+ const mbVariableDeclarator = AST2__namespace.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
424
+ if (eff.O.isNone(mbVariableDeclarator)) break;
425
+ const variableDeclarator = mbVariableDeclarator.value;
426
+ const prevs = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
427
+ indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
416
428
  }
417
- if (isUseEffectLikeCall(node.parent)) {
418
- const calls = indirectSetStateCallsAsArgs.get(node.parent) ?? [];
419
- indirectSetStateCallsAsSetups.set(node.parent, [...calls, node]);
429
+ if (isUseLayoutEffectLikeCall(node.parent)) {
430
+ const prevs = indSetStateCallsInUseLayoutEffectArg0.get(node.parent) ?? [];
431
+ indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
420
432
  }
421
433
  break;
422
434
  }
@@ -429,13 +441,13 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
429
441
  case types.AST_NODE_TYPES.ArrowFunctionExpression:
430
442
  case types.AST_NODE_TYPES.FunctionDeclaration:
431
443
  case types.AST_NODE_TYPES.FunctionExpression:
432
- return indirectSetStateCalls.get(node) ?? [];
444
+ return indSetStateCalls.get(node) ?? [];
433
445
  case types.AST_NODE_TYPES.CallExpression:
434
- return indirectSetStateCallsInHooks.get(node) ?? indirectSetStateCallsAsArgs.get(node) ?? [];
446
+ return indSetStateCallsInUseMemoOrCallback.get(node) ?? indSetStateCallsInUseLayoutEffectArg0.get(node) ?? [];
435
447
  }
436
448
  return [];
437
449
  };
438
- for (const [_, calls] of indirectSetStateCallsAsSetups) {
450
+ for (const [_, calls] of indSetStateCallsInUseLayoutEffectSetup) {
439
451
  for (const call of calls) {
440
452
  context.report({
441
453
  messageId: "noDirectSetStateInUseLayoutEffect",
@@ -444,7 +456,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
444
456
  });
445
457
  }
446
458
  }
447
- for (const { callee } of indirectFunctionCalls) {
459
+ for (const { callee } of indFunctionCalls) {
448
460
  if (!("name" in callee)) continue;
449
461
  const { name: name2 } = callee;
450
462
  const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
@@ -494,7 +506,7 @@ var no_unnecessary_use_callback_default = createRule({
494
506
  name: RULE_NAME3,
495
507
  create(context) {
496
508
  if (!context.sourceCode.text.includes("use")) return {};
497
- const alias = shared.decodeSettings(context.settings).additionalHooks?.useCallback ?? [];
509
+ const alias = shared.getSettingsFromContext(context).additionalHooks?.useCallback ?? [];
498
510
  return {
499
511
  CallExpression(node) {
500
512
  if (!core.isReactHookCall(node)) return;
@@ -563,7 +575,7 @@ var no_unnecessary_use_memo_default = createRule({
563
575
  name: RULE_NAME4,
564
576
  create(context) {
565
577
  if (!context.sourceCode.text.includes("use")) return {};
566
- const alias = shared.decodeSettings(context.settings).additionalHooks?.useMemo ?? [];
578
+ const alias = shared.getSettingsFromContext(context).additionalHooks?.useMemo ?? [];
567
579
  return {
568
580
  CallExpression(node) {
569
581
  if (!core.isReactHookCall(node)) return;
@@ -682,7 +694,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
682
694
  name: RULE_NAME6,
683
695
  create(context) {
684
696
  if (!context.sourceCode.text.includes("use")) return {};
685
- const alias = shared.decodeSettings(context.settings).additionalHooks?.useState ?? [];
697
+ const alias = shared.getSettingsFromContext(context).additionalHooks?.useState ?? [];
686
698
  return {
687
699
  CallExpression(node) {
688
700
  if (!core.isReactHookCall(node)) return;
package/dist/index.mjs CHANGED
@@ -1,14 +1,14 @@
1
1
  import * as AST2 from '@eslint-react/ast';
2
2
  import { isReactHookCallWithNameAlias, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, useHookCollector, isUseStateCall, isReactHookName } from '@eslint-react/core';
3
3
  import { O, F } from '@eslint-react/eff';
4
- import { createRuleForPlugin, decodeSettings } from '@eslint-react/shared';
4
+ import { createRuleForPlugin, getSettingsFromContext } from '@eslint-react/shared';
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.23.1";
11
+ var version = "1.23.2-beta.6";
12
12
  var createRule = createRuleForPlugin("hooks-extra");
13
13
  function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
14
14
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
@@ -105,7 +105,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
105
105
  name: RULE_NAME,
106
106
  create(context) {
107
107
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
108
- const settings = decodeSettings(context.settings);
108
+ const settings = getSettingsFromContext(context);
109
109
  const additionalHooks = settings.additionalHooks ?? {};
110
110
  const isUseEffectLikeCall = isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
111
111
  const isUseStateCall2 = isReactHookCallWithNameAlias("useState", context, additionalHooks.useState ?? []);
@@ -116,11 +116,11 @@ var no_direct_set_state_in_use_effect_default = createRule({
116
116
  const functionStack = [];
117
117
  const setupFunctionRef = { current: O.none() };
118
118
  const setupFunctionIdentifiers = [];
119
- const indirectFunctionCalls = [];
120
- const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
121
- const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
122
- const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
123
- const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
119
+ const indFunctionCalls = [];
120
+ const indSetStateCalls = /* @__PURE__ */ new WeakMap();
121
+ const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new WeakMap();
122
+ const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
123
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
124
124
  const onSetupFunctionEnter = (node) => {
125
125
  setupFunctionRef.current = O.some(node);
126
126
  };
@@ -138,47 +138,54 @@ var no_direct_set_state_in_use_effect_default = createRule({
138
138
  }
139
139
  return {
140
140
  ":function"(node) {
141
- const functionKind = getFunctionKind(node);
142
- functionStack.push([node, functionKind]);
143
- if (functionKind === "setup") onSetupFunctionEnter(node);
141
+ const kind = getFunctionKind(node);
142
+ functionStack.push({ kind, node });
143
+ if (kind === "setup") {
144
+ onSetupFunctionEnter(node);
145
+ }
144
146
  },
145
147
  ":function:exit"(node) {
146
- const [_, functionKind] = functionStack.at(-1) ?? [];
148
+ const { kind } = functionStack.at(-1) ?? {};
149
+ if (kind === "setup") {
150
+ onSetupFunctionExit(node);
151
+ }
147
152
  functionStack.pop();
148
- if (functionKind === "setup") onSetupFunctionExit(node);
149
153
  },
150
154
  CallExpression(node) {
151
- const effectFn = O.getOrNull(setupFunctionRef.current);
152
- const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
153
- if (parentFn?.async) return;
155
+ const setupFunction = O.getOrNull(setupFunctionRef.current);
156
+ const pEntry = functionStack.at(-1);
157
+ if (pEntry?.node.async) return;
154
158
  match(getCallKind(node)).with("setState", () => {
155
- if (!parentFn) return;
156
- if (parentFn !== effectFn && parentFnKind !== "immediate") {
157
- const maybeVd = AST2.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
158
- if (O.isSome(maybeVd)) {
159
- const vd = maybeVd.value;
160
- const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
161
- indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
159
+ if (!pEntry) return;
160
+ switch (true) {
161
+ case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
162
+ context.report({
163
+ messageId: "noDirectSetStateInUseEffect",
164
+ node,
165
+ data: {
166
+ name: context.sourceCode.getText(node.callee)
167
+ }
168
+ });
162
169
  return;
163
170
  }
164
- const calls = indirectSetStateCalls.get(parentFn) ?? [];
165
- indirectSetStateCalls.set(parentFn, [...calls, node]);
166
- return;
171
+ default: {
172
+ const mbVariableDeclarator = AST2.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
173
+ if (O.isNone(mbVariableDeclarator)) {
174
+ const calls = indSetStateCalls.get(pEntry.node) ?? [];
175
+ indSetStateCalls.set(pEntry.node, [...calls, node]);
176
+ return;
177
+ }
178
+ const vd = mbVariableDeclarator.value;
179
+ const prevs = indSetStateCallsInUseMemoOrCallback.get(vd.init) ?? [];
180
+ indSetStateCallsInUseMemoOrCallback.set(vd.init, [...prevs, node]);
181
+ }
167
182
  }
168
- context.report({
169
- messageId: "noDirectSetStateInUseEffect",
170
- node,
171
- data: { name: context.sourceCode.getText(node.callee) }
172
- });
173
183
  }).with("useEffect", () => {
174
- const [firstArg] = node.arguments;
175
- if (AST2.isFunction(firstArg)) return;
176
- const identifiers = AST2.getNestedIdentifiers(node);
177
- setupFunctionIdentifiers.push(...identifiers);
184
+ if (AST2.isFunction(node.arguments.at(0))) return;
185
+ setupFunctionIdentifiers.push(...AST2.getNestedIdentifiers(node));
178
186
  }).with("other", () => {
179
- const isInSetupFunction = effectFn === parentFn;
180
- if (!isInSetupFunction) return;
181
- indirectFunctionCalls.push(node);
187
+ if (pEntry?.node !== setupFunction) return;
188
+ indFunctionCalls.push(node);
182
189
  }).otherwise(F.constVoid);
183
190
  },
184
191
  Identifier(node) {
@@ -189,26 +196,25 @@ var no_direct_set_state_in_use_effect_default = createRule({
189
196
  const parent = node.parent.parent;
190
197
  if (parent.type !== AST_NODE_TYPES.CallExpression) break;
191
198
  if (!isUseMemoCall2(parent)) break;
192
- const maybeVd = AST2.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
193
- if (O.isNone(maybeVd)) break;
194
- const vd = maybeVd.value;
195
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
196
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
199
+ const mbVariableDeclarator = AST2.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
200
+ if (O.isNone(mbVariableDeclarator)) break;
201
+ const variableDeclarator = mbVariableDeclarator.value;
202
+ const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
203
+ indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
197
204
  break;
198
205
  }
199
206
  case AST_NODE_TYPES.CallExpression: {
200
- const [firstArg] = node.parent.arguments;
201
- if (node !== firstArg) break;
207
+ if (node !== node.parent.arguments.at(0)) break;
202
208
  if (isUseCallbackCall2(node.parent)) {
203
- const maybeVd = AST2.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
204
- if (O.isNone(maybeVd)) break;
205
- const vd = maybeVd.value;
206
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
207
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
209
+ const mbVariableDeclarator = AST2.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
210
+ if (O.isNone(mbVariableDeclarator)) break;
211
+ const variableDeclarator = mbVariableDeclarator.value;
212
+ const prevs = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
213
+ indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
208
214
  }
209
215
  if (isUseEffectLikeCall(node.parent)) {
210
- const calls = indirectSetStateCallsAsArgs.get(node.parent) ?? [];
211
- indirectSetStateCallsAsSetups.set(node.parent, [...calls, node]);
216
+ const prevs = indSetStateCallsInUseEffectArg0.get(node.parent) ?? [];
217
+ indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
212
218
  }
213
219
  break;
214
220
  }
@@ -221,13 +227,13 @@ var no_direct_set_state_in_use_effect_default = createRule({
221
227
  case AST_NODE_TYPES.ArrowFunctionExpression:
222
228
  case AST_NODE_TYPES.FunctionDeclaration:
223
229
  case AST_NODE_TYPES.FunctionExpression:
224
- return indirectSetStateCalls.get(node) ?? [];
230
+ return indSetStateCalls.get(node) ?? [];
225
231
  case AST_NODE_TYPES.CallExpression:
226
- return indirectSetStateCallsInHooks.get(node) ?? indirectSetStateCallsAsArgs.get(node) ?? [];
232
+ return indSetStateCallsInUseMemoOrCallback.get(node) ?? indSetStateCallsInUseEffectArg0.get(node) ?? [];
227
233
  }
228
234
  return [];
229
235
  };
230
- for (const [_, calls] of indirectSetStateCallsAsSetups) {
236
+ for (const [_, calls] of indSetStateCallsInUseEffectSetup) {
231
237
  for (const call of calls) {
232
238
  context.report({
233
239
  messageId: "noDirectSetStateInUseEffect",
@@ -236,7 +242,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
236
242
  });
237
243
  }
238
244
  }
239
- for (const { callee } of indirectFunctionCalls) {
245
+ for (const { callee } of indFunctionCalls) {
240
246
  if (!("name" in callee)) continue;
241
247
  const { name: name2 } = callee;
242
248
  const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
@@ -286,9 +292,9 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
286
292
  name: RULE_NAME2,
287
293
  create(context) {
288
294
  if (!/use\w*Effect/u.test(context.sourceCode.text)) return {};
289
- const settings = decodeSettings(context.settings);
295
+ const settings = getSettingsFromContext(context);
290
296
  const additionalHooks = settings.additionalHooks ?? {};
291
- const isUseEffectLikeCall = isReactHookCallWithNameAlias(
297
+ const isUseLayoutEffectLikeCall = isReactHookCallWithNameAlias(
292
298
  "useLayoutEffect",
293
299
  context,
294
300
  additionalHooks.useLayoutEffect ?? []
@@ -301,11 +307,11 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
301
307
  const functionStack = [];
302
308
  const setupFunctionRef = { current: O.none() };
303
309
  const setupFunctionIdentifiers = [];
304
- const indirectFunctionCalls = [];
305
- const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
306
- const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
307
- const indirectSetStateCallsAsSetups = /* @__PURE__ */ new Map();
308
- const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
310
+ const indFunctionCalls = [];
311
+ const indSetStateCalls = /* @__PURE__ */ new WeakMap();
312
+ const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new WeakMap();
313
+ const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
314
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
309
315
  const onSetupFunctionEnter = (node) => {
310
316
  setupFunctionRef.current = O.some(node);
311
317
  };
@@ -313,57 +319,64 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
313
319
  setupFunctionRef.current = O.filter(setupFunctionRef.current, (current) => current !== node);
314
320
  };
315
321
  function isSetupFunction(node) {
316
- return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
322
+ return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseLayoutEffectLikeCall(node.parent);
317
323
  }
318
324
  function getCallKind(node) {
319
- return match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
325
+ return match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
320
326
  }
321
327
  function getFunctionKind(node) {
322
328
  return match(node).when(isSetupFunction, () => "setup").when(AST2.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
323
329
  }
324
330
  return {
325
331
  ":function"(node) {
326
- const functionKind = getFunctionKind(node);
327
- functionStack.push([node, functionKind]);
328
- if (functionKind === "setup") onSetupFunctionEnter(node);
332
+ const kind = getFunctionKind(node);
333
+ functionStack.push({ kind, node });
334
+ if (kind === "setup") {
335
+ onSetupFunctionEnter(node);
336
+ }
329
337
  },
330
338
  ":function:exit"(node) {
331
- const [_, functionKind] = functionStack.at(-1) ?? [];
339
+ const { kind } = functionStack.at(-1) ?? {};
340
+ if (kind === "setup") {
341
+ onSetupFunctionExit(node);
342
+ }
332
343
  functionStack.pop();
333
- if (functionKind === "setup") onSetupFunctionExit(node);
334
344
  },
335
345
  CallExpression(node) {
336
- const effectFn = O.getOrNull(setupFunctionRef.current);
337
- const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
338
- if (parentFn?.async) return;
346
+ const setupFunction = O.getOrNull(setupFunctionRef.current);
347
+ const pEntry = functionStack.at(-1);
348
+ if (pEntry?.node.async) return;
339
349
  match(getCallKind(node)).with("setState", () => {
340
- if (!parentFn) return;
341
- if (parentFn !== effectFn && parentFnKind !== "immediate") {
342
- const maybeVd = AST2.traverseUpGuard(node, isVariableDeclaratorFromHookCall);
343
- if (O.isSome(maybeVd)) {
344
- const vd = maybeVd.value;
345
- const calls2 = indirectSetStateCallsInHooks.get(vd.init) ?? [];
346
- indirectSetStateCallsInHooks.set(vd.init, [...calls2, node]);
350
+ if (!pEntry) return;
351
+ switch (true) {
352
+ case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
353
+ context.report({
354
+ messageId: "noDirectSetStateInUseLayoutEffect",
355
+ node,
356
+ data: {
357
+ name: context.sourceCode.getText(node.callee)
358
+ }
359
+ });
347
360
  return;
348
361
  }
349
- const calls = indirectSetStateCalls.get(parentFn) ?? [];
350
- indirectSetStateCalls.set(parentFn, [...calls, node]);
351
- return;
362
+ default: {
363
+ const mbVariableDeclarator = AST2.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
364
+ if (O.isNone(mbVariableDeclarator)) {
365
+ const calls = indSetStateCalls.get(pEntry.node) ?? [];
366
+ indSetStateCalls.set(pEntry.node, [...calls, node]);
367
+ return;
368
+ }
369
+ const vd = mbVariableDeclarator.value;
370
+ const prevs = indSetStateCallsInUseMemoOrCallback.get(vd.init) ?? [];
371
+ indSetStateCallsInUseMemoOrCallback.set(vd.init, [...prevs, node]);
372
+ }
352
373
  }
353
- context.report({
354
- messageId: "noDirectSetStateInUseLayoutEffect",
355
- node,
356
- data: { name: context.sourceCode.getText(node.callee) }
357
- });
358
374
  }).with("useLayoutEffect", () => {
359
- const [firstArg] = node.arguments;
360
- if (AST2.isFunction(firstArg)) return;
361
- const identifiers = AST2.getNestedIdentifiers(node);
362
- setupFunctionIdentifiers.push(...identifiers);
375
+ if (AST2.isFunction(node.arguments.at(0))) return;
376
+ setupFunctionIdentifiers.push(...AST2.getNestedIdentifiers(node));
363
377
  }).with("other", () => {
364
- const isInSetupFunction = effectFn === parentFn;
365
- if (!isInSetupFunction) return;
366
- indirectFunctionCalls.push(node);
378
+ if (pEntry?.node !== setupFunction) return;
379
+ indFunctionCalls.push(node);
367
380
  }).otherwise(F.constVoid);
368
381
  },
369
382
  Identifier(node) {
@@ -374,26 +387,25 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
374
387
  const parent = node.parent.parent;
375
388
  if (parent.type !== AST_NODE_TYPES.CallExpression) break;
376
389
  if (!isUseMemoCall2(parent)) break;
377
- const maybeVd = AST2.traverseUpGuard(parent, isVariableDeclaratorFromHookCall);
378
- if (O.isNone(maybeVd)) break;
379
- const vd = maybeVd.value;
380
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
381
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
390
+ const mbVariableDeclarator = AST2.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
391
+ if (O.isNone(mbVariableDeclarator)) break;
392
+ const variableDeclarator = mbVariableDeclarator.value;
393
+ const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
394
+ indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
382
395
  break;
383
396
  }
384
397
  case AST_NODE_TYPES.CallExpression: {
385
- const [firstArg] = node.parent.arguments;
386
- if (node !== firstArg) break;
398
+ if (node !== node.parent.arguments.at(0)) break;
387
399
  if (isUseCallbackCall2(node.parent)) {
388
- const maybeVd = AST2.traverseUpGuard(node.parent, isVariableDeclaratorFromHookCall);
389
- if (O.isNone(maybeVd)) break;
390
- const vd = maybeVd.value;
391
- const calls = indirectSetStateCallsAsArgs.get(vd.init) ?? [];
392
- indirectSetStateCallsAsArgs.set(vd.init, [...calls, node]);
400
+ const mbVariableDeclarator = AST2.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
401
+ if (O.isNone(mbVariableDeclarator)) break;
402
+ const variableDeclarator = mbVariableDeclarator.value;
403
+ const prevs = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
404
+ indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
393
405
  }
394
- if (isUseEffectLikeCall(node.parent)) {
395
- const calls = indirectSetStateCallsAsArgs.get(node.parent) ?? [];
396
- indirectSetStateCallsAsSetups.set(node.parent, [...calls, node]);
406
+ if (isUseLayoutEffectLikeCall(node.parent)) {
407
+ const prevs = indSetStateCallsInUseLayoutEffectArg0.get(node.parent) ?? [];
408
+ indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
397
409
  }
398
410
  break;
399
411
  }
@@ -406,13 +418,13 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
406
418
  case AST_NODE_TYPES.ArrowFunctionExpression:
407
419
  case AST_NODE_TYPES.FunctionDeclaration:
408
420
  case AST_NODE_TYPES.FunctionExpression:
409
- return indirectSetStateCalls.get(node) ?? [];
421
+ return indSetStateCalls.get(node) ?? [];
410
422
  case AST_NODE_TYPES.CallExpression:
411
- return indirectSetStateCallsInHooks.get(node) ?? indirectSetStateCallsAsArgs.get(node) ?? [];
423
+ return indSetStateCallsInUseMemoOrCallback.get(node) ?? indSetStateCallsInUseLayoutEffectArg0.get(node) ?? [];
412
424
  }
413
425
  return [];
414
426
  };
415
- for (const [_, calls] of indirectSetStateCallsAsSetups) {
427
+ for (const [_, calls] of indSetStateCallsInUseLayoutEffectSetup) {
416
428
  for (const call of calls) {
417
429
  context.report({
418
430
  messageId: "noDirectSetStateInUseLayoutEffect",
@@ -421,7 +433,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
421
433
  });
422
434
  }
423
435
  }
424
- for (const { callee } of indirectFunctionCalls) {
436
+ for (const { callee } of indFunctionCalls) {
425
437
  if (!("name" in callee)) continue;
426
438
  const { name: name2 } = callee;
427
439
  const setStateCalls = getSetStateCalls(name2, context.sourceCode.getScope(callee));
@@ -471,7 +483,7 @@ var no_unnecessary_use_callback_default = createRule({
471
483
  name: RULE_NAME3,
472
484
  create(context) {
473
485
  if (!context.sourceCode.text.includes("use")) return {};
474
- const alias = decodeSettings(context.settings).additionalHooks?.useCallback ?? [];
486
+ const alias = getSettingsFromContext(context).additionalHooks?.useCallback ?? [];
475
487
  return {
476
488
  CallExpression(node) {
477
489
  if (!isReactHookCall(node)) return;
@@ -540,7 +552,7 @@ var no_unnecessary_use_memo_default = createRule({
540
552
  name: RULE_NAME4,
541
553
  create(context) {
542
554
  if (!context.sourceCode.text.includes("use")) return {};
543
- const alias = decodeSettings(context.settings).additionalHooks?.useMemo ?? [];
555
+ const alias = getSettingsFromContext(context).additionalHooks?.useMemo ?? [];
544
556
  return {
545
557
  CallExpression(node) {
546
558
  if (!isReactHookCall(node)) return;
@@ -659,7 +671,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
659
671
  name: RULE_NAME6,
660
672
  create(context) {
661
673
  if (!context.sourceCode.text.includes("use")) return {};
662
- const alias = decodeSettings(context.settings).additionalHooks?.useState ?? [];
674
+ const alias = getSettingsFromContext(context).additionalHooks?.useState ?? [];
663
675
  return {
664
676
  CallExpression(node) {
665
677
  if (!isReactHookCall(node)) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.23.1",
3
+ "version": "1.23.2-beta.6",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -42,22 +42,22 @@
42
42
  "./package.json"
43
43
  ],
44
44
  "dependencies": {
45
- "@typescript-eslint/scope-manager": "^8.19.0",
46
- "@typescript-eslint/type-utils": "^8.19.0",
47
- "@typescript-eslint/types": "^8.19.0",
48
- "@typescript-eslint/utils": "^8.19.0",
45
+ "@typescript-eslint/scope-manager": "^8.19.1",
46
+ "@typescript-eslint/type-utils": "^8.19.1",
47
+ "@typescript-eslint/types": "^8.19.1",
48
+ "@typescript-eslint/utils": "^8.19.1",
49
49
  "string-ts": "^2.2.0",
50
50
  "ts-pattern": "^5.6.0",
51
- "@eslint-react/ast": "1.23.1",
52
- "@eslint-react/eff": "1.23.1",
53
- "@eslint-react/core": "1.23.1",
54
- "@eslint-react/jsx": "1.23.1",
55
- "@eslint-react/shared": "1.23.1",
56
- "@eslint-react/var": "1.23.1",
57
- "@eslint-react/types": "1.23.1"
51
+ "@eslint-react/ast": "1.23.2-beta.6",
52
+ "@eslint-react/core": "1.23.2-beta.6",
53
+ "@eslint-react/jsx": "1.23.2-beta.6",
54
+ "@eslint-react/eff": "1.23.2-beta.6",
55
+ "@eslint-react/shared": "1.23.2-beta.6",
56
+ "@eslint-react/types": "1.23.2-beta.6",
57
+ "@eslint-react/var": "1.23.2-beta.6"
58
58
  },
59
59
  "devDependencies": {
60
- "@types/react": "^19.0.2",
60
+ "@types/react": "^19.0.3",
61
61
  "@types/react-dom": "^19.0.2",
62
62
  "tsup": "^8.3.5",
63
63
  "@workspace/configs": "0.0.0"