@eslint-react/var 5.24.1 → 5.24.2

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 +4 -834
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -5,44 +5,6 @@ import { DefinitionType } from "@typescript-eslint/scope-manager";
5
5
  import { P, isMatching } from "ts-pattern";
6
6
 
7
7
  //#region ../../.pkgs/eff/dist/index.js
8
- /**
9
- * Applies a `pipe` method's variadic arguments to an initial value from left
10
- * to right.
11
- *
12
- * **When to use**
13
- *
14
- * Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
15
- * object.
16
- *
17
- * **Details**
18
- *
19
- * This helper is intended for implementing `Pipeable.pipe` methods that
20
- * receive JavaScript's `arguments` object. With no functions it returns the
21
- * original value; otherwise it feeds each result into the next function.
22
- *
23
- * **Example** (Implementing a pipe method)
24
- *
25
- * ```ts
26
- * import { Pipeable } from "effect"
27
- *
28
- * class NumberBox {
29
- * constructor(readonly value: number) {}
30
- *
31
- * pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
32
- * return Pipeable.pipeArguments(this.value, arguments) as number
33
- * }
34
- * }
35
- *
36
- * const result = new NumberBox(5).pipe(
37
- * (n) => n + 2,
38
- * (n) => n * 3
39
- * )
40
- * result // => 21
41
- * ```
42
- *
43
- * @category combinators
44
- * @since 2.0.0
45
- */
46
8
  const pipeArguments = (self, args) => {
47
9
  switch (args.length) {
48
10
  case 0: return self;
@@ -62,100 +24,14 @@ const pipeArguments = (self, args) => {
62
24
  }
63
25
  }
64
26
  };
65
- /**
66
- * Reusable prototype that implements `Pipeable.pipe`.
67
- *
68
- * **When to use**
69
- *
70
- * Use when classes or object prototypes can reuse this value when they need the
71
- * standard pipe implementation backed by `pipeArguments`.
72
- *
73
- * @category prototypes
74
- * @since 3.15.0
75
- */
76
27
  const Prototype = { pipe() {
77
28
  return pipeArguments(this, arguments);
78
29
  } };
79
- /**
80
- * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
81
- * method.
82
- *
83
- * **When to use**
84
- *
85
- * Use when you need to define a class that supports Effect-style method
86
- * chaining through `.pipe(...)`.
87
- *
88
- * @category constructors
89
- * @since 3.15.0
90
- */
91
30
  const Class = (function() {
92
31
  function PipeableBase() {}
93
32
  PipeableBase.prototype = Prototype;
94
33
  return PipeableBase;
95
34
  })();
96
- /**
97
- * Creates a function that can be called in data-first style or data-last
98
- * (`pipe`-friendly) style.
99
- *
100
- * **When to use**
101
- *
102
- * Use to expose one implementation through both direct and `pipe`-friendly
103
- * call styles.
104
- *
105
- * **Details**
106
- *
107
- * Pass either the arity of the uncurried function or a predicate that decides
108
- * whether the current call is data-first. Arity is the common case. Use a
109
- * predicate when optional arguments make arity ambiguous.
110
- *
111
- * **Example** (Selecting data-first or data-last style by arity)
112
- *
113
- * ```ts
114
- * import { Function, pipe } from "effect"
115
- *
116
- * const sum = Function.dual<
117
- * (that: number) => (self: number) => number,
118
- * (self: number, that: number) => number
119
- * >(2, (self, that) => self + that)
120
- *
121
- * sum(2, 3) // => 5
122
- * pipe(2, sum(3)) // => 5
123
- * ```
124
- *
125
- * **Example** (Defining overloads with call signatures)
126
- *
127
- * ```ts
128
- * import { Function, pipe } from "effect"
129
- *
130
- * const sum: {
131
- * (that: number): (self: number) => number
132
- * (self: number, that: number): number
133
- * } = Function.dual(2, (self: number, that: number): number => self + that)
134
- *
135
- * sum(2, 3) // => 5
136
- * pipe(2, sum(3)) // => 5
137
- * ```
138
- *
139
- * **Example** (Selecting data-first or data-last style with a predicate)
140
- *
141
- * ```ts
142
- * import { Function, pipe } from "effect"
143
- *
144
- * const sum = Function.dual<
145
- * (that: number) => (self: number) => number,
146
- * (self: number, that: number) => number
147
- * >(
148
- * (args) => args.length === 2,
149
- * (self, that) => self + that
150
- * )
151
- *
152
- * sum(2, 3) // => 5
153
- * pipe(2, sum(3)) // => 5
154
- * ```
155
- *
156
- * @category combinators
157
- * @since 2.0.0
158
- */
159
35
  const dual = function(arity, body) {
160
36
  if (typeof arity === "function") return function() {
161
37
  return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
@@ -184,529 +60,31 @@ const dual = function(arity, body) {
184
60
  };
185
61
  }
186
62
  };
