eslint-plugin-react-x 5.24.0-beta.2 → 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.js +415 -87
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ const rules$6 = {
|
|
|
145
145
|
//#endregion
|
|
146
146
|
//#region package.json
|
|
147
147
|
var name$6 = "eslint-plugin-react-x";
|
|
148
|
-
var version = "5.24.
|
|
148
|
+
var version = "5.24.1";
|
|
149
149
|
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/utils/create-rule.ts
|
|
@@ -2094,22 +2094,6 @@ function create$41(context) {
|
|
|
2094
2094
|
|
|
2095
2095
|
//#endregion
|
|
2096
2096
|
//#region ../../.pkgs/eff/dist/index.js
|
|
2097
|
-
function not(predicate) {
|
|
2098
|
-
return (data) => !predicate(data);
|
|
2099
|
-
}
|
|
2100
|
-
function or(a, b) {
|
|
2101
|
-
return (data) => a(data) || b(data);
|
|
2102
|
-
}
|
|
2103
|
-
/**
|
|
2104
|
-
* A function that checks if the passed parameter is a string and narrows its type accordingly.
|
|
2105
|
-
*
|
|
2106
|
-
* @param data - The variable to check.
|
|
2107
|
-
* @returns True if the passed input is a string, false otherwise.
|
|
2108
|
-
* @category guards
|
|
2109
|
-
*/
|
|
2110
|
-
function isString(data) {
|
|
2111
|
-
return typeof data === "string";
|
|
2112
|
-
}
|
|
2113
2097
|
/**
|
|
2114
2098
|
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
2115
2099
|
* to right.
|
|
@@ -2142,7 +2126,7 @@ function isString(data) {
|
|
|
2142
2126
|
* (n) => n + 2,
|
|
2143
2127
|
* (n) => n * 3
|
|
2144
2128
|
* )
|
|
2145
|
-
*
|
|
2129
|
+
* result // => 21
|
|
2146
2130
|
* ```
|
|
2147
2131
|
*
|
|
2148
2132
|
* @category combinators
|
|
@@ -2199,16 +2183,6 @@ const Class = (function() {
|
|
|
2199
2183
|
return PipeableBase;
|
|
2200
2184
|
})();
|
|
2201
2185
|
/**
|
|
2202
|
-
* Provides small helpers for defining and reusing TypeScript functions.
|
|
2203
|
-
*
|
|
2204
|
-
* The main helpers are `pipe` and `flow` for left-to-right composition and
|
|
2205
|
-
* `dual` for APIs that support both direct and pipe-friendly call styles. The
|
|
2206
|
-
* module also contains small identity, constant, tuple, type-level, and
|
|
2207
|
-
* memoization helpers used across the library.
|
|
2208
|
-
*
|
|
2209
|
-
* @since 2.0.0
|
|
2210
|
-
*/
|
|
2211
|
-
/**
|
|
2212
2186
|
* Creates a function that can be called in data-first style or data-last
|
|
2213
2187
|
* (`pipe`-friendly) style.
|
|
2214
2188
|
*
|
|
@@ -2233,8 +2207,8 @@ const Class = (function() {
|
|
|
2233
2207
|
* (self: number, that: number) => number
|
|
2234
2208
|
* >(2, (self, that) => self + that)
|
|
2235
2209
|
*
|
|
2236
|
-
*
|
|
2237
|
-
*
|
|
2210
|
+
* sum(2, 3) // => 5
|
|
2211
|
+
* pipe(2, sum(3)) // => 5
|
|
2238
2212
|
* ```
|
|
2239
2213
|
*
|
|
2240
2214
|
* **Example** (Defining overloads with call signatures)
|
|
@@ -2247,8 +2221,8 @@ const Class = (function() {
|
|
|
2247
2221
|
* (self: number, that: number): number
|
|
2248
2222
|
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
2249
2223
|
*
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2224
|
+
* sum(2, 3) // => 5
|
|
2225
|
+
* pipe(2, sum(3)) // => 5
|
|
2252
2226
|
* ```
|
|
2253
2227
|
*
|
|
2254
2228
|
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
@@ -2264,8 +2238,8 @@ const Class = (function() {
|
|
|
2264
2238
|
* (self, that) => self + that
|
|
2265
2239
|
* )
|
|
2266
2240
|
*
|
|
2267
|
-
*
|
|
2268
|
-
*
|
|
2241
|
+
* sum(2, 3) // => 5
|
|
2242
|
+
* pipe(2, sum(3)) // => 5
|
|
2269
2243
|
* ```
|
|
2270
2244
|
*
|
|
2271
2245
|
* @category combinators
|
|
@@ -2310,9 +2284,8 @@ const dual = function(arity, body) {
|
|
|
2310
2284
|
*
|
|
2311
2285
|
* ```ts
|
|
2312
2286
|
* import { identity } from "effect"
|
|
2313
|
-
* import * as assert from "node:assert"
|
|
2314
2287
|
*
|
|
2315
|
-
*
|
|
2288
|
+
* identity(5) // => 5
|
|
2316
2289
|
* ```
|
|
2317
2290
|
*
|
|
2318
2291
|
* @category combinators
|
|
@@ -2350,12 +2323,11 @@ const cast = identity;
|
|
|
2350
2323
|
*
|
|
2351
2324
|
* ```ts
|
|
2352
2325
|
* import { Function } from "effect"
|
|
2353
|
-
* import * as assert from "node:assert"
|
|
2354
2326
|
*
|
|
2355
2327
|
* const constNull = Function.constant(null)
|
|
2356
2328
|
*
|
|
2357
|
-
*
|
|
2358
|
-
*
|
|
2329
|
+
* constNull() // => null
|
|
2330
|
+
* constNull() // => null
|
|
2359
2331
|
* ```
|
|
2360
2332
|
*
|
|
2361
2333
|
* @category constructors
|
|
@@ -2373,9 +2345,8 @@ const constant = (value) => () => value;
|
|
|
2373
2345
|
*
|
|
2374
2346
|
* ```ts
|
|
2375
2347
|
* import { Function } from "effect"
|
|
2376
|
-
* import * as assert from "node:assert"
|
|
2377
2348
|
*
|
|
2378
|
-
*
|
|
2349
|
+
* Function.constTrue() // => true
|
|
2379
2350
|
* ```
|
|
2380
2351
|
*
|
|
2381
2352
|
* @category constants
|
|
@@ -2393,9 +2364,8 @@ const constTrue = constant(true);
|
|
|
2393
2364
|
*
|
|
2394
2365
|
* ```ts
|
|
2395
2366
|
* import { Function } from "effect"
|
|
2396
|
-
* import * as assert from "node:assert"
|
|
2397
2367
|
*
|
|
2398
|
-
*
|
|
2368
|
+
* Function.constFalse() // => false
|
|
2399
2369
|
* ```
|
|
2400
2370
|
*
|
|
2401
2371
|
* @category constants
|
|
@@ -2413,9 +2383,8 @@ const constFalse = constant(false);
|
|
|
2413
2383
|
*
|
|
2414
2384
|
* ```ts
|
|
2415
2385
|
* import { Function } from "effect"
|
|
2416
|
-
* import * as assert from "node:assert"
|
|
2417
2386
|
*
|
|
2418
|
-
*
|
|
2387
|
+
* Function.constNull() // => null
|
|
2419
2388
|
* ```
|
|
2420
2389
|
*
|
|
2421
2390
|
* @category constants
|
|
@@ -2433,9 +2402,8 @@ const constNull = constant(null);
|
|
|
2433
2402
|
*
|
|
2434
2403
|
* ```ts
|
|
2435
2404
|
* import { Function } from "effect"
|
|
2436
|
-
* import * as assert from "node:assert"
|
|
2437
2405
|
*
|
|
2438
|
-
*
|
|
2406
|
+
* Function.constUndefined() // => undefined
|
|
2439
2407
|
* ```
|
|
2440
2408
|
*
|
|
2441
2409
|
* @category constants
|
|
@@ -2454,12 +2422,11 @@ const constUndefined = constant(void 0);
|
|
|
2454
2422
|
*
|
|
2455
2423
|
* ```ts
|
|
2456
2424
|
* import { Function } from "effect"
|
|
2457
|
-
* import * as assert from "node:assert"
|
|
2458
2425
|
*
|
|
2459
2426
|
* const increment = (n: number) => n + 1
|
|
2460
2427
|
* const square = (n: number) => n * n
|
|
2461
2428
|
*
|
|
2462
|
-
*
|
|
2429
|
+
* Function.compose(increment, square)(2) // => 9
|
|
2463
2430
|
* ```
|
|
2464
2431
|
*
|
|
2465
2432
|
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
@@ -2551,13 +2518,350 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
|
|
|
2551
2518
|
* name: hole<string>()
|
|
2552
2519
|
* })
|
|
2553
2520
|
*
|
|
2554
|
-
* console.log(typeof buildUser) // "function"
|
|
2555
2521
|
* ```
|
|
2556
2522
|
*
|
|
2557
2523
|
* @category utility types
|
|
2558
2524
|
* @since 2.0.0
|
|
2559
2525
|
*/
|
|
2560
2526
|
const hole = cast(absurd);
|
|
2527
|
+
function not(predicate) {
|
|
2528
|
+
return (data) => !predicate(data);
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
2532
|
+
*
|
|
2533
|
+
* **When to use**
|
|
2534
|
+
*
|
|
2535
|
+
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
2536
|
+
* satisfy multiple conditions, including refinements that narrow to an
|
|
2537
|
+
* intersection.
|
|
2538
|
+
*
|
|
2539
|
+
* **Details**
|
|
2540
|
+
*
|
|
2541
|
+
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
2542
|
+
* type is an intersection.
|
|
2543
|
+
*
|
|
2544
|
+
* **Example** (Checking both conditions)
|
|
2545
|
+
*
|
|
2546
|
+
* ```ts
|
|
2547
|
+
* import { Predicate } from "effect"
|
|
2548
|
+
*
|
|
2549
|
+
* const hasAAndB = Predicate.and(
|
|
2550
|
+
* Predicate.hasProperty("a"),
|
|
2551
|
+
* Predicate.hasProperty("b")
|
|
2552
|
+
* )
|
|
2553
|
+
*
|
|
2554
|
+
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
2555
|
+
* if (hasAAndB(input)) {
|
|
2556
|
+
* // input has both properties at this point
|
|
2557
|
+
* const a = input.a
|
|
2558
|
+
* const b = input.b
|
|
2559
|
+
*
|
|
2560
|
+
* const values = [a, b] // => [1, "ok"]
|
|
2561
|
+
* }
|
|
2562
|
+
* ```
|
|
2563
|
+
*
|
|
2564
|
+
* @see {@link or}
|
|
2565
|
+
* @see {@link not}
|
|
2566
|
+
* @category combinators
|
|
2567
|
+
* @since 2.0.0
|
|
2568
|
+
*/
|
|
2569
|
+
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
2570
|
+
/**
|
|
2571
|
+
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
2572
|
+
*
|
|
2573
|
+
* **When to use**
|
|
2574
|
+
*
|
|
2575
|
+
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
2576
|
+
* satisfy at least one condition, including refinements that narrow to a union.
|
|
2577
|
+
*
|
|
2578
|
+
* **Details**
|
|
2579
|
+
*
|
|
2580
|
+
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
2581
|
+
* type is a union.
|
|
2582
|
+
*
|
|
2583
|
+
* **Example** (Checking either condition)
|
|
2584
|
+
*
|
|
2585
|
+
* ```ts
|
|
2586
|
+
* import { Predicate } from "effect"
|
|
2587
|
+
*
|
|
2588
|
+
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
2589
|
+
*
|
|
2590
|
+
* isStringOrNumber("a") // => true
|
|
2591
|
+
* ```
|
|
2592
|
+
*
|
|
2593
|
+
* @see {@link and}
|
|
2594
|
+
* @see {@link xor}
|
|
2595
|
+
* @category combinators
|
|
2596
|
+
* @since 2.0.0
|
|
2597
|
+
*/
|
|
2598
|
+
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
2599
|
+
/**
|
|
2600
|
+
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
2601
|
+
*
|
|
2602
|
+
* **When to use**
|
|
2603
|
+
*
|
|
2604
|
+
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
2605
|
+
*
|
|
2606
|
+
* **Details**
|
|
2607
|
+
*
|
|
2608
|
+
* Returns `true` when results differ.
|
|
2609
|
+
*
|
|
2610
|
+
* **Example** (Checking exclusive-or conditions)
|
|
2611
|
+
*
|
|
2612
|
+
* ```ts
|
|
2613
|
+
* import { Predicate } from "effect"
|
|
2614
|
+
*
|
|
2615
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
2616
|
+
* const isPositive = (n: number) => n > 0
|
|
2617
|
+
* const either = Predicate.xor(isEven, isPositive)
|
|
2618
|
+
*
|
|
2619
|
+
* either(-2) // => true
|
|
2620
|
+
* ```
|
|
2621
|
+
*
|
|
2622
|
+
* @see {@link or}
|
|
2623
|
+
* @see {@link and}
|
|
2624
|
+
* @category combinators
|
|
2625
|
+
* @since 2.0.0
|
|
2626
|
+
*/
|
|
2627
|
+
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
2628
|
+
/**
|
|
2629
|
+
* Creates a predicate that returns `true` when both predicates agree.
|
|
2630
|
+
*
|
|
2631
|
+
* **When to use**
|
|
2632
|
+
*
|
|
2633
|
+
* Use when you want to check equivalence of two `Predicate`s.
|
|
2634
|
+
*
|
|
2635
|
+
* **Details**
|
|
2636
|
+
*
|
|
2637
|
+
* Returns `true` when both results are equal.
|
|
2638
|
+
*
|
|
2639
|
+
* **Example** (Defining equivalence)
|
|
2640
|
+
*
|
|
2641
|
+
* ```ts
|
|
2642
|
+
* import { Predicate } from "effect"
|
|
2643
|
+
*
|
|
2644
|
+
* const isEven = (n: number) => n % 2 === 0
|
|
2645
|
+
* const same = Predicate.eqv(isEven, isEven)
|
|
2646
|
+
*
|
|
2647
|
+
* same(3) // => true
|
|
2648
|
+
* ```
|
|
2649
|
+
*
|
|
2650
|
+
* @see {@link xor}
|
|
2651
|
+
* @category combinators
|
|
2652
|
+
* @since 2.0.0
|
|
2653
|
+
*/
|
|
2654
|
+
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
2655
|
+
/**
|
|
2656
|
+
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
2657
|
+
*
|
|
2658
|
+
* **When to use**
|
|
2659
|
+
*
|
|
2660
|
+
* Use when you need to encode logical implication between `Predicate` rules,
|
|
2661
|
+
* where one rule only applies when a precondition holds.
|
|
2662
|
+
*
|
|
2663
|
+
* **Details**
|
|
2664
|
+
*
|
|
2665
|
+
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
2666
|
+
* is `false`.
|
|
2667
|
+
*
|
|
2668
|
+
* **Example** (Checking implication)
|
|
2669
|
+
*
|
|
2670
|
+
* ```ts
|
|
2671
|
+
* import { Predicate } from "effect"
|
|
2672
|
+
*
|
|
2673
|
+
* const isAdult = (age: number) => age >= 18
|
|
2674
|
+
* const canVote = (age: number) => age >= 18
|
|
2675
|
+
* const implies = Predicate.implies(isAdult, canVote)
|
|
2676
|
+
*
|
|
2677
|
+
* implies(16) // => true
|
|
2678
|
+
* ```
|
|
2679
|
+
*
|
|
2680
|
+
* @see {@link and}
|
|
2681
|
+
* @see {@link or}
|
|
2682
|
+
* @category combinators
|
|
2683
|
+
* @since 2.0.0
|
|
2684
|
+
*/
|
|
2685
|
+
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
2686
|
+
/**
|
|
2687
|
+
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
2688
|
+
*
|
|
2689
|
+
* **When to use**
|
|
2690
|
+
*
|
|
2691
|
+
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
2692
|
+
*
|
|
2693
|
+
* **Details**
|
|
2694
|
+
*
|
|
2695
|
+
* Returns the negation of `or`.
|
|
2696
|
+
*
|
|
2697
|
+
* **Example** (Checking NOR conditions)
|
|
2698
|
+
*
|
|
2699
|
+
* ```ts
|
|
2700
|
+
* import { Predicate } from "effect"
|
|
2701
|
+
*
|
|
2702
|
+
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
2703
|
+
*
|
|
2704
|
+
* neither(true) // => true
|
|
2705
|
+
* ```
|
|
2706
|
+
*
|
|
2707
|
+
* @see {@link or}
|
|
2708
|
+
* @see {@link not}
|
|
2709
|
+
* @category combinators
|
|
2710
|
+
* @since 2.0.0
|
|
2711
|
+
*/
|
|
2712
|
+
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
2713
|
+
/**
|
|
2714
|
+
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
2715
|
+
*
|
|
2716
|
+
* **When to use**
|
|
2717
|
+
*
|
|
2718
|
+
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
2719
|
+
*
|
|
2720
|
+
* **Details**
|
|
2721
|
+
*
|
|
2722
|
+
* Returns the negation of `and`.
|
|
2723
|
+
*
|
|
2724
|
+
* **Example** (Checking NAND conditions)
|
|
2725
|
+
*
|
|
2726
|
+
* ```ts
|
|
2727
|
+
* import { Predicate } from "effect"
|
|
2728
|
+
*
|
|
2729
|
+
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
2730
|
+
*
|
|
2731
|
+
* notBoth("a") // => true
|
|
2732
|
+
* ```
|
|
2733
|
+
*
|
|
2734
|
+
* @see {@link and}
|
|
2735
|
+
* @see {@link not}
|
|
2736
|
+
* @category combinators
|
|
2737
|
+
* @since 2.0.0
|
|
2738
|
+
*/
|
|
2739
|
+
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
2740
|
+
/**
|
|
2741
|
+
* Checks whether a value is a `string`.
|
|
2742
|
+
*
|
|
2743
|
+
* **When to use**
|
|
2744
|
+
*
|
|
2745
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
2746
|
+
* string.
|
|
2747
|
+
*
|
|
2748
|
+
* **Details**
|
|
2749
|
+
*
|
|
2750
|
+
* Uses `typeof input === "string"`.
|
|
2751
|
+
*
|
|
2752
|
+
* **Example** (Guarding strings)
|
|
2753
|
+
*
|
|
2754
|
+
* ```ts
|
|
2755
|
+
* import { Predicate } from "effect"
|
|
2756
|
+
*
|
|
2757
|
+
* const data: unknown = "hi"
|
|
2758
|
+
*
|
|
2759
|
+
* if (Predicate.isString(data)) {
|
|
2760
|
+
* data.toUpperCase() // => "HI"
|
|
2761
|
+
* }
|
|
2762
|
+
* ```
|
|
2763
|
+
*
|
|
2764
|
+
* @see {@link isNumber}
|
|
2765
|
+
* @see {@link isBoolean}
|
|
2766
|
+
* @see {@link Refinement}
|
|
2767
|
+
* @category guards
|
|
2768
|
+
* @since 2.0.0
|
|
2769
|
+
*/
|
|
2770
|
+
function isString(input) {
|
|
2771
|
+
return typeof input === "string";
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* Checks whether a value is a `function`.
|
|
2775
|
+
*
|
|
2776
|
+
* **When to use**
|
|
2777
|
+
*
|
|
2778
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
2779
|
+
* callable function.
|
|
2780
|
+
*
|
|
2781
|
+
* **Details**
|
|
2782
|
+
*
|
|
2783
|
+
* Uses `typeof input === "function"`.
|
|
2784
|
+
*
|
|
2785
|
+
* **Example** (Guarding functions)
|
|
2786
|
+
*
|
|
2787
|
+
* ```ts
|
|
2788
|
+
* import { Predicate } from "effect"
|
|
2789
|
+
*
|
|
2790
|
+
* const data: unknown = () => 1
|
|
2791
|
+
*
|
|
2792
|
+
* if (Predicate.isFunction(data)) {
|
|
2793
|
+
* data() // => 1
|
|
2794
|
+
* }
|
|
2795
|
+
* ```
|
|
2796
|
+
*
|
|
2797
|
+
* @see {@link isObjectKeyword}
|
|
2798
|
+
* @category guards
|
|
2799
|
+
* @since 2.0.0
|
|
2800
|
+
*/
|
|
2801
|
+
function isFunction(input) {
|
|
2802
|
+
return typeof input === "function";
|
|
2803
|
+
}
|
|
2804
|
+
/**
|
|
2805
|
+
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
2806
|
+
*
|
|
2807
|
+
* **When to use**
|
|
2808
|
+
*
|
|
2809
|
+
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
2810
|
+
* well as objects.
|
|
2811
|
+
*
|
|
2812
|
+
* **Details**
|
|
2813
|
+
*
|
|
2814
|
+
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
2815
|
+
*
|
|
2816
|
+
* **Example** (Checking object keywords)
|
|
2817
|
+
*
|
|
2818
|
+
* ```ts
|
|
2819
|
+
* import { Predicate } from "effect"
|
|
2820
|
+
*
|
|
2821
|
+
* Predicate.isObjectKeyword(() => 1) // => true
|
|
2822
|
+
* Predicate.isObjectKeyword(null) // => false
|
|
2823
|
+
* ```
|
|
2824
|
+
*
|
|
2825
|
+
* @see {@link isObject}
|
|
2826
|
+
* @see {@link isObjectOrArray}
|
|
2827
|
+
* @category guards
|
|
2828
|
+
* @since 4.0.0
|
|
2829
|
+
*/
|
|
2830
|
+
function isObjectKeyword(input) {
|
|
2831
|
+
return typeof input === "object" && input !== null || isFunction(input);
|
|
2832
|
+
}
|
|
2833
|
+
/**
|
|
2834
|
+
* Checks whether a value has a given property key.
|
|
2835
|
+
*
|
|
2836
|
+
* **When to use**
|
|
2837
|
+
*
|
|
2838
|
+
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
2839
|
+
* values with a simple structural object check.
|
|
2840
|
+
*
|
|
2841
|
+
* **Details**
|
|
2842
|
+
*
|
|
2843
|
+
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
2844
|
+
* value types.
|
|
2845
|
+
*
|
|
2846
|
+
* **Example** (Guarding object properties)
|
|
2847
|
+
*
|
|
2848
|
+
* ```ts
|
|
2849
|
+
* import { Predicate } from "effect"
|
|
2850
|
+
*
|
|
2851
|
+
* const hasName = Predicate.hasProperty("name")
|
|
2852
|
+
* const data: unknown = { name: "Ada" }
|
|
2853
|
+
*
|
|
2854
|
+
* if (hasName(data)) {
|
|
2855
|
+
* data.name // => "Ada"
|
|
2856
|
+
* }
|
|
2857
|
+
* ```
|
|
2858
|
+
*
|
|
2859
|
+
* @see {@link isTagged}
|
|
2860
|
+
* @see {@link isObjectKeyword}
|
|
2861
|
+
* @category guards
|
|
2862
|
+
* @since 2.0.0
|
|
2863
|
+
*/
|
|
2864
|
+
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
2561
2865
|
function getOrInsertComputed(map, key, callback) {
|
|
2562
2866
|
if (map.has(key)) return map.get(key);
|
|
2563
2867
|
const value = callback(key);
|
|
@@ -2565,56 +2869,72 @@ function getOrInsertComputed(map, key, callback) {
|
|
|
2565
2869
|
return value;
|
|
2566
2870
|
}
|
|
2567
2871
|
/**
|
|
2568
|
-
* Drops
|
|
2872
|
+
* Drops elements from the start while the predicate holds, returning the rest.
|
|
2569
2873
|
*
|
|
2570
|
-
*
|
|
2874
|
+
* **When to use**
|
|
2571
2875
|
*
|
|
2572
|
-
*
|
|
2573
|
-
* @returns A new array without the matching prefix.
|
|
2574
|
-
* @example
|
|
2575
|
-
* ```ts
|
|
2576
|
-
* import * as assert from "node:assert"
|
|
2577
|
-
* import { dropWhile, pipe } from "@local/eff"
|
|
2876
|
+
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
2578
2877
|
*
|
|
2579
|
-
*
|
|
2580
|
-
* assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
|
|
2878
|
+
* **Details**
|
|
2581
2879
|
*
|
|
2582
|
-
*
|
|
2583
|
-
*
|
|
2880
|
+
* The predicate receives `(element, index)`.
|
|
2881
|
+
*
|
|
2882
|
+
* **Example** (Dropping while condition holds)
|
|
2883
|
+
*
|
|
2884
|
+
* ```ts
|
|
2885
|
+
* import { Array } from "effect"
|
|
2886
|
+
*
|
|
2887
|
+
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
2584
2888
|
* ```
|
|
2585
|
-
*
|
|
2889
|
+
*
|
|
2890
|
+
* @see {@link takeWhile} — keep the matching prefix instead
|
|
2891
|
+
* @see {@link drop} — drop a fixed count
|
|
2892
|
+
*
|
|
2893
|
+
* @category getters
|
|
2894
|
+
* @since 2.0.0
|
|
2586
2895
|
*/
|
|
2587
|
-
const dropWhile = dual(2, (
|
|
2588
|
-
const
|
|
2896
|
+
const dropWhile = dual(2, (self, predicate) => {
|
|
2897
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
2898
|
+
const len = input.length;
|
|
2589
2899
|
let idx = 0;
|
|
2590
|
-
while (idx < len &&
|
|
2591
|
-
return
|
|
2900
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
2901
|
+
return input.slice(idx);
|
|
2592
2902
|
});
|
|
2593
2903
|
/**
|
|
2594
|
-
* Takes
|
|
2904
|
+
* Takes elements from the start while the predicate holds, stopping at the
|
|
2905
|
+
* first element that fails.
|
|
2595
2906
|
*
|
|
2596
|
-
*
|
|
2907
|
+
* **When to use**
|
|
2597
2908
|
*
|
|
2598
|
-
*
|
|
2599
|
-
*
|
|
2600
|
-
*
|
|
2601
|
-
*
|
|
2602
|
-
*
|
|
2603
|
-
*
|
|
2909
|
+
* Use to keep the leading elements of an iterable while each element satisfies
|
|
2910
|
+
* a predicate, returning the retained prefix as an array.
|
|
2911
|
+
*
|
|
2912
|
+
* **Details**
|
|
2913
|
+
*
|
|
2914
|
+
* Supports refinements for type narrowing. The predicate receives
|
|
2915
|
+
* `(element, index)`.
|
|
2604
2916
|
*
|
|
2605
|
-
*
|
|
2606
|
-
*
|
|
2917
|
+
* **Example** (Taking while condition holds)
|
|
2918
|
+
*
|
|
2919
|
+
* ```ts
|
|
2920
|
+
* import { Array } from "effect"
|
|
2607
2921
|
*
|
|
2608
|
-
* //
|
|
2609
|
-
* assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
|
|
2922
|
+
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
2610
2923
|
* ```
|
|
2611
|
-
*
|
|
2924
|
+
*
|
|
2925
|
+
* @see {@link take} for keeping a fixed number of leading elements
|
|
2926
|
+
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
2927
|
+
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
2928
|
+
*
|
|
2929
|
+
* @category getters
|
|
2930
|
+
* @since 2.0.0
|
|
2612
2931
|
*/
|
|
2613
|
-
const takeWhile = dual(2, (
|
|
2614
|
-
const
|
|
2932
|
+
const takeWhile = dual(2, (self, predicate) => {
|
|
2933
|
+
const input = Array.isArray(self) ? self : Array.from(self);
|
|
2934
|
+
const len = input.length;
|
|
2615
2935
|
let idx = 0;
|
|
2616
|
-
while (idx < len &&
|
|
2617
|
-
return
|
|
2936
|
+
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
2937
|
+
return input.slice(0, idx);
|
|
2618
2938
|
});
|
|
2619
2939
|
|
|
2620
2940
|
//#endregion
|
|
@@ -3455,6 +3775,12 @@ function create$24(context) {
|
|
|
3455
3775
|
*/
|
|
3456
3776
|
function visitItemExpression(node) {
|
|
3457
3777
|
switch (node.type) {
|
|
3778
|
+
case AST_NODE_TYPES.ChainExpression:
|
|
3779
|
+
case AST_NODE_TYPES.TSAsExpression:
|
|
3780
|
+
case AST_NODE_TYPES.TSTypeAssertion:
|
|
3781
|
+
case AST_NODE_TYPES.TSNonNullExpression:
|
|
3782
|
+
case AST_NODE_TYPES.TSSatisfiesExpression:
|
|
3783
|
+
case AST_NODE_TYPES.TSInstantiationExpression: return visitItemExpression(node.expression);
|
|
3458
3784
|
case AST_NODE_TYPES.JSXElement: return hasAttribute(context, node, "key") ? [] : [{
|
|
3459
3785
|
messageId: "default",
|
|
3460
3786
|
node
|
|
@@ -8232,6 +8558,7 @@ function inferViolations$2(context, facts) {
|
|
|
8232
8558
|
const resolver = createSetStateResolver$1(context);
|
|
8233
8559
|
const getText = (n) => context.sourceCode.getText(n);
|
|
8234
8560
|
const isUseEffectCall = (node) => core.isUseEffectLikeCall(node, additionalEffectHooks);
|
|
8561
|
+
const isUseStateOrThenCall = or(resolver.isUseStateCall, isThenCall);
|
|
8235
8562
|
const setStateCallsByFn = /* @__PURE__ */ new Map();
|
|
8236
8563
|
const setStateInHookCallbacks = /* @__PURE__ */ new Map();
|
|
8237
8564
|
const setStateInEffectArg = /* @__PURE__ */ new Map();
|
|
@@ -8239,7 +8566,7 @@ function inferViolations$2(context, facts) {
|
|
|
8239
8566
|
const trackedFnCalls = [];
|
|
8240
8567
|
const violations = [];
|
|
8241
8568
|
for (const { enclosingFunction, enclosingFunctionKind, node, setupFunction } of facts.calls) {
|
|
8242
|
-
if (
|
|
8569
|
+
if (isUseStateOrThenCall(node)) continue;
|
|
8243
8570
|
if (!resolver.isSetStateCall(node)) {
|
|
8244
8571
|
if (setupFunction != null && enclosingFunction === setupFunction) trackedFnCalls.push(node);
|
|
8245
8572
|
continue;
|
|
@@ -8355,11 +8682,12 @@ function create$5(context) {
|
|
|
8355
8682
|
|
|
8356
8683
|
//#endregion
|
|
8357
8684
|
//#region src/rules/set-state-in-render/helpers.ts
|
|
8685
|
+
const isComponentOrHookName = or(core.isFunctionComponentName, core.isHookName);
|
|
8358
8686
|
function isComponentOrHookLikeFunction(node) {
|
|
8359
8687
|
const id = core.getFunctionId(node);
|
|
8360
8688
|
if (id == null) return false;
|
|
8361
|
-
if (Check.isIdentifier(id)) return
|
|
8362
|
-
if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return
|
|
8689
|
+
if (Check.isIdentifier(id)) return isComponentOrHookName(id.name);
|
|
8690
|
+
if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isComponentOrHookName(id.property.name);
|
|
8363
8691
|
return false;
|
|
8364
8692
|
}
|
|
8365
8693
|
function isInsideConditional(node, stopAt) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.1",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@eslint-react/ast": "5.24.
|
|
40
|
-
"@eslint-react/core": "5.24.
|
|
41
|
-
"@eslint-react/eslint": "5.24.
|
|
42
|
-
"@eslint-react/jsx": "5.24.
|
|
43
|
-
"@eslint-react/shared": "5.24.
|
|
44
|
-
"@eslint-react/var": "5.24.
|
|
39
|
+
"@eslint-react/ast": "5.24.1",
|
|
40
|
+
"@eslint-react/core": "5.24.1",
|
|
41
|
+
"@eslint-react/eslint": "5.24.1",
|
|
42
|
+
"@eslint-react/jsx": "5.24.1",
|
|
43
|
+
"@eslint-react/shared": "5.24.1",
|
|
44
|
+
"@eslint-react/var": "5.24.1",
|
|
45
45
|
"@typescript-eslint/scope-manager": "^8.71.0",
|
|
46
46
|
"@typescript-eslint/types": "^8.71.0",
|
|
47
47
|
"@typescript-eslint/typescript-estree": "^8.71.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@types/react": "^19.3.0",
|
|
60
60
|
"@types/react-dom": "^19.3.0",
|
|
61
61
|
"dedent": "^1.7.2",
|
|
62
|
-
"eslint": "^10.
|
|
62
|
+
"eslint": "^10.12.0",
|
|
63
63
|
"react": "^19.3.0",
|
|
64
64
|
"react-dom": "^19.3.0",
|
|
65
65
|
"tsdown": "^0.23.0",
|