eslint-plugin-react-x 5.16.1 → 5.17.0

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 +357 -36
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -144,7 +144,7 @@ const rules$6 = {
144
144
  //#endregion
145
145
  //#region package.json
146
146
  var name$6 = "eslint-plugin-react-x";
147
- var version = "5.16.1";
147
+ var version = "5.17.0";
148
148
 
149
149
  //#endregion
150
150
  //#region src/utils/create-rule.ts
@@ -2492,28 +2492,124 @@ function not(predicate) {
2492
2492
  return (data) => !predicate(data);
2493
2493
  }
2494
2494
  /**
2495
- * Creates a function that can be used in a data-last (aka `pipe`able) or
2496
- * data-first style.
2495
+ * Applies a `pipe` method's variadic arguments to an initial value from left
2496
+ * to right.
2497
2497
  *
2498
- * The first parameter to `dual` is either the arity of the uncurried function
2499
- * or a predicate that determines if the function is being used in a data-first
2500
- * or data-last style.
2498
+ * **When to use**
2501
2499
  *
2502
- * Using the arity is the most common use case, but there are some cases where
2503
- * you may want to use a predicate. For example, if you have a function that
2504
- * takes an optional argument, you can use a predicate to determine if the
2505
- * function is being used in a data-first or data-last style.
2500
+ * Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
2501
+ * object.
2506
2502
  *
2507
- * You can pass either the arity of the uncurried function or a predicate
2508
- * which determines if the function is being used in a data-first or
2509
- * data-last style.
2503
+ * **Details**
2510
2504
  *
2511
- * **Example** (Using arity to determine data-first or data-last style)
2505
+ * This helper is intended for implementing `Pipeable.pipe` methods that
2506
+ * receive JavaScript's `arguments` object. With no functions it returns the
2507
+ * original value; otherwise it feeds each result into the next function.
2508
+ *
2509
+ * **Example** (Implementing a pipe method)
2512
2510
  *
2513
2511
  * ```ts
2514
- * import { dual, pipe } from "effect/Function"
2512
+ * import { Pipeable } from "effect"
2513
+ *
2514
+ * class NumberBox {
2515
+ * constructor(readonly value: number) {}
2516
+ *
2517
+ * pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
2518
+ * return Pipeable.pipeArguments(this.value, arguments) as number
2519
+ * }
2520
+ * }
2521
+ *
2522
+ * const result = new NumberBox(5).pipe(
2523
+ * (n) => n + 2,
2524
+ * (n) => n * 3
2525
+ * )
2526
+ * console.log(result) // 21
2527
+ * ```
2528
+ *
2529
+ * @category combinators
2530
+ * @since 2.0.0
2531
+ */
2532
+ const pipeArguments = (self, args) => {
2533
+ switch (args.length) {
2534
+ case 0: return self;
2535
+ case 1: return args[0](self);
2536
+ case 2: return args[1](args[0](self));
2537
+ case 3: return args[2](args[1](args[0](self)));
2538
+ case 4: return args[3](args[2](args[1](args[0](self))));
2539
+ case 5: return args[4](args[3](args[2](args[1](args[0](self)))));
2540
+ case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
2541
+ case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
2542
+ case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
2543
+ case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
2544
+ default: {
2545
+ let ret = self;
2546
+ for (let i = 0, len = args.length; i < len; i++) ret = args[i](ret);
2547
+ return ret;
2548
+ }
2549
+ }
2550
+ };
2551
+ /**
2552
+ * Reusable prototype that implements `Pipeable.pipe`.
2553
+ *
2554
+ * **When to use**
2555
+ *
2556
+ * Use when classes or object prototypes can reuse this value when they need the
2557
+ * standard pipe implementation backed by `pipeArguments`.
2558
+ *
2559
+ * @category prototypes
2560
+ * @since 3.15.0
2561
+ */
2562
+ const Prototype = { pipe() {
2563
+ return pipeArguments(this, arguments);
2564
+ } };
2565
+ /**
2566
+ * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
2567
+ * method.
2568
+ *
2569
+ * **When to use**
2570
+ *
2571
+ * Use when you need to define a class that supports Effect-style method
2572
+ * chaining through `.pipe(...)`.
2515
2573
  *
2516
- * const sum = dual<
2574
+ * @category constructors
2575
+ * @since 3.15.0
2576
+ */
2577
+ const Class = (function() {
2578
+ function PipeableBase() {}
2579
+ PipeableBase.prototype = Prototype;
2580
+ return PipeableBase;
2581
+ })();
2582
+ /**
2583
+ * Provides small helpers for defining and reusing TypeScript functions.
2584
+ *
2585
+ * The main helpers are `pipe` and `flow` for left-to-right composition and
2586
+ * `dual` for APIs that support both direct and pipe-friendly call styles. The
2587
+ * module also contains small identity, constant, tuple, type-level, and
2588
+ * memoization helpers used across the library.
2589
+ *
2590
+ * @since 2.0.0
2591
+ */
2592
+ /**
2593
+ * Creates a function that can be called in data-first style or data-last
2594
+ * (`pipe`-friendly) style.
2595
+ *
2596
+ * **When to use**
2597
+ *
2598
+ * Use to expose one implementation through both direct and `pipe`-friendly
2599
+ * call styles.
2600
+ *
2601
+ * **Details**
2602
+ *
2603
+ * Pass either the arity of the uncurried function or a predicate that decides
2604
+ * whether the current call is data-first. Arity is the common case. Use a
2605
+ * predicate when optional arguments make arity ambiguous.
2606
+ *
2607
+ * **Example** (Selecting data-first or data-last style by arity)
2608
+ *
2609
+ * ```ts
2610
+ * import { Function, pipe } from "effect"
2611
+ *
2612
+ * const sum = Function.dual<
2517
2613
  * (that: number) => (self: number) => number,
2518
2614
  * (self: number, that: number) => number
2519
2615
  * >(2, (self, that) => self + that)
@@ -2522,26 +2618,26 @@ function not(predicate) {
2522
2618
  * console.log(pipe(2, sum(3))) // 5
2523
2619
  * ```
2524
2620
  *
2525
- * **Example** (Using call signatures to define the overloads)
2621
+ * **Example** (Defining overloads with call signatures)
2526
2622
  *
2527
2623
  * ```ts
2528
- * import { dual, pipe } from "effect/Function"
2624
+ * import { Function, pipe } from "effect"
2529
2625
  *
2530
2626
  * const sum: {
2531
2627
  * (that: number): (self: number) => number
2532
2628
  * (self: number, that: number): number
2533
- * } = dual(2, (self: number, that: number): number => self + that)
2629
+ * } = Function.dual(2, (self: number, that: number): number => self + that)
2534
2630
  *
2535
2631
  * console.log(sum(2, 3)) // 5
2536
2632
  * console.log(pipe(2, sum(3))) // 5
2537
2633
  * ```
2538
2634
  *
2539
- * **Example** (Using a predicate to determine data-first or data-last style)
2635
+ * **Example** (Selecting data-first or data-last style with a predicate)
2540
2636
  *
2541
2637
  * ```ts
2542
- * import { dual, pipe } from "effect/Function"
2638
+ * import { Function, pipe } from "effect"
2543
2639
  *
2544
- * const sum = dual<
2640
+ * const sum = Function.dual<
2545
2641
  * (that: number) => (self: number) => number,
2546
2642
  * (self: number, that: number) => number
2547
2643
  * >(
@@ -2553,9 +2649,8 @@ function not(predicate) {
2553
2649
  * console.log(pipe(2, sum(3))) // 5
2554
2650
  * ```
2555
2651
  *
2556
- * @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style.
2557
- * @param body - The function to be curried.
2558
- * @since 1.0.0
2652
+ * @category combinators
2653
+ * @since 2.0.0
2559
2654
  */
2560
2655
  const dual = function(arity, body) {
2561
2656
  if (typeof arity === "function") return function() {
@@ -2586,30 +2681,226 @@ const dual = function(arity, body) {
2586
2681
  }
2587
2682
  };
2588
2683
  /**
2589
- * Do nothing and return `void`.
2684
+ * Returns its input argument unchanged.
2685
+ *
2686
+ * **When to use**
2687
+ *
2688
+ * Use to return a value unchanged where a function is required.
2689
+ *
2690
+ * **Example** (Returning the same value)
2691
+ *
2692
+ * ```ts
2693
+ * import { identity } from "effect"
2694
+ * import * as assert from "node:assert"
2695
+ *
2696
+ * assert.deepStrictEqual(identity(5), 5)
2697
+ * ```
2698
+ *
2699
+ * @category combinators
2700
+ * @since 2.0.0
2701
+ */
2702
+ const identity = (a) => a;
2703
+ /**
2704
+ * Returns the input value with a different static type.
2705
+ *
2706
+ * **When to use**
2707
+ *
2708
+ * Use when you need an explicit type-level cast and accept that the value is
2709
+ * returned unchanged at runtime.
2710
+ *
2711
+ * **Gotchas**
2712
+ *
2713
+ * This is a type-level cast only; it performs no runtime validation or
2714
+ * conversion.
2715
+ *
2716
+ * @see {@link satisfies} for checking assignability without changing the resulting type
2717
+ *
2718
+ * @category utility types
2719
+ * @since 4.0.0
2590
2720
  */
2591
- function constVoid() {}
2721
+ const cast = identity;
2722
+ /**
2723
+ * Creates a zero-argument function that always returns the provided value.
2724
+ *
2725
+ * **When to use**
2726
+ *
2727
+ * Use when you need a thunk or callback that returns the same value on every
2728
+ * invocation.
2729
+ *
2730
+ * **Example** (Creating a constant thunk)
2731
+ *
2732
+ * ```ts
2733
+ * import { Function } from "effect"
2734
+ * import * as assert from "node:assert"
2735
+ *
2736
+ * const constNull = Function.constant(null)
2737
+ *
2738
+ * assert.deepStrictEqual(constNull(), null)
2739
+ * assert.deepStrictEqual(constNull(), null)
2740
+ * ```
2741
+ *
2742
+ * @category constructors
2743
+ * @since 2.0.0
2744
+ */
2745
+ const constant = (value) => () => value;
2746
+ /**
2747
+ * Returns `true` when called.
2748
+ *
2749
+ * **When to use**
2750
+ *
2751
+ * Use when you need a thunk that returns `true` on every invocation.
2752
+ *
2753
+ * **Example** (Returning true from a thunk)
2754
+ *
2755
+ * ```ts
2756
+ * import { Function } from "effect"
2757
+ * import * as assert from "node:assert"
2758
+ *
2759
+ * assert.deepStrictEqual(Function.constTrue(), true)
2760
+ * ```
2761
+ *
2762
+ * @category constants
2763
+ * @since 2.0.0
2764
+ */
2765
+ const constTrue = constant(true);
2766
+ /**
2767
+ * Returns `false` when called.
2768
+ *
2769
+ * **When to use**
2770
+ *
2771
+ * Use when you need a thunk that returns `false` on every invocation.
2772
+ *
2773
+ * **Example** (Returning false from a thunk)
2774
+ *
2775
+ * ```ts
2776
+ * import { Function } from "effect"
2777
+ * import * as assert from "node:assert"
2778
+ *
2779
+ * assert.deepStrictEqual(Function.constFalse(), false)
2780
+ * ```
2781
+ *
2782
+ * @category constants
2783
+ * @since 2.0.0
2784
+ */
2785
+ const constFalse = constant(false);
2786
+ /**
2787
+ * Returns `null` when called.
2788
+ *
2789
+ * **When to use**
2790
+ *
2791
+ * Use when you need a thunk that returns `null` on every invocation.
2792
+ *
2793
+ * **Example** (Returning null from a thunk)
2794
+ *
2795
+ * ```ts
2796
+ * import { Function } from "effect"
2797
+ * import * as assert from "node:assert"
2798
+ *
2799
+ * assert.deepStrictEqual(Function.constNull(), null)
2800
+ * ```
2801
+ *
2802
+ * @category constants
2803
+ * @since 2.0.0
2804
+ */
2805
+ const constNull = constant(null);
2806
+ /**
2807
+ * Returns `undefined` when called.
2808
+ *
2809
+ * **When to use**
2810
+ *
2811
+ * Use when you need a thunk that returns `undefined` on every invocation.
2812
+ *
2813
+ * **Example** (Returning undefined from a thunk)
2814
+ *
2815
+ * ```ts
2816
+ * import { Function } from "effect"
2817
+ * import * as assert from "node:assert"
2818
+ *
2819
+ * assert.deepStrictEqual(Function.constUndefined(), undefined)
2820
+ * ```
2821
+ *
2822
+ * @category constants
2823
+ * @since 2.0.0
2824
+ */
2825
+ const constUndefined = constant(void 0);
2826
+ /**
2827
+ * Returns no meaningful value when called.
2828
+ *
2829
+ * **When to use**
2830
+ *
2831
+ * Use when you need a thunk that is called only for its effect and has no
2832
+ * meaningful return value.
2833
+ *
2834
+ * **Example** (Returning void from a thunk)
2835
+ *
2836
+ * ```ts
2837
+ * import { Function } from "effect"
2838
+ * import * as assert from "node:assert"
2839
+ *
2840
+ * assert.deepStrictEqual(Function.constVoid(), undefined)
2841
+ * ```
2842
+ *
2843
+ * @category constants
2844
+ * @since 2.0.0
2845
+ */
2846
+ const constVoid = constUndefined;
2592
2847
  /**
2593
2848
  * 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`.
2594
2849
  * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
2595
2850
  *
2596
- * @param self - The first function to apply (or the composed function in data-last style).
2597
- * @param bc - The second function to apply.
2598
- * @returns A composed function that applies both functions in sequence.
2599
- * @example
2851
+ * **When to use**
2852
+ *
2853
+ * Use to compose exactly two unary functions into a reusable unary function.
2854
+ *
2855
+ * **Example** (Composing two functions)
2856
+ *
2600
2857
  * ```ts
2858
+ * import { Function } from "effect"
2601
2859
  * import * as assert from "node:assert"
2602
- * import { compose } from "effect/Function"
2603
2860
  *
2604
- * const increment = (n: number) => n + 1;
2605
- * const square = (n: number) => n * n;
2861
+ * const increment = (n: number) => n + 1
2862
+ * const square = (n: number) => n * n
2606
2863
  *
2607
- * assert.strictEqual(compose(increment, square)(2), 9);
2864
+ * assert.strictEqual(Function.compose(increment, square)(2), 9)
2608
2865
  * ```
2609
2866
  *
2610
- * @since 1.0.0
2867
+ * @see {@link flow} for composing a left-to-right sequence of functions
2868
+ * @see {@link pipe} for applying a value through a left-to-right sequence immediately
2869
+ *
2870
+ * @category combinators
2871
+ * @since 2.0.0
2611
2872
  */
2612
2873
  const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
2874
+ /**
2875
+ * Marks an impossible branch by accepting a `never` value and returning any
2876
+ * type.
2877
+ *
2878
+ * **When to use**
2879
+ *
2880
+ * Use when you need a return value in a branch that exhaustive checks prove
2881
+ * cannot be reached.
2882
+ *
2883
+ * **Gotchas**
2884
+ *
2885
+ * Calling `absurd` throws, because a value of type `never` should be
2886
+ * impossible at runtime.
2887
+ *
2888
+ * **Example** (Handling impossible values)
2889
+ *
2890
+ * ```ts
2891
+ * import { absurd } from "effect"
2892
+ *
2893
+ * const handleNever = (value: never) => {
2894
+ * return absurd(value) // This will throw an error if called
2895
+ * }
2896
+ * ```
2897
+ *
2898
+ * @category utility types
2899
+ * @since 2.0.0
2900
+ */
2901
+ const absurd = (_) => {
2902
+ throw new Error("Called `absurd` function which should be uncallable");
2903
+ };
2613
2904
  function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
2614
2905
  switch (arguments.length) {
2615
2906
  case 1: return ab;
@@ -2639,6 +2930,36 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
2639
2930
  };
2640
2931
  }
2641
2932
  }