187
- /**
188
- * Returns its input argument unchanged.
189
- *
190
- * **When to use**
191
- *
192
- * Use to return a value unchanged where a function is required.
193
- *
194
- * **Example** (Returning the same value)
195
- *
196
- * ```ts
197
- * import { identity } from "effect"
198
- *
199
- * identity(5) // => 5
200
- * ```
201
- *
202
- * @category combinators
203
- * @since 2.0.0
204
- */
205
63
  const identity = (a) => a;
206
- /**
207
- * Returns the input value with a different static type.
208
- *
209
- * **When to use**
210
- *
211
- * Use when you need an explicit type-level cast and accept that the value is
212
- * returned unchanged at runtime.
213
- *
214
- * **Gotchas**
215
- *
216
- * This is a type-level cast only; it performs no runtime validation or
217
- * conversion.
218
- *
219
- * @see {@link satisfies} for checking assignability without changing the resulting type
220
- *
221
- * @category utility types
222
- * @since 4.0.0
223
- */
224
64
  const cast = identity;
225
- /**
226
- * Creates a zero-argument function that always returns the provided value.
227
- *
228
- * **When to use**
229
- *
230
- * Use when you need a thunk or callback that returns the same value on every
231
- * invocation.
232
- *
233
- * **Example** (Creating a constant thunk)
234
- *
235
- * ```ts
236
- * import { Function } from "effect"
237
- *
238
- * const constNull = Function.constant(null)
239
- *
240
- * constNull() // => null
241
- * constNull() // => null
242
- * ```
243
- *
244
- * @category constructors
245
- * @since 2.0.0
246
- */
247
65
  const constant = (value) => () => value;
248
- /**
249
- * Returns `true` when called.
250
- *
251
- * **When to use**
252
- *
253
- * Use when you need a thunk that returns `true` on every invocation.
254
- *
255
- * **Example** (Returning true from a thunk)
256
- *
257
- * ```ts
258
- * import { Function } from "effect"
259
- *
260
- * Function.constTrue() // => true
261
- * ```
262
- *
263
- * @category constants
264
- * @since 2.0.0
265
- */
266
66
  const constTrue = constant(true);
267
- /**
268
- * Returns `false` when called.
269
- *
270
- * **When to use**
271
- *
272
- * Use when you need a thunk that returns `false` on every invocation.
273
- *
274
- * **Example** (Returning false from a thunk)
275
- *
276
- * ```ts
277
- * import { Function } from "effect"
278
- *
279
- * Function.constFalse() // => false
280
- * ```
281
- *
282
- * @category constants
283
- * @since 2.0.0
284
- */
285
67
  const constFalse = constant(false);
286
- /**
287
- * Returns `null` when called.
288
- *
289
- * **When to use**
290
- *
291
- * Use when you need a thunk that returns `null` on every invocation.
292
- *
293
- * **Example** (Returning null from a thunk)
294
- *
295
- * ```ts
296
- * import { Function } from "effect"
297
- *
298
- * Function.constNull() // => null
299
- * ```
300
- *
301
- * @category constants
302
- * @since 2.0.0
303
- */
304
68
  const constNull = constant(null);
305
- /**
306
- * Returns `undefined` when called.
307
- *
308
- * **When to use**
309
- *
310
- * Use when you need a thunk that returns `undefined` on every invocation.
311
- *
312
- * **Example** (Returning undefined from a thunk)
313
- *
314
- * ```ts
315
- * import { Function } from "effect"
316
- *
317
- * Function.constUndefined() // => undefined
318
- * ```
319
- *
320
- * @category constants
321
- * @since 2.0.0
322
- */
323
69
  const constUndefined = constant(void 0);
324
- /**
325
- * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
326
- * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
327
- *
328
- * **When to use**
329
- *
330
- * Use to compose exactly two unary functions into a reusable unary function.
331
- *
332
- * **Example** (Composing two functions)
333
- *
334
- * ```ts
335
- * import { Function } from "effect"
336
- *
337
- * const increment = (n: number) => n + 1
338
- * const square = (n: number) => n * n
339
- *
340
- * Function.compose(increment, square)(2) // => 9
341
- * ```
342
- *
343
- * @see {@link flow} for composing a left-to-right sequence of functions
344
- * @see {@link pipe} for applying a value through a left-to-right sequence immediately
345
- *
346
- * @category combinators
347
- * @since 2.0.0
348
- */
349
70
  const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
