@eslint-react/shared 5.24.0 → 5.24.1
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.d.ts +14 -0
- package/dist/index.js +408 -74
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -166,6 +166,20 @@ export declare const normalizeSettings: ({ importSource, compilationMode, polymo
|
|
|
166
166
|
* @returns The detected React version or the fallback version.
|
|
167
167
|
*/
|
|
168
168
|
export declare function getReactVersion(fallback: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Get the normalized ESLint React settings, memoized by the input settings object.
|
|
171
|
+
* @param settings The ESLint React settings to decode and normalize.
|
|
172
|
+
* @returns The normalized ESLint React settings.
|
|
173
|
+
*/
|
|
174
|
+
export declare const getNormalizedSettings: (ast: object) => {
|
|
175
|
+
readonly importSource: string;
|
|
176
|
+
readonly compilationMode: "infer" | "annotation" | "syntax" | "all" | "off";
|
|
177
|
+
readonly polymorphicPropName: string;
|
|
178
|
+
readonly version: string;
|
|
179
|
+
readonly additionalRefHooks: RegExpLike;
|
|
180
|
+
readonly additionalStateHooks: RegExpLike;
|
|
181
|
+
readonly additionalEffectHooks: RegExpLike;
|
|
182
|
+
};
|
|
169
183
|
/**
|
|
170
184
|
* Get the normalized ESLint React settings from the rule context.
|
|
171
185
|
* @param context The rule context.
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import { z } from "zod/v4";
|
|
|
36
36
|
* (n) => n + 2,
|
|
37
37
|
* (n) => n * 3
|
|
38
38
|
* )
|
|
39
|
-
*
|
|
39
|
+
* result // => 21
|
|
40
40
|
* ```
|
|
41
41
|
*
|
|
42
42
|
* @category combinators
|
|
@@ -93,16 +93,6 @@ const Class = (function() {
|
|
|
93
93
|
return PipeableBase;
|
|
94
94
|
})();
|
|
95
95
|
/**
|
|
96
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
97
|
-
*
|
|
98
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
99
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
100
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
101
|
-
* memoization helpers used across the library.
|
|
102
|
-
*
|
|
103
|
-
* @since 2.0.0
|
|
104
|
-
*/
|
|
105
|
-
/**
|
|
106
96
|
* Creates a function that can be called in data-first style or data-last
|
|
107
97
|
* (`pipe`-friendly) style.
|
|
108
98
|
*
|
|
@@ -127,8 +117,8 @@ const Class = (function() {
|
|
|
127
117
|
* (self: number, that: number) => number
|
|
128
118
|
* >(2, (self, that) => self + that)
|
|
129
119
|
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
120
|
+
* sum(2, 3) // => 5
|
|
121
|
+
* pipe(2, sum(3)) // => 5
|
|
132
122
|
* ```
|
|
133
123
|
*
|
|
134
124
|
* **Example** (Defining overloads with call signatures)
|
|
@@ -141,8 +131,8 @@ const Class = (function() {
|
|
|
141
131
|
* (self: number, that: number): number
|
|
142
132
|
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
143
133
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
134
|
+
* sum(2, 3) // => 5
|
|
135
|
+
* pipe(2, sum(3)) // => 5
|
|
146
136
|
* ```
|
|
147
137
|
*
|
|
148
138
|
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
@@ -158,8 +148,8 @@ const Class = (function() {
|
|
|
158
148
|
* (self, that) => self + that
|
|
159
149
|
* )
|
|
160
150
|
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
151
|
+
* sum(2, 3) // => 5
|
|
152
|
+
* pipe(2, sum(3)) // => 5
|
|
163
153
|
* ```
|
|
164
154
|
*
|
|
165
155
|
* @category combinators
|
|
@@ -204,9 +194,8 @@ const dual = function(arity, body) {
|
|
|
204
194
|
*
|
|
205
195
|
* ```ts
|
|
206
196
|
* import { identity } from "effect"
|
|
207
|
-
* import * as assert from "node:assert"
|
|
208
197
|
*
|
|
209
|
-
*
|
|
198
|
+
* identity(5) // => 5
|
|
210
199
|
* ```
|
|
211
200
|
*
|
|
212
201
|
* @category combinators
|
|
@@ -244,12 +233,11 @@ const cast = identity;
|
|
|
244
233
|
*
|
|
245
234
|
* ```ts
|
|
246
235
|
* import { Function } from "effect"
|
|
247
|
-
* import * as assert from "node:assert"
|
|
248
236
|
*
|
|
249
237
|
* const constNull = Function.constant(null)
|
|
250
238
|
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
239
|
+
* constNull() // => null
|
|
240
|
+
* constNull() // => null
|
|
253
241
|
* ```
|
|
254
242
|
*
|
|
255
243
|
* @category constructors
|
|
@@ -267,9 +255,8 @@ const constant = (value) => () => value;
|
|
|
267
255
|
*
|
|
268
256
|
* ```ts
|
|
269
257
|
* import { Function } from "effect"
|
|
270
|
-
* import * as assert from "node:assert"
|
|
271
258
|
*
|
|
272
|
-
*
|
|
259
|
+
* Function.constTrue() // => true
|
|
273
260
|
* ```
|
|
274
261
|
*
|
|
275
262
|
* @category constants
|
|
@@ -287,9 +274,8 @@ const constTrue = constant(true);
|
|
|
287
274
|
*
|
|
288
275
|
* ```ts
|
|
289
276
|
* import { Function } from "effect"
|
|
290
|
-
* import * as assert from "node:assert"
|
|
291
277
|
*
|
|
292
|
-
*
|
|
278
|
+
* Function.constFalse() // => false
|
|
293
279
|
* ```
|
|
294
280
|
*
|
|
295
281
|
* @category constants
|
|
@@ -307,9 +293,8 @@ const constFalse = constant(false);
|
|
|
307
293
|
*
|
|
308
294
|
* ```ts
|
|
309
295
|
* import { Function } from "effect"
|
|
310
|
-
* import * as assert from "node:assert"
|
|
311
296
|
*
|
|
312
|
-
*
|
|
297
|
+
* Function.constNull() // => null
|
|
313
298
|
* ```
|
|
314
299
|
*
|
|
315
300
|
* @category constants
|
|
@@ -327,9 +312,8 @@ const constNull = constant(null);
|
|
|
327
312
|
*
|
|
328
313
|
* ```ts
|
|
329
314
|
* import { Function } from "effect"
|
|
330
|
-
* import * as assert from "node:assert"
|
|
331
315
|
*
|
|
332
|
-
*
|
|
316
|
+
* Function.constUndefined() // => undefined
|
|
333
317
|
* ```
|
|
334
318
|
*
|
|
335
319
|
* @category constants
|
|
@@ -348,12 +332,11 @@ const constUndefined = constant(void 0);
|
|
|
348
332
|
*
|
|
349
333
|
* ```ts
|
|
350
334
|
* import { Function } from "effect"
|
|
351
|
-
* import * as assert from "node:assert"
|
|
352
335
|
*
|
|
353
336
|
* const increment = (n: number) => n + 1
|
|
354
337
|
* const square = (n: number) => n * n
|
|
355
338
|
*
|
|
356
|
-
*
|
|
339
|
+
* Function.compose(increment, square)(2) // => 9
|
|
357
340
|
* ```
|
|
358
341
|
*
|
|
359
342
|
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
@@ -416,70 +399,416 @@ const absurd = (_) => {
|
|
|
416
399
|
* name: hole<string>()
|
|
417
400
|
* })
|
|
418
401
|
*
|
|
419
|
-
* console.log(typeof buildUser) // "function"
|
|
420
402
|
* ```
|
|
421
403
|
*
|
|
422
404
|
* @category utility types
|
|
423
405
|
* @since 2.0.0
|
|
424
406
|
*/
|
|
425
407
|
const hole = cast(absurd);
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
408
|
+
/**
|
|
409
|
+
* Creates a memoized function whose input is an object, caching results by
|
|
410
|
+
* object identity.
|
|
411
|
+
*
|
|
412
|
+
* **When to use**
|
|
413
|
+
*
|
|
414
|
+
* Use to reuse the result of a synchronous computation whose output is stable
|
|
415
|
+
* for a given object reference.
|
|
416
|
+
*
|
|
417
|
+
* **Details**
|
|
418
|
+
*
|
|
419
|
+
* Each memoized wrapper owns a private `WeakMap` keyed by object identity.
|
|
420
|
+
*
|
|
421
|
+
* **Gotchas**
|
|
422
|
+
*
|
|
423
|
+
* `undefined` is reserved to represent a cache miss and is therefore not
|
|
424
|
+
* supported as a return value.
|
|
425
|
+
*
|
|
426
|
+
* Structurally equal objects do not share cache entries. If the same object is
|
|
427
|
+
* mutated after its first call, later calls still return the cached result for
|
|
428
|
+
* that reference.
|
|
429
|
+
*
|
|
430
|
+
* @category caching
|
|
431
|
+
* @since 4.0.0
|
|
432
|
+
*/
|
|
433
|
+
function memoize(f) {
|
|
434
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
435
|
+
return (a) => {
|
|
436
|
+
const cached = cache.get(a);
|
|
437
|
+
if (cached !== void 0) return cached;
|
|
438
|
+
const result = f(a);
|
|
439
|
+
cache.set(a, result);
|
|
440
|
+
return result;
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
445
|
+
*
|
|
446
|
+
* **When to use**
|
|
447
|
+
*
|
|
448
|
+
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
449
|
+
* satisfy multiple conditions, including refinements that narrow to an
|
|
450
|
+
* intersection.
|
|
451
|
+
*
|
|
452
|
+
* **Details**
|
|
453
|
+
*
|
|
454
|
+
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
455
|
+
* type is an intersection.
|
|
456
|
+
*
|
|
457
|
+
* **Example** (Checking both conditions)
|
|
458
|
+
*
|
|
459
|
+
* ```ts
|
|
460
|
+
* import { Predicate } from "effect"
|
|
461
|
+
*
|
|
462
|
+
* const hasAAndB = Predicate.and(
|
|
463
|
+
* Predicate.hasProperty("a"),
|
|
464
|
+
* Predicate.hasProperty("b")
|
|
465
|
+
* )
|
|
466
|
+
*
|
|
467
|
+
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
468
|
+
* if (hasAAndB(input)) {
|
|
469
|
+
* // input has both properties at this point
|
|
470
|
+
* const a = input.a
|
|
471
|
+
* const b = input.b
|
|
472
|
+
*
|
|
473
|
+
* const values = [a, b] // => [1, "ok"]
|
|
474
|
+
* }
|
|
475
|
+
* ```
|
|
476
|
+
*
|
|
477
|
+
* @see {@link or}
|
|
478
|
+
* @see {@link not}
|
|
479
|
+
* @category combinators
|
|
480
|
+
* @since 2.0.0
|
|
481
|
+
*/
|
|
482
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
483
|
+
/**
|
|
484
|
+
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
485
|
+
*
|
|
486
|
+
* **When to use**
|
|
487
|
+
*
|
|
488
|
+
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
489
|
+
* satisfy at least one condition, including refinements that narrow to a union.
|
|
490
|
+
*
|
|
491
|
+
* **Details**
|
|
492
|
+
*
|
|
493
|
+
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
494
|
+
* type is a union.
|
|
495
|
+
*
|
|
496
|
+
* **Example** (Checking either condition)
|
|
497
|
+
*
|
|
498
|
+
* ```ts
|
|
499
|
+
* import { Predicate } from "effect"
|
|
500
|
+
*
|
|
501
|
+
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
502
|
+
*
|
|
503
|
+
* isStringOrNumber("a") // => true
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @see {@link and}
|
|
507
|
+
* @see {@link xor}
|
|
508
|
+
* @category combinators
|
|
509
|
+
* @since 2.0.0
|
|
510
|
+
*/
|
|
511
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
512
|
+
/**
|
|
513
|
+
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
514
|
+
*
|
|
515
|
+
* **When to use**
|
|
516
|
+
*
|
|
517
|
+
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
518
|
+
*
|
|
519
|
+
* **Details**
|
|
520
|
+
*
|
|
521
|
+
* Returns `true` when results differ.
|
|
522
|
+
*
|
|
523
|
+
* **Example** (Checking exclusive-or conditions)
|
|
524
|
+
*
|
|
525
|
+
* ```ts
|
|
526
|
+
* import { Predicate } from "effect"
|
|
527
|
+
*
|
|
528
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
529
|
+
* const isPositive = (n: number) => n > 0
|
|
530
|
+
* const either = Predicate.xor(isEven, isPositive)
|
|
531
|
+
*
|
|
532
|
+
* either(-2) // => true
|
|
533
|
+
* ```
|
|
534
|
+
*
|
|
535
|
+
* @see {@link or}
|
|
536
|
+
* @see {@link and}
|
|
537
|
+
* @category combinators
|
|
538
|
+
* @since 2.0.0
|
|
539
|
+
*/
|
|
540
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
541
|
+
/**
|
|
542
|
+
* Creates a predicate that returns `true` when both predicates agree.
|
|
543
|
+
*
|
|
544
|
+
* **When to use**
|
|
545
|
+
*
|
|
546
|
+
* Use when you want to check equivalence of two `Predicate`s.
|
|
547
|
+
*
|
|
548
|
+
* **Details**
|
|
549
|
+
*
|
|
550
|
+
* Returns `true` when both results are equal.
|
|
551
|
+
*
|
|
552
|
+
* **Example** (Defining equivalence)
|
|
553
|
+
*
|
|
554
|
+
* ```ts
|
|
555
|
+
* import { Predicate } from "effect"
|
|
556
|
+
*
|
|
557
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
558
|
+
* const same = Predicate.eqv(isEven, isEven)
|
|
559
|
+
*
|
|
560
|
+
* same(3) // => true
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @see {@link xor}
|
|
564
|
+
* @category combinators
|
|
565
|
+
* @since 2.0.0
|
|
566
|
+
*/
|
|
567
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
568
|
+
/**
|
|
569
|
+
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
570
|
+
*
|
|
571
|
+
* **When to use**
|
|
572
|
+
*
|
|
573
|
+
* Use when you need to encode logical implication between `Predicate` rules,
|
|
574
|
+
* where one rule only applies when a precondition holds.
|
|
575
|
+
*
|
|
576
|
+
* **Details**
|
|
577
|
+
*
|
|
578
|
+
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
579
|
+
* is `false`.
|
|
580
|
+
*
|
|
581
|
+
* **Example** (Checking implication)
|
|
582
|
+
*
|
|
583
|
+
* ```ts
|
|
584
|
+
* import { Predicate } from "effect"
|
|
585
|
+
*
|
|
586
|
+
* const isAdult = (age: number) => age >= 18
|
|
587
|
+
* const canVote = (age: number) => age >= 18
|
|
588
|
+
* const implies = Predicate.implies(isAdult, canVote)
|
|
589
|
+
*
|
|
590
|
+
* implies(16) // => true
|
|
591
|
+
* ```
|
|
592
|
+
*
|
|
593
|
+
* @see {@link and}
|
|
594
|
+
* @see {@link or}
|
|
595
|
+
* @category combinators
|
|
596
|
+
* @since 2.0.0
|
|
597
|
+
*/
|
|
598
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
599
|
+
/**
|
|
600
|
+
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
601
|
+
*
|
|
602
|
+
* **When to use**
|
|
603
|
+
*
|
|
604
|
+
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
605
|
+
*
|
|
606
|
+
* **Details**
|
|
607
|
+
*
|
|
608
|
+
* Returns the negation of `or`.
|
|
609
|
+
*
|
|
610
|
+
* **Example** (Checking NOR conditions)
|
|
611
|
+
*
|
|
612
|
+
* ```ts
|
|
613
|
+
* import { Predicate } from "effect"
|
|
614
|
+
*
|
|
615
|
+
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
616
|
+
*
|
|
617
|
+
* neither(true) // => true
|
|
618
|
+
* ```
|
|
619
|
+
*
|
|
620
|
+
* @see {@link or}
|
|
621
|
+
* @see {@link not}
|
|
622
|
+
* @category combinators
|
|
623
|
+
* @since 2.0.0
|
|
624
|
+
*/
|
|
625
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
626
|
+
/**
|
|
627
|
+
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
628
|
+
*
|
|
629
|
+
* **When to use**
|
|
630
|
+
*
|
|
631
|
+
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
632
|
+
*
|
|
633
|
+
* **Details**
|
|
634
|
+
*
|
|
635
|
+
* Returns the negation of `and`.
|
|
636
|
+
*
|
|
637
|
+
* **Example** (Checking NAND conditions)
|
|
638
|
+
*
|
|
639
|
+
* ```ts
|
|
640
|
+
* import { Predicate } from "effect"
|
|
641
|
+
*
|
|
642
|
+
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
643
|
+
*
|
|
644
|
+
* notBoth("a") // => true
|
|
645
|
+
* ```
|
|
646
|
+
*
|
|
647
|
+
* @see {@link and}
|
|
648
|
+
* @see {@link not}
|
|
649
|
+
* @category combinators
|
|
650
|
+
* @since 2.0.0
|
|
651
|
+
*/
|
|
652
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
653
|
+
/**
|
|
654
|
+
* Checks whether a value is a `function`.
|
|
655
|
+
*
|
|
656
|
+
* **When to use**
|
|
657
|
+
*
|
|
658
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
659
|
+
* callable function.
|
|
660
|
+
*
|
|
661
|
+
* **Details**
|
|
662
|
+
*
|
|
663
|
+
* Uses `typeof input === "function"`.
|
|
664
|
+
*
|
|
665
|
+
* **Example** (Guarding functions)
|
|
666
|
+
*
|
|
667
|
+
* ```ts
|
|
668
|
+
* import { Predicate } from "effect"
|
|
669
|
+
*
|
|
670
|
+
* const data: unknown = () => 1
|
|
671
|
+
*
|
|
672
|
+
* if (Predicate.isFunction(data)) {
|
|
673
|
+
* data() // => 1
|
|
674
|
+
* }
|
|
675
|
+
* ```
|
|
676
|
+
*
|
|
677
|
+
* @see {@link isObjectKeyword}
|
|
678
|
+
* @category guards
|
|
679
|
+
* @since 2.0.0
|
|
680
|
+
*/
|
|
681
|
+
function isFunction(input) {
|
|
682
|
+
return typeof input === "function";
|
|
431
683
|
}
|
|
432
684
|
/**
|
|
433
|
-
*
|
|
685
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
434
686
|
*
|
|
435
|
-
*
|
|
687
|
+
* **When to use**
|
|
688
|
+
*
|
|
689
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
690
|
+
* well as objects.
|
|
691
|
+
*
|
|
692
|
+
* **Details**
|
|
693
|
+
*
|
|
694
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
695
|
+
*
|
|
696
|
+
* **Example** (Checking object keywords)
|
|
436
697
|
*
|
|
437
|
-
* @param pred - The predicate to test each element with.
|
|
438
|
-
* @returns A new array without the matching prefix.
|
|
439
|
-
* @example
|
|
440
698
|
* ```ts
|
|
441
|
-
* import
|
|
442
|
-
*
|
|
699
|
+
* import { Predicate } from "effect"
|
|
700
|
+
*
|
|
701
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
702
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
703
|
+
* ```
|
|
704
|
+
*
|
|
705
|
+
* @see {@link isObject}
|
|
706
|
+
* @see {@link isObjectOrArray}
|
|
707
|
+
* @category guards
|
|
708
|
+
* @since 4.0.0
|
|
709
|
+
*/
|
|
710
|
+
function isObjectKeyword(input) {
|
|
711
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Checks whether a value has a given property key.
|
|
715
|
+
*
|
|
716
|
+
* **When to use**
|
|
443
717
|
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
718
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
719
|
+
* values with a simple structural object check.
|
|
446
720
|
*
|
|
447
|
-
*
|
|
448
|
-
*
|
|
721
|
+
* **Details**
|
|
722
|
+
*
|
|
723
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
724
|
+
* value types.
|
|
725
|
+
*
|
|
726
|
+
* **Example** (Guarding object properties)
|
|
727
|
+
*
|
|
728
|
+
* ```ts
|
|
729
|
+
* import { Predicate } from "effect"
|
|
730
|
+
*
|
|
731
|
+
* const hasName = Predicate.hasProperty("name")
|
|
732
|
+
* const data: unknown = { name: "Ada" }
|
|
733
|
+
*
|
|
734
|
+
* if (hasName(data)) {
|
|
735
|
+
* data.name // => "Ada"
|
|
736
|
+
* }
|
|
449
737
|
* ```
|
|
450
|
-
*
|
|
738
|
+
*
|
|
739
|
+
* @see {@link isTagged}
|
|
740
|
+
* @see {@link isObjectKeyword}
|
|
741
|
+
* @category guards
|
|
742
|
+
* @since 2.0.0
|
|
451
743
|
*/
|
|
452
|
-
const
|
|
453
|
-
|
|
744
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
745
|
+
/**
|
|
746
|
+
* Drops elements from the start while the predicate holds, returning the rest.
|
|
747
|
+
*
|
|
748
|
+
* **When to use**
|
|
749
|
+
*
|
|
750
|
+
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
751
|
+
*
|
|
752
|
+
* **Details**
|
|
753
|
+
*
|
|
754
|
+
* The predicate receives `(element, index)`.
|
|
755
|
+
*
|
|
756
|
+
* **Example** (Dropping while condition holds)
|
|
757
|
+
*
|
|
758
|
+
* ```ts
|
|
759
|
+
* import { Array } from "effect"
|
|
760
|
+
*
|
|
761
|
+
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
762
|
+
* ```
|
|
763
|
+
*
|
|
764
|
+
* @see {@link takeWhile} — keep the matching prefix instead
|
|
765
|
+
* @see {@link drop} — drop a fixed count
|
|
766
|
+
*
|
|
767
|
+
* @category getters
|
|
768
|
+
* @since 2.0.0
|
|
769
|
+
*/
|
|
770
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
771
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
772
|
+
const len = input.length;
|
|
454
773
|
let idx = 0;
|
|
455
|
-
while (idx < len &&
|
|
456
|
-
return
|
|
774
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
775
|
+
return input.slice(idx);
|
|
457
776
|
});
|
|
458
777
|
/**
|
|
459
|
-
* Takes
|
|
778
|
+
* Takes elements from the start while the predicate holds, stopping at the
|
|
779
|
+
* first element that fails.
|
|
460
780
|
*
|
|
461
|
-
*
|
|
781
|
+
* **When to use**
|
|
462
782
|
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
* import * as assert from "node:assert"
|
|
468
|
-
* import { pipe, takeWhile } from "@local/eff"
|
|
783
|
+
* Use to keep the leading elements of an iterable while each element satisfies
|
|
784
|
+
* a predicate, returning the retained prefix as an array.
|
|
785
|
+
*
|
|
786
|
+
* **Details**
|
|
469
787
|
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
788
|
+
* Supports refinements for type narrowing. The predicate receives
|
|
789
|
+
* `(element, index)`.
|
|
790
|
+
*
|
|
791
|
+
* **Example** (Taking while condition holds)
|
|
792
|
+
*
|
|
793
|
+
* ```ts
|
|
794
|
+
* import { Array } from "effect"
|
|
472
795
|
*
|
|
473
|
-
* //
|
|
474
|
-
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
|
|
796
|
+
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
475
797
|
* ```
|
|
476
|
-
*
|
|
798
|
+
*
|
|
799
|
+
* @see {@link take} for keeping a fixed number of leading elements
|
|
800
|
+
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
801
|
+
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
802
|
+
*
|
|
803
|
+
* @category getters
|
|
804
|
+
* @since 2.0.0
|
|
477
805
|
*/
|
|
478
|
-
const takeWhile = dual(2, (
|
|
479
|
-
const
|
|
806
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
807
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
808
|
+
const len = input.length;
|
|
480
809
|
let idx = 0;
|
|
481
|
-
while (idx < len &&
|
|
482
|
-
return
|
|
810
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
811
|
+
return input.slice(0, idx);
|
|
483
812
|
});
|
|
484
813
|
|
|
485
814
|
//#endregion
|
|
@@ -665,7 +994,6 @@ const normalizeSettings = ({ importSource = "react", compilationMode, polymorphi
|
|
|
665
994
|
additionalEffectHooks: toRegExp(additionalEffectHooks)
|
|
666
995
|
};
|
|
667
996
|
};
|
|
668
|
-
const cache = /* @__PURE__ */ new Map();
|
|
669
997
|
/**
|
|
670
998
|
* Get the React version from the project's dependencies.
|
|
671
999
|
* @param fallback The fallback version to return if React is not found.
|
|
@@ -679,14 +1007,20 @@ function getReactVersion(fallback) {
|
|
|
679
1007
|
}
|
|
680
1008
|
}
|
|
681
1009
|
/**
|
|
1010
|
+
* Get the normalized ESLint React settings, memoized by the input settings object.
|
|
1011
|
+
* @param settings The ESLint React settings to decode and normalize.
|
|
1012
|
+
* @returns The normalized ESLint React settings.
|
|
1013
|
+
*/
|
|
1014
|
+
const getNormalizedSettings = memoize((settings) => normalizeSettings(decodeSettings(settings)));
|
|
1015
|
+
/**
|
|
682
1016
|
* Get the normalized ESLint React settings from the rule context.
|
|
683
1017
|
* @param context The rule context.
|
|
684
1018
|
* @returns The normalized ESLint React settings.
|
|
685
1019
|
*/
|
|
686
1020
|
function getSettingsFromContext(context) {
|
|
687
1021
|
const settings = context.settings["react-x"];
|
|
688
|
-
return
|
|
1022
|
+
return getNormalizedSettings(isObjectKeyword(settings) ? settings : DEFAULT_ESLINT_REACT_SETTINGS);
|
|
689
1023
|
}
|
|
690
1024
|
|
|
691
1025
|
//#endregion
|
|
692
|
-
export { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, decodeESLintSettings, decodeSettings, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, toRegExp };
|
|
1026
|
+
export { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, decodeESLintSettings, decodeSettings, getNormalizedSettings, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, toRegExp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.1",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@eslint-react/eslint": "5.24.
|
|
32
|
+
"@eslint-react/eslint": "5.24.1",
|
|
33
33
|
"@typescript-eslint/utils": "^8.71.0",
|
|
34
34
|
"ts-pattern": "^5.9.0",
|
|
35
35
|
"zod": "^3.25.0 || ^4.0.0"
|
|
@@ -40,7 +40,8 @@
|
|
|
40
40
|
"@tsconfig/node24": "^24.0.5",
|
|
41
41
|
"@types/node": "^26.6.4",
|
|
42
42
|
"@types/picomatch": "^4.0.3",
|
|
43
|
-
"eslint": "^10.
|
|
43
|
+
"eslint": "^10.12.0",
|
|
44
|
+
"tinybench": "6.1.4",
|
|
44
45
|
"tsdown": "^0.23.0",
|
|
45
46
|
"typescript": "6.0.3"
|
|
46
47
|
},
|
|
@@ -63,6 +64,7 @@
|
|
|
63
64
|
"@local/eff": "workspace:*"
|
|
64
65
|
},
|
|
65
66
|
"scripts": {
|
|
67
|
+
"bench": "nub ./benchmarks/settings.bench.ts",
|
|
66
68
|
"build": "tsdown",
|
|
67
69
|
"build:docs": "typedoc",
|
|
68
70
|
"lint:publish": "publint",
|