eslint-plugin-react-x 5.16.0 → 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 +358 -36
  2. package/package.json +9 -9
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.0";
147
+ var version = "5.17.0";
148
148
 
149
149
  //#endregion
150
150
  //#region src/utils/create-rule.ts
@@ -1348,6 +1348,7 @@ const MUTATING_METHODS = /* @__PURE__ */ new Set([
1348
1348
  * Known navigation hooks.
1349
1349
  */
1350
1350
  const NAVIGATION_HOOKS = /* @__PURE__ */ new Set([
1351
+ "useHistory",
1351
1352
  "useNavigate",
1352
1353
  "useNavigation",
1353
1354
  "useRouter"
@@ -2491,28 +2492,124 @@ function not(predicate) {
2491
2492
  return (data) => !predicate(data);
2492
2493
  }
2493
2494
  /**
2494
- * Creates a function that can be used in a data-last (aka `pipe`able) or
2495
- * data-first style.
2495
+ * Applies a `pipe` method's variadic arguments to an initial value from left
2496
+ * to right.
2496
2497
  *
2497
- * The first parameter to `dual` is either the arity of the uncurried function
2498
- * or a predicate that determines if the function is being used in a data-first
2499
- * or data-last style.
2498
+ * **When to use**
2500
2499
  *
2501
- * Using the arity is the most common use case, but there are some cases where
2502
- * you may want to use a predicate. For example, if you have a function that
2503
- * takes an optional argument, you can use a predicate to determine if the
2504
- * 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.
2505
2502
  *
2506
- * You can pass either the arity of the uncurried function or a predicate
2507
- * which determines if the function is being used in a data-first or
2508
- * data-last style.
2503
+ * **Details**
2509
2504
  *
2510
- * **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)
2511
2510
  *
2512
2511
  * ```ts
2513
- * 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(...)`.
2514
2573
  *
2515
- * 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<
2516
2613
  * (that: number) => (self: number) => number,
2517
2614
  * (self: number, that: number) => number
2518
2615
  * >(2, (self, that) => self + that)
@@ -2521,26 +2618,26 @@ function not(predicate) {
2521
2618
  * console.log(pipe(2, sum(3))) // 5
2522
2619
  * ```
2523
2620
  *
2524
- * **Example** (Using call signatures to define the overloads)
2621
+ * **Example** (Defining overloads with call signatures)
2525
2622
  *
2526
2623
  * ```ts
2527
- * import { dual, pipe } from "effect/Function"
2624
+ * import { Function, pipe } from "effect"
2528
2625
  *
2529
2626
  * const sum: {
2530
2627
  * (that: number): (self: number) => number
2531
2628
  * (self: number, that: number): number
2532
- * } = dual(2, (self: number, that: number): number => self + that)
2629
+ * } = Function.dual(2, (self: number, that: number): number => self + that)
2533
2630
  *
2534
2631
  * console.log(sum(2, 3)) // 5
2535
2632
  * console.log(pipe(2, sum(3))) // 5
2536
2633
  * ```
2537
2634
  *
2538
- * **Example** (Using a predicate to determine data-first or data-last style)
2635
+ * **Example** (Selecting data-first or data-last style with a predicate)
2539
2636
  *
2540
2637
  * ```ts
2541
- * import { dual, pipe } from "effect/Function"
2638
+ * import { Function, pipe } from "effect"
2542
2639
  *
2543
- * const sum = dual<
2640
+ * const sum = Function.dual<
2544
2641
  * (that: number) => (self: number) => number,
2545
2642
  * (self: number, that: number) => number
2546
2643
  * >(
@@ -2552,9 +2649,8 @@ function not(predicate) {
2552
2649
  * console.log(pipe(2, sum(3))) // 5
2553
2650
  * ```
2554
2651
  *
2555
- * @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.
2556
- * @param body - The function to be curried.
2557
- * @since 1.0.0
2652
+ * @category combinators
2653
+ * @since 2.0.0
2558
2654
  */
2559
2655
  const dual = function(arity, body) {
2560
2656
  if (typeof arity === "function") return function() {
@@ -2585,30 +2681,226 @@ const dual = function(arity, body) {
2585
2681
  }
2586
2682
  };
2587
2683
  /**
2588
- * 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
2589
2720
  */
2590
- 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;
2591
2847
  /**
2592
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`.
2593
2849
  * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
2594
2850
  *
2595
- * @param self - The first function to apply (or the composed function in data-last style).
2596
- * @param bc - The second function to apply.
2597
- * @returns A composed function that applies both functions in sequence.
2598
- * @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
+ *
2599
2857
  * ```ts
2858
+ * import { Function } from "effect"
2600
2859
  * import * as assert from "node:assert"
2601
- * import { compose } from "effect/Function"
2602
2860
  *
2603
- * const increment = (n: number) => n + 1;
2604
- * const square = (n: number) => n * n;
2861
+ * const increment = (n: number) => n + 1
2862
+ * const square = (n: number) => n * n
2605
2863
  *
2606
- * assert.strictEqual(compose(increment, square)(2), 9);
2864
+ * assert.strictEqual(Function.compose(increment, square)(2), 9)
2607
2865
  * ```
2608
2866
  *
2609
- * @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
2610
2872
  */
2611
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
+ };
2612
2904
  function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
2613
2905
  switch (arguments.length) {
2614
2906
  case 1: return ab;
@@ -2638,6 +2930,36 @@ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
2638
2930
  };
2639
2931
  }
2640
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);
2641
2963
  function getOrInsertComputed(map, key, callback) {
2642
2964
  if (map.has(key)) return map.get(key);
2643
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.0",
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/core": "5.16.0",
49
- "@eslint-react/ast": "5.16.0",
50
- "@eslint-react/eslint": "5.16.0",
51
- "@eslint-react/jsx": "5.16.0",
52
- "@eslint-react/shared": "5.16.0",
53
- "@eslint-react/var": "5.16.0"
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",
@@ -63,8 +63,8 @@
63
63
  "tsl": "^1.0.30",
64
64
  "tsl-dx": "^0.13.2",
65
65
  "typescript": "6.0.3",
66
- "@local/eff": "0.0.0",
67
- "@local/configs": "0.0.0"
66
+ "@local/configs": "0.0.0",
67
+ "@local/eff": "0.0.0"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "eslint": "*",