350
- /**
351
- * Marks an impossible branch by accepting a `never` value and returning any
352
- * type.
353
- *
354
- * **When to use**
355
- *
356
- * Use when you need a return value in a branch that exhaustive checks prove
357
- * cannot be reached.
358
- *
359
- * **Gotchas**
360
- *
361
- * Calling `absurd` throws, because a value of type `never` should be
362
- * impossible at runtime.
363
- *
364
- * **Example** (Handling impossible values)
365
- *
366
- * ```ts
367
- * import { absurd } from "effect"
368
- *
369
- * const handleNever = (value: never) => {
370
- * return absurd(value) // This will throw an error if called
371
- * }
372
- * ```
373
- *
374
- * @category utility types
375
- * @since 2.0.0
376
- */
377
71
  const absurd = (_) => {
378
72
  throw new Error("Called `absurd` function which should be uncallable");
379
73
  };
380
- /**
381
- * Creates a compile-time placeholder for a value of any type.
382
- *
383
- * **When to use**
384
- *
385
- * Use as a temporary typed placeholder while developing incomplete code.
386
- *
387
- * **Gotchas**
388
- *
389
- * `hole` is intended for temporary development use. If the placeholder is
390
- * evaluated at runtime, it throws.
391
- *
392
- * **Example** (Creating a development placeholder)
393
- *
394
- * ```ts
395
- * import { hole } from "effect"
396
- *
397
- * // Intentionally not called: `hole` throws if the placeholder is evaluated.
398
- * const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
399
- * id,
400
- * name: hole<string>()
401
- * })
402
- *
403
- * ```
404
- *
405
- * @category utility types
406
- * @since 2.0.0
407
- */
408
74
  const hole = cast(absurd);
409
- /**
410
- * Creates a predicate that returns `true` only if both predicates are `true`.
411
- *
412
- * **When to use**
413
- *
414
- * Use when you want to combine `Predicate`s with AND, accepting values that
415
- * satisfy multiple conditions, including refinements that narrow to an
416
- * intersection.
417
- *
418
- * **Details**
419
- *
420
- * Evaluation short-circuits on the first `false`. For refinements, the output
421
- * type is an intersection.
422
- *
423
- * **Example** (Checking both conditions)
424
- *
425
- * ```ts
426
- * import { Predicate } from "effect"
427
- *
428
- * const hasAAndB = Predicate.and(
429
- * Predicate.hasProperty("a"),
430
- * Predicate.hasProperty("b")
431
- * )
432
- *
433
- * const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
434
- * if (hasAAndB(input)) {
435
- * // input has both properties at this point
436
- * const a = input.a
437
- * const b = input.b
438
- *
439
- * const values = [a, b] // => [1, "ok"]
440
- * }
441
- * ```
442
- *
443
- * @see {@link or}
444
- * @see {@link not}
445
- * @category combinators
446
- * @since 2.0.0
447
- */
448
75
  const and = dual(2, (a, b) => (data) => a(data) && b(data));
449
- /**
450
- * Creates a predicate that returns `true` if either predicate is `true`.
451
- *
452
- * **When to use**
453
- *
454
- * Use when you want to combine `Predicate`s with OR, accepting values that
455
- * satisfy at least one condition, including refinements that narrow to a union.
456
- *
457
- * **Details**
458
- *
459
- * Evaluation short-circuits on the first `true`. For refinements, the output
460
- * type is a union.
461
- *
462
- * **Example** (Checking either condition)
463
- *
464
- * ```ts
465
- * import { Predicate } from "effect"
466
- *
467
- * const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
468
- *
469
- * isStringOrNumber("a") // => true
470
- * ```
471
- *
472
- * @see {@link and}
473
- * @see {@link xor}
474
- * @category combinators
475
- * @since 2.0.0
476
- */
477
76
  const or = dual(2, (a, b) => (data) => a(data) || b(data));
478
- /**
479
- * Creates a predicate that returns `true` if exactly one predicate is `true`.
480
- *
481
- * **When to use**
482
- *
483
- * Use when you want to combine two `Predicate`s with exclusive-or semantics.
484
- *
485
- * **Details**
486
- *
487
- * Returns `true` when results differ.
488
- *
489
- * **Example** (Checking exclusive-or conditions)
490
- *
491
- * ```ts
492
- * import { Predicate } from "effect"
493
- *
494
- * const isEven = (n: number) => n % 2 === 0
495
- * const isPositive = (n: number) => n > 0
496
- * const either = Predicate.xor(isEven, isPositive)
497
- *
498
- * either(-2) // => true
499
- * ```
500
- *
501
- * @see {@link or}
502
- * @see {@link and}
503
- * @category combinators
504
- * @since 2.0.0
505
- */
506
77
  const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