2933
+ /**
2934
+ * Creates a compile-time placeholder for a value of any type.
2935
+ *
2936
+ * **When to use**
2937
+ *
2938
+ * Use as a temporary typed placeholder while developing incomplete code.
2939
+ *
2940
+ * **Gotchas**
2941
+ *
2942
+ * `hole` is intended for temporary development use. If the placeholder is
2943
+ * evaluated at runtime, it throws.
2944
+ *
2945
+ * **Example** (Creating a development placeholder)
2946
+ *
2947
+ * ```ts
2948
+ * import { hole } from "effect"
2949
+ *
2950
+ * // Intentionally not called: `hole` throws if the placeholder is evaluated.
2951
+ * const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
2952
+ * id,
2953
+ * name: hole<string>()
2954
+ * })
2955
+ *
2956
+ * console.log(typeof buildUser) // "function"
2957
+ * ```
2958
+ *
2959
+ * @category utility types
2960
+ * @since 2.0.0
2961
+ */
2962
+ const hole = cast(absurd);
2642
2963
  function getOrInsertComputed(map, key, callback) {
2643
2964
  if (map.has(key)) return map.get(key);
2644
2965
  const value = callback(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "5.16.1",
3
+ "version": "5.17.0",
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",
@@ -45,12 +45,12 @@
45
45
  "string-ts": "^2.3.1",
46
46
  "ts-api-utils": "^2.5.0",
47
47
  "ts-pattern": "^5.9.0",
48
- "@eslint-react/ast": "5.16.1",
49
- "@eslint-react/eslint": "5.16.1",
50
- "@eslint-react/core": "5.16.1",
51
- "@eslint-react/jsx": "5.16.1",
52
- "@eslint-react/shared": "5.16.1",
53
- "@eslint-react/var": "5.16.1"
48
+ "@eslint-react/ast": "5.17.0",
49
+ "@eslint-react/eslint": "5.17.0",
50
+ "@eslint-react/jsx": "5.17.0",
51
+ "@eslint-react/var": "5.17.0",
52
+ "@eslint-react/shared": "5.17.0",
53
+ "@eslint-react/core": "5.17.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.17",