507
- /**
508
- * Creates a predicate that returns `true` when both predicates agree.
509
- *
510
- * **When to use**
511
- *
512
- * Use when you want to check equivalence of two `Predicate`s.
513
- *
514
- * **Details**
515
- *
516
- * Returns `true` when both results are equal.
517
- *
518
- * **Example** (Defining equivalence)
519
- *
520
- * ```ts
521
- * import { Predicate } from "effect"
522
- *
523
- * const isEven = (n: number) => n % 2 === 0
524
- * const same = Predicate.eqv(isEven, isEven)
525
- *
526
- * same(3) // => true
527
- * ```
528
- *
529
- * @see {@link xor}
530
- * @category combinators
531
- * @since 2.0.0
532
- */
533
78
  const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
534
- /**
535
- * Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
536
- *
537
- * **When to use**
538
- *
539
- * Use when you need to encode logical implication between `Predicate` rules,
540
- * where one rule only applies when a precondition holds.
541
- *
542
- * **Details**
543
- *
544
- * Models constraints like "if A then B" and returns `true` when the antecedent
545
- * is `false`.
546
- *
547
- * **Example** (Checking implication)
548
- *
549
- * ```ts
550
- * import { Predicate } from "effect"
551
- *
552
- * const isAdult = (age: number) => age >= 18
553
- * const canVote = (age: number) => age >= 18
554
- * const implies = Predicate.implies(isAdult, canVote)
555
- *
556
- * implies(16) // => true
557
- * ```
558
- *
559
- * @see {@link and}
560
- * @see {@link or}
561
- * @category combinators
562
- * @since 2.0.0
563
- */
564
79
  const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
565
- /**
566
- * Creates a predicate that returns `true` when neither predicate is `true`.
567
- *
568
- * **When to use**
569
- *
570
- * Use when you want to combine two `Predicate`s with logical NOR semantics.
571
- *
572
- * **Details**
573
- *
574
- * Returns the negation of `or`.
575
- *
576
- * **Example** (Checking NOR conditions)
577
- *
578
- * ```ts
579
- * import { Predicate } from "effect"
580
- *
581
- * const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
582
- *
583
- * neither(true) // => true
584
- * ```
585
- *
586
- * @see {@link or}
587
- * @see {@link not}
588
- * @category combinators
589
- * @since 2.0.0
590
- */
591
80
  const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
592
- /**
593
- * Creates a predicate that returns `true` unless both predicates are `true`.
594
- *
595
- * **When to use**
596
- *
597
- * Use when you want to combine two `Predicate`s with logical NAND semantics.
598
- *
599
- * **Details**
600
- *
601
- * Returns the negation of `and`.
602
- *
603
- * **Example** (Checking NAND conditions)
604
- *
605
- * ```ts
606
- * import { Predicate } from "effect"
607
- *
608
- * const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
609
- *
610
- * notBoth("a") // => true
611
- * ```
612
- *
613
- * @see {@link and}
614
- * @see {@link not}
615
- * @category combinators
616
- * @since 2.0.0
617
- */
618
81
  const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
619
- /**
620
- * Checks whether a value is a `function`.
621
- *
622
- * **When to use**
623
- *
624
- * Use when you need a `Predicate` guard to narrow an `unknown` value to a
625
- * callable function.
626
- *
627
- * **Details**
628
- *
629
- * Uses `typeof input === "function"`.
630
- *
631
- * **Example** (Guarding functions)
632
- *
633
- * ```ts
634
- * import { Predicate } from "effect"
635
- *
636
- * const data: unknown = () => 1
637
- *
638
- * if (Predicate.isFunction(data)) {
639
- * data() // => 1
640
- * }
641
- * ```
642
- *
643
- * @see {@link isObjectKeyword}
644
- * @category guards
645
- * @since 2.0.0
646
- */
647
82
  function isFunction(input) {
648
83
  return typeof input === "function";
649
84
  }
650
- /**
651
- * Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
652
- *
653
- * **When to use**
654
- *
655
- * Use when you need a `Predicate` guard that accepts arrays and functions as
656
- * well as objects.
657
- *
658
- * **Details**
659
- *
660
- * Returns `true` for arrays and functions, and `false` for `null`.
661
- *
662
- * **Example** (Checking object keywords)
663
- *
664
- * ```ts
665
- * import { Predicate } from "effect"
666
- *
667
- * Predicate.isObjectKeyword(() => 1) // => true
668
- * Predicate.isObjectKeyword(null) // => false
669
- * ```
670
- *
671
- * @see {@link isObject}
672
- * @see {@link isObjectOrArray}
673
- * @category guards
674
- * @since 4.0.0
675
- */
676
85
  function isObjectKeyword(input) {
677
86
  return typeof input === "object" && input !== null || isFunction(input);
678
87
  }
679
- /**
680
- * Checks whether a value has a given property key.
681
- *
682
- * **When to use**
683
- *
684
- * Use when you need a `Predicate` guard for property access on `unknown`
685
- * values with a simple structural object check.
686
- *
687
- * **Details**
688
- *
689
- * Uses the `in` operator and `isObjectKeyword`. This does not check property
690
- * value types.
691
- *
692
- * **Example** (Guarding object properties)
693
- *
694
- * ```ts
695
- * import { Predicate } from "effect"
696
- *
697
- * const hasName = Predicate.hasProperty("name")
698
- * const data: unknown = { name: "Ada" }
699
- *
700
- * if (hasName(data)) {
701
- * data.name // => "Ada"
702
- * }
703
- * ```
704
- *
705
- * @see {@link isTagged}
706
- * @see {@link isObjectKeyword}
707
- * @category guards
708
- * @since 2.0.0
709
- */
710
88
  const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
711
89
  function getOrInsertComputed(map, key, callback) {
712
90
  if (map.has(key)) return map.get(key);
@@ -714,31 +92,6 @@ function getOrInsertComputed(map, key, callback) {
714
92
  map.set(key, value);
715
93
  return value;
716
94
  }
717
- /**
718
- * Drops elements from the start while the predicate holds, returning the rest.
719
- *
720
- * **When to use**
721
- *
722
- * Use to remove a leading prefix of elements that satisfy a predicate.
723
- *
724
- * **Details**
725
- *
726
- * The predicate receives `(element, index)`.
727
- *
728
- * **Example** (Dropping while condition holds)
729
- *
730
- * ```ts
731
- * import { Array } from "effect"
732
- *
733
- * Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
734
- * ```
735
- *
736
- * @see {@link takeWhile} — keep the matching prefix instead
737
- * @see {@link drop} — drop a fixed count
738
- *
739
- * @category getters
740
- * @since 2.0.0
741
- */
742
95
  const dropWhile = dual(2, (self, predicate) => {
743
96
  const input = Array.isArray(self) ? self : Array.from(self);
744
97
  const len = input.length;
@@ -746,35 +99,6 @@ const dropWhile = dual(2, (self, predicate) => {
746
99
  while (idx < len && predicate(input[idx], idx)) idx++;
747
100
  return input.slice(idx);
748
101
  });
749
- /**
750
- * Takes elements from the start while the predicate holds, stopping at the
751
- * first element that fails.
752
- *
753
- * **When to use**
754
- *
755
- * Use to keep the leading elements of an iterable while each element satisfies
756
- * a predicate, returning the retained prefix as an array.
757
- *
758
- * **Details**
759
- *
760
- * Supports refinements for type narrowing. The predicate receives
761
- * `(element, index)`.
762
- *
763
- * **Example** (Taking while condition holds)
764
- *
765
- * ```ts
766
- * import { Array } from "effect"
767
- *
768
- * Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
769
- * ```
770
- *
771
- * @see {@link take} for keeping a fixed number of leading elements
772
- * @see {@link dropWhile} for removing the matching prefix and keeping the rest
773
- * @see {@link span} for splitting the matching prefix from the remaining elements
774
- *
775
- * @category getters
776
- * @since 2.0.0
777
- */
778
102
  const takeWhile = dual(2, (self, predicate) => {
779
103
  const input = Array.isArray(self) ? self : Array.from(self);
780
104
  const len = input.length;
@@ -785,32 +109,6 @@ const takeWhile = dual(2, (self, predicate) => {
785
109
 
786
110
  //#endregion
787
111
  //#region src/create-import-lookup.ts
788
- /**
789
- * Create a lookup of local import bindings from a source by scanning the
790
- * top-level imports of a program.
791
- *
792
- * Entries are kept in source order, and both indexes (by local name and by
793
- * imported name) are built during the same scan, so every query works
794
- * immediately after creation. Aliases (`import { flushSync as fs }`) are
795
- * handled naturally: the alias is the entry's local name.
796
- *
797
- * @param program - The program whose top-level import declarations to scan.
798
- * @param options - The source to track and optional builtin namespaces.
799
- * @returns An {@link ImportLookup} over the matching import bindings.
800
- *
801
- * @example
802
- * ```typescript
803
- * const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
804
- * return {
805
- * CallExpression(node) {
806
- * const callee = Extract.unwrap(node.callee);
807
- * if (Check.isIdentifier(callee) && imports.has(callee.name, "flushSync")) {
808
- * // ...
809
- * }
810
- * },
811
- * };
812
- * ```
813
- */
814
112
  function createImportLookup(program, options) {
815
113
  const { builtinNamespaces = [], source } = options;
816
114
  const entries = [];
@@ -884,47 +182,6 @@ function createImportLookup(program, options) {
884
182
 
885
183
  //#endregion
886
184
  //#region src/resolve-origin.ts
887
- /**
888
- * Resolve an identifier to the AST node its value **originates from**,
889
- * suitable for origin/pedigree tracking in ESLint rule analysis.
890
- *
891
- * The resolution follows these rules per definition type:
892
- *
893
- * | Definition type | `def.node` | Returns |
894
- * |--------------------------|----------------------------------------------|------------------------------------|
895
- * | `CatchClause` | `CatchClause` | `null` |
896
- * | `ClassName` | `ClassDeclaration` / `ClassExpression` | `def.node` |
897
- * | `FunctionName` | `FunctionDeclaration` / `FunctionExpression` | `def.node` |
898
- * | `ImplicitGlobalVariable` | any node | `null` |
899
- * | `ImportBinding` | import specifier | `def.node` (the import specifier) |
900
- * | `Parameter` | containing function node | `def.node` (if a real function) |
901
- * | `TSEnumMember` | `TSEnumMember` | `def.node.initializer` (or `null`) |
902
- * | `TSEnumName` | `TSEnumDeclaration` | `def.node` |
903
- * | `TSModuleName` | `TSModuleDeclaration` | `null` |
904
- * | `Type` | type alias node | `null` |
905
- * | `Variable` | `VariableDeclarator` | `def.node.init` (or `null`), including for destructured bindings |
906
- *
907
- * Unlike {@link resolve}, a binding declared through a destructuring
908
- * pattern (e.g. `setState` in `const [state, setState] = useState()`) resolves to the
909
- * declarator's initializer (the `useState()` call), i.e. the source expression the
910
- * binding derives from rather than the binding's own value; and a parameter resolves
911
- * to the containing function node (the binding's declaration site) instead of `null`;
912
- * and an import binding resolves to its import specifier (whose parent
913
- * `ImportDeclaration` carries the module source) instead of `null`.
914
- *
915
- * Use this for origin/pedigree tracking ("what produced this value?"); use
916
- * {@link resolve} when the precise value of the binding is needed.
917
- *
918
- * @param context The ESLint rule context.
919
- * @param node The identifier to resolve.
920
- * @param options Optional settings:
921
- * - `at`: Index of the definition to resolve (default: `0` for the first definition).
922
- * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier
923
- * (this will miss variables declared in an outer scope). When `false` (default), traverse the
924
- * scope chain upward via `findVariable` so that references to outer-scope bindings are resolved
925
- * correctly.
926
- * @returns The resolved origin node, or `null` if the identifier cannot be resolved.
927
- */
928
185
  function resolveOrigin(context, node, options) {
929
186
  const { at = 0, localOnly = false } = options ?? {};
930
187
  const scope = context.sourceCode.getScope(node);
@@ -938,7 +195,7 @@ function resolveOrigin(context, node, options) {
938
195
  case DefinitionType.Variable: {
939
196
  const { init } = def.node;
940
197
  if (init == null) return null;
941
- if ("declarations" in init) return null;
198
+ if (hasProperty(init, "declarations")) return null;
942
199
  return init;
943
200
  }
944
201
  case DefinitionType.Parameter: return Check.isFunction(def.node) ? def.node : null;
@@ -961,13 +218,6 @@ const thisBlockTypes = [
961
218
  AST_NODE_TYPES.ClassBody,
962
219
  AST_NODE_TYPES.Program
963
220
  ];
964
- /**
965
- * Check if two nodes have equal values.
966
- * @param context The ESLint rule context.
967
- * @param a The first node to compare.
968
- * @param b The second node to compare.
969
- * @returns `true` if the two nodes have equal values.
970
- */
971
221
  function isValueEqual(context, a, b) {
972
222
  a = Check.isTypeExpression(a) ? Extract.unwrap(a) : a;
973
223
  b = Check.isTypeExpression(b) ? Extract.unwrap(b) : b;
@@ -1023,14 +273,6 @@ function isValueEqual(context, a, b) {
1023
273
 
1024
274
  //#endregion
1025
275
  //#region src/is-assignment-target-equal.ts
1026
- /**
1027
- * Check if two assignment targets are equal, either directly or by their values.
1028
- * @param context The ESLint rule context.
1029
- * @param a The first node to compare.
1030
- * @param b The second node to compare.
1031
- * @returns `true` if the assignment targets are equal.
1032
- * @internal
1033
- */
1034
276
  function isAssignmentTargetEqual(context, a, b) {
1035
277
  const unwrappedA = Check.isTypeExpression(a) ? Extract.unwrap(a) : a;
1036
278
  const unwrappedB = Check.isTypeExpression(b) ? Extract.unwrap(b) : b;
@@ -1040,11 +282,6 @@ function isAssignmentTargetEqual(context, a, b) {
1040
282
 
1041
283
  //#endregion
1042
284
  //#region src/resolve-import-source.ts
1043
- /**
1044
- * Get the arguments of a require expression.
1045
- * @param node The node to check.
1046
- * @returns The require expression arguments, or `null` when the node is not a require expression.
1047
- */
1048
285
  function getRequireExpressionArguments(node) {
1049
286
  const expr = Extract.unwrap(node);
1050
287
  if (expr.type === AST_NODE_TYPES.CallExpression) {
@@ -1055,13 +292,6 @@ function getRequireExpressionArguments(node) {
1055
292
  if (expr.type === AST_NODE_TYPES.MemberExpression) return getRequireExpressionArguments(expr.object);
1056
293
  return null;
1057
294
  }
1058
- /**
1059
- * Resolve the import source of a variable by walking its latest definition.
1060
- * @param name The variable name.
1061
- * @param initialScope The initial scope.
1062
- * @param seen The set of already visited variable names (for cycle detection).
1063
- * @returns The import source, or `null` when it cannot be resolved.
1064
- */
1065
295
  function resolveImportSource(name, initialScope, seen = /* @__PURE__ */ new Set()) {
1066
296
  if (seen.has(name)) return null;
1067
297
  seen.add(name);
@@ -1085,28 +315,12 @@ function resolveImportSource(name, initialScope, seen = /* @__PURE__ */ new Set(
1085
315
 
1086
316
  //#endregion
1087
317
  //#region src/is-initialized-from-react.ts
1088
- /**
1089
- * Check if a variable is initialized from a React import.
1090
- * @param name The variable name.
1091
- * @param initialScope The initial scope.
1092
- * @param importSource Alternative import source of React (ex: "preact/compat").
1093
- * @returns `true` if the variable is initialized or derived from a React import.
1094
- * @internal
1095
- */
1096
318
  function isInitializedFromReact(name, initialScope, importSource = "react") {
1097
319
  return name.toLowerCase() === "react" || Boolean(resolveImportSource(name, initialScope)?.startsWith(importSource));
1098
320
  }
1099
321
 
1100
322
  //#endregion
1101
323
  //#region src/is-initialized-from-react-native.ts
1102
- /**
1103
- * Check if a variable is initialized from a React Native import.
1104
- * @param name The variable name.
1105
- * @param initialScope The initial scope.
1106
- * @param importSource Alternative import source of React Native (ex: "react-native-web").
1107
- * @returns `true` if the variable is initialized or derived from a React Native import.
1108
- * @internal
1109
- */
1110
324
  function isInitializedFromReactNative(name, initialScope, importSource = "react-native") {
1111
325
  return [
1112
326
  "react_native",
@@ -1117,39 +331,6 @@ function isInitializedFromReactNative(name, initialScope, importSource = "react-
1117
331
 
1118
332
  //#endregion
1119
333
  //#region src/resolve.ts
1120
- /**
1121
- * Resolve an identifier to the AST node that represents its value,
1122
- * suitable for use in ESLint rule analysis.
1123
- *
1124
- * The resolution follows these rules per definition type:
1125
- *
1126
- * | Definition type | `def.node` | Returns |
1127
- * |--------------------------|----------------------------------------------|------------------------------------|
1128
- * | `CatchClause` | `CatchClause` | `null` |
1129
- * | `ClassName` | `ClassDeclaration` / `ClassExpression` | `def.node` |
1130
- * | `FunctionName` | `FunctionDeclaration` / `FunctionExpression` | `def.node` |
1131
- * | `ImplicitGlobalVariable` | any node | `null` |
1132
- * | `ImportBinding` | import specifier | `null` |
1133
- * | `Parameter` | containing function node | `null` (the value is supplied by the caller) |
1134
- * | `TSEnumMember` | `TSEnumMember` | `def.node.initializer` (or `null`) |
1135
- * | `TSEnumName` | `TSEnumDeclaration` | `def.node` |
1136
- * | `TSModuleName` | `TSModuleDeclaration` | `null` |
1137
- * | `Type` | type alias node | `null` |
1138
- * | `Variable` | `VariableDeclarator` | `def.node.init` for a plain identifier binding; `null` for destructured bindings or missing init |
1139
- *
1140
- * @param context The ESLint rule context.
1141
- * @param node The identifier to resolve.
1142
- * @param options Optional settings:
1143
- * - `at`: Index of the definition to resolve (default: `0` for the first definition).
1144
- * - `localOnly`: If `true`, only consider variables declared in the same scope as the identifier
1145
- * (this will miss variables declared in an outer scope). When `false` (default), traverse the
1146
- * scope chain upward via `findVariable` so that references to outer-scope bindings are resolved
1147
- * correctly.
1148
- * @returns The resolved node, or `null` if the identifier cannot be resolved to a value node.
1149
- *
1150
- * For origin/pedigree tracking that maps destructured bindings to the declarator's
1151
- * initializer, see {@link resolveOrigin}.
1152
- */
1153
334
  function resolve(context, node, options) {
1154
335
  const { at = 0, localOnly = false } = options ?? {};
1155
336
  const scope = context.sourceCode.getScope(node);
@@ -1164,7 +345,7 @@ function resolve(context, node, options) {
1164
345
  const { id, init } = def.node;
1165
346
  if (id !== def.name) return null;
1166
347
  if (init == null) return null;
1167
- if ("declarations" in init) return null;
348
+ if (hasProperty(init, "declarations")) return null;
1168
349
  return init;
1169
350
  }
1170
351
  case DefinitionType.Parameter: return null;
@@ -1181,11 +362,6 @@ function resolve(context, node, options) {
1181
362
 
1182
363
  //#endregion
1183
364
  //#region src/resolve-enclosing-assignment-target.ts
1184
- /**
1185
- * Resolve the enclosing assignment target (variable, property, etc.) of the node.
1186
- * @param node The starting node for the upward search.
1187
- * @returns The enclosing assignment target node, or `null` when not found.
1188
- */
1189
365
  function resolveEnclosingAssignmentTarget(node) {
1190
366
  switch (node.type) {
1191
367
  case AST_NODE_TYPES.VariableDeclarator: return node.id;
@@ -1200,12 +376,6 @@ function resolveEnclosingAssignmentTarget(node) {
1200
376
 
1201
377
  //#endregion
1202
378
  //#region src/resolve-object-type.ts
1203
- /**
1204
- * Resolve the object type of the node.
1205
- * @param context The ESLint rule context.
1206
- * @param node The node to resolve.
1207
- * @returns The object type of the node, or `null` when it cannot be resolved.
1208
- */
1209
379
  function resolveObjectType(context, node) {
1210
380
  if (node == null) return null;
1211
381
  switch (node.type) {
@@ -1238,7 +408,7 @@ function resolveObjectType(context, node) {
1238
408
  node
1239
409
  };
1240
410
  case AST_NODE_TYPES.Literal:
1241
- if ("regex" in node) return {
411
+ if (hasProperty(node, "regex")) return {
1242
412
  kind: "regexp",
1243
413
  node
1244
414
  };
@@ -1302,7 +472,7 @@ function resolveObjectType(context, node) {
1302
472
  };
1303
473
  }
1304
474
  default:
1305
- if (!("expression" in node) || typeof node.expression !== "object") return null;
475
+ if (!hasProperty(node, "expression") || typeof node.expression !== "object") return null;
1306
476
  return resolveObjectType(context, node.expression);
1307
477
  }
1308
478
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/var",
3
- "version": "5.24.1",
3
+ "version": "5.24.2",
4
4
  "description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -29,8 +29,8 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@eslint-react/ast": "5.24.1",
33
- "@eslint-react/eslint": "5.24.1",
32
+ "@eslint-react/ast": "5.24.2",
33
+ "@eslint-react/eslint": "5.24.2",
34
34
  "@typescript-eslint/scope-manager": "^8.71.0",
35
35
  "@typescript-eslint/types": "^8.71.0",
36
36
  "@typescript-eslint/utils": "^8.71.0",