@eslint-react/shared 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.
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import { z } from "zod/v4";
2
2
  import { RuleContext } from "@eslint-react/eslint";
3
3
  //#region src/regexp.d.ts
4
4
  /**
5
- * Regular expressions for matching a HTML tag name
5
+ * Regular expressions for matching a HTML tag name.
6
6
  */
7
7
  declare const RE_HTML_TAG: RegExp;
8
8
  /**
@@ -86,9 +86,9 @@ type RegExpLike = {
86
86
  */
87
87
  declare function toRegExp(string: string | null | undefined): RegExpLike;
88
88
  /**
89
- * Check whether given string is regexp string
90
- * @param string The string to check
91
- * @returns boolean
89
+ * Check whether given string is regexp string.
90
+ * @param string The string to check.
91
+ * @returns boolean.
92
92
  */
93
93
  declare function isRegExp(string: string): boolean;
94
94
  //#endregion
package/dist/index.js CHANGED
@@ -5,37 +5,124 @@ import { z } from "zod/v4";
5
5
 
6
6
  //#region ../../.pkgs/eff/dist/index.js
7
7
  /**
8
- * Returns its argument.
8
+ * Applies a `pipe` method's variadic arguments to an initial value from left
9
+ * to right.
9
10
  *
10
- * @param x - The value to return.
11
- * @returns The input value unchanged.
11
+ * **When to use**
12
+ *
13
+ * Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
14
+ * object.
15
+ *
16
+ * **Details**
17
+ *
18
+ * This helper is intended for implementing `Pipeable.pipe` methods that
19
+ * receive JavaScript's `arguments` object. With no functions it returns the
20
+ * original value; otherwise it feeds each result into the next function.
21
+ *
22
+ * **Example** (Implementing a pipe method)
23
+ *
24
+ * ```ts
25
+ * import { Pipeable } from "effect"
26
+ *
27
+ * class NumberBox {
28
+ * constructor(readonly value: number) {}
29
+ *
30
+ * pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
31
+ * return Pipeable.pipeArguments(this.value, arguments) as number
32
+ * }
33
+ * }
34
+ *
35
+ * const result = new NumberBox(5).pipe(
36
+ * (n) => n + 2,
37
+ * (n) => n * 3
38
+ * )
39
+ * console.log(result) // 21
40
+ * ```
41
+ *
42
+ * @category combinators
43
+ * @since 2.0.0
12
44
  */
13
- function identity(x) {
14
- return x;
15
- }
45
+ const pipeArguments = (self, args) => {
46
+ switch (args.length) {
47
+ case 0: return self;
48
+ case 1: return args[0](self);
49
+ case 2: return args[1](args[0](self));
50
+ case 3: return args[2](args[1](args[0](self)));
51
+ case 4: return args[3](args[2](args[1](args[0](self))));
52
+ case 5: return args[4](args[3](args[2](args[1](args[0](self)))));
53
+ case 6: return args[5](args[4](args[3](args[2](args[1](args[0](self))))));
54
+ case 7: return args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))));
55
+ case 8: return args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self))))))));
56
+ case 9: return args[8](args[7](args[6](args[5](args[4](args[3](args[2](args[1](args[0](self)))))))));
57
+ default: {
58
+ let ret = self;
59
+ for (let i = 0, len = args.length; i < len; i++) ret = args[i](ret);
60
+ return ret;
61
+ }
62
+ }
63
+ };
64
+ /**
65
+ * Reusable prototype that implements `Pipeable.pipe`.
66
+ *
67
+ * **When to use**
68
+ *
69
+ * Use when classes or object prototypes can reuse this value when they need the
70
+ * standard pipe implementation backed by `pipeArguments`.
71
+ *
72
+ * @category prototypes
73
+ * @since 3.15.0
74
+ */
75
+ const Prototype = { pipe() {
76
+ return pipeArguments(this, arguments);
77
+ } };
16
78
  /**
17
- * Creates a function that can be used in a data-last (aka `pipe`able) or
18
- * data-first style.
79
+ * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
80
+ * method.
19
81
  *
20
- * The first parameter to `dual` is either the arity of the uncurried function
21
- * or a predicate that determines if the function is being used in a data-first
22
- * or data-last style.
82
+ * **When to use**
23
83
  *
24
- * Using the arity is the most common use case, but there are some cases where
25
- * you may want to use a predicate. For example, if you have a function that
26
- * takes an optional argument, you can use a predicate to determine if the
27
- * function is being used in a data-first or data-last style.
84
+ * Use when you need to define a class that supports Effect-style method
85
+ * chaining through `.pipe(...)`.
28
86
  *
29
- * You can pass either the arity of the uncurried function or a predicate
30
- * which determines if the function is being used in a data-first or
31
- * data-last style.
87
+ * @category constructors
88
+ * @since 3.15.0
89
+ */
90
+ const Class = (function() {
91
+ function PipeableBase() {}
92
+ PipeableBase.prototype = Prototype;
93
+ return PipeableBase;
94
+ })();
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
+ * Creates a function that can be called in data-first style or data-last
107
+ * (`pipe`-friendly) style.
32
108
  *
33
- * **Example** (Using arity to determine data-first or data-last style)
109
+ * **When to use**
110
+ *
111
+ * Use to expose one implementation through both direct and `pipe`-friendly
112
+ * call styles.
113
+ *
114
+ * **Details**
115
+ *
116
+ * Pass either the arity of the uncurried function or a predicate that decides
117
+ * whether the current call is data-first. Arity is the common case. Use a
118
+ * predicate when optional arguments make arity ambiguous.
119
+ *
120
+ * **Example** (Selecting data-first or data-last style by arity)
34
121
  *
35
122
  * ```ts
36
- * import { dual, pipe } from "effect/Function"
123
+ * import { Function, pipe } from "effect"
37
124
  *
38
- * const sum = dual<
125
+ * const sum = Function.dual<
39
126
  * (that: number) => (self: number) => number,
40
127
  * (self: number, that: number) => number
41
128
  * >(2, (self, that) => self + that)
@@ -44,26 +131,26 @@ function identity(x) {
44
131
  * console.log(pipe(2, sum(3))) // 5
45
132
  * ```
46
133
  *
47
- * **Example** (Using call signatures to define the overloads)
134
+ * **Example** (Defining overloads with call signatures)
48
135
  *
49
136
  * ```ts
50
- * import { dual, pipe } from "effect/Function"
137
+ * import { Function, pipe } from "effect"
51
138
  *
52
139
  * const sum: {
53
140
  * (that: number): (self: number) => number
54
141
  * (self: number, that: number): number
55
- * } = dual(2, (self: number, that: number): number => self + that)
142
+ * } = Function.dual(2, (self: number, that: number): number => self + that)
56
143
  *
57
144
  * console.log(sum(2, 3)) // 5
58
145
  * console.log(pipe(2, sum(3))) // 5
59
146
  * ```
60
147
  *
61
- * **Example** (Using a predicate to determine data-first or data-last style)
148
+ * **Example** (Selecting data-first or data-last style with a predicate)
62
149
  *
63
150
  * ```ts
64
- * import { dual, pipe } from "effect/Function"
151
+ * import { Function, pipe } from "effect"
65
152
  *
66
- * const sum = dual<
153
+ * const sum = Function.dual<
67
154
  * (that: number) => (self: number) => number,
68
155
  * (self: number, that: number) => number
69
156
  * >(
@@ -75,9 +162,8 @@ function identity(x) {
75
162
  * console.log(pipe(2, sum(3))) // 5
76
163
  * ```
77
164
  *
78
- * @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.
79
- * @param body - The function to be curried.
80
- * @since 1.0.0
165
+ * @category combinators
166
+ * @since 2.0.0
81
167
  */
82
168
  const dual = function(arity, body) {
83
169
  if (typeof arity === "function") return function() {
@@ -108,34 +194,235 @@ const dual = function(arity, body) {
108
194
  }
109
195
  };
110
196
  /**
111
- * Do nothing and return `false`.
197
+ * Returns its input argument unchanged.
112
198
  *
113
- * @returns false
199
+ * **When to use**
200
+ *
201
+ * Use to return a value unchanged where a function is required.
202
+ *
203
+ * **Example** (Returning the same value)
204
+ *
205
+ * ```ts
206
+ * import { identity } from "effect"
207
+ * import * as assert from "node:assert"
208
+ *
209
+ * assert.deepStrictEqual(identity(5), 5)
210
+ * ```
211
+ *
212
+ * @category combinators
213
+ * @since 2.0.0
114
214
  */
115
- function constFalse() {
116
- return false;
117
- }
215
+ const identity = (a) => a;
216
+ /**
217
+ * Returns the input value with a different static type.
218
+ *
219
+ * **When to use**
220
+ *
221
+ * Use when you need an explicit type-level cast and accept that the value is
222
+ * returned unchanged at runtime.
223
+ *
224
+ * **Gotchas**
225
+ *
226
+ * This is a type-level cast only; it performs no runtime validation or
227
+ * conversion.
228
+ *
229
+ * @see {@link satisfies} for checking assignability without changing the resulting type
230
+ *
231
+ * @category utility types
232
+ * @since 4.0.0
233
+ */
234
+ const cast = identity;
235
+ /**
236
+ * Creates a zero-argument function that always returns the provided value.
237
+ *
238
+ * **When to use**
239
+ *
240
+ * Use when you need a thunk or callback that returns the same value on every
241
+ * invocation.
242
+ *
243
+ * **Example** (Creating a constant thunk)
244
+ *
245
+ * ```ts
246
+ * import { Function } from "effect"
247
+ * import * as assert from "node:assert"
248
+ *
249
+ * const constNull = Function.constant(null)
250
+ *
251
+ * assert.deepStrictEqual(constNull(), null)
252
+ * assert.deepStrictEqual(constNull(), null)
253
+ * ```
254
+ *
255
+ * @category constructors
256
+ * @since 2.0.0
257
+ */
258
+ const constant = (value) => () => value;
259
+ /**
260
+ * Returns `true` when called.
261
+ *
262
+ * **When to use**
263
+ *
264
+ * Use when you need a thunk that returns `true` on every invocation.
265
+ *
266
+ * **Example** (Returning true from a thunk)
267
+ *
268
+ * ```ts
269
+ * import { Function } from "effect"
270
+ * import * as assert from "node:assert"
271
+ *
272
+ * assert.deepStrictEqual(Function.constTrue(), true)
273
+ * ```
274
+ *
275
+ * @category constants
276
+ * @since 2.0.0
277
+ */
278
+ const constTrue = constant(true);
279
+ /**
280
+ * Returns `false` when called.
281
+ *
282
+ * **When to use**
283
+ *
284
+ * Use when you need a thunk that returns `false` on every invocation.
285
+ *
286
+ * **Example** (Returning false from a thunk)
287
+ *
288
+ * ```ts
289
+ * import { Function } from "effect"
290
+ * import * as assert from "node:assert"
291
+ *
292
+ * assert.deepStrictEqual(Function.constFalse(), false)
293
+ * ```
294
+ *
295
+ * @category constants
296
+ * @since 2.0.0
297
+ */
298
+ const constFalse = constant(false);
299
+ /**
300
+ * Returns `null` when called.
301
+ *
302
+ * **When to use**
303
+ *
304
+ * Use when you need a thunk that returns `null` on every invocation.
305
+ *
306
+ * **Example** (Returning null from a thunk)
307
+ *
308
+ * ```ts
309
+ * import { Function } from "effect"
310
+ * import * as assert from "node:assert"
311
+ *
312
+ * assert.deepStrictEqual(Function.constNull(), null)
313
+ * ```
314
+ *
315
+ * @category constants
316
+ * @since 2.0.0
317
+ */
318
+ const constNull = constant(null);
319
+ /**
320
+ * Returns `undefined` when called.
321
+ *
322
+ * **When to use**
323
+ *
324
+ * Use when you need a thunk that returns `undefined` on every invocation.
325
+ *
326
+ * **Example** (Returning undefined from a thunk)
327
+ *
328
+ * ```ts
329
+ * import { Function } from "effect"
330
+ * import * as assert from "node:assert"
331
+ *
332
+ * assert.deepStrictEqual(Function.constUndefined(), undefined)
333
+ * ```
334
+ *
335
+ * @category constants
336
+ * @since 2.0.0
337
+ */
338
+ const constUndefined = constant(void 0);
118
339
  /**
119
340
  * 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`.
120
341
  * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
121
342
  *
122
- * @param self - The first function to apply (or the composed function in data-last style).
123
- * @param bc - The second function to apply.
124
- * @returns A composed function that applies both functions in sequence.
125
- * @example
343
+ * **When to use**
344
+ *
345
+ * Use to compose exactly two unary functions into a reusable unary function.
346
+ *
347
+ * **Example** (Composing two functions)
348
+ *
126
349
  * ```ts
350
+ * import { Function } from "effect"
127
351
  * import * as assert from "node:assert"
128
- * import { compose } from "effect/Function"
129
352
  *
130
- * const increment = (n: number) => n + 1;
131
- * const square = (n: number) => n * n;
353
+ * const increment = (n: number) => n + 1
354
+ * const square = (n: number) => n * n
132
355
  *
133
- * assert.strictEqual(compose(increment, square)(2), 9);
356
+ * assert.strictEqual(Function.compose(increment, square)(2), 9)
134
357
  * ```
135
358
  *
136
- * @since 1.0.0
359
+ * @see {@link flow} for composing a left-to-right sequence of functions
360
+ * @see {@link pipe} for applying a value through a left-to-right sequence immediately
361
+ *
362
+ * @category combinators
363
+ * @since 2.0.0
137
364
  */
138
365
  const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
366
+ /**
367
+ * Marks an impossible branch by accepting a `never` value and returning any
368
+ * type.
369
+ *
370
+ * **When to use**
371
+ *
372
+ * Use when you need a return value in a branch that exhaustive checks prove
373
+ * cannot be reached.
374
+ *
375
+ * **Gotchas**
376
+ *
377
+ * Calling `absurd` throws, because a value of type `never` should be
378
+ * impossible at runtime.
379
+ *
380
+ * **Example** (Handling impossible values)
381
+ *
382
+ * ```ts
383
+ * import { absurd } from "effect"
384
+ *
385
+ * const handleNever = (value: never) => {
386
+ * return absurd(value) // This will throw an error if called
387
+ * }
388
+ * ```
389
+ *
390
+ * @category utility types
391
+ * @since 2.0.0
392
+ */
393
+ const absurd = (_) => {
394
+ throw new Error("Called `absurd` function which should be uncallable");
395
+ };
396
+ /**
397
+ * Creates a compile-time placeholder for a value of any type.
398
+ *
399
+ * **When to use**
400
+ *
401
+ * Use as a temporary typed placeholder while developing incomplete code.
402
+ *
403
+ * **Gotchas**
404
+ *
405
+ * `hole` is intended for temporary development use. If the placeholder is
406
+ * evaluated at runtime, it throws.
407
+ *
408
+ * **Example** (Creating a development placeholder)
409
+ *
410
+ * ```ts
411
+ * import { hole } from "effect"
412
+ *
413
+ * // Intentionally not called: `hole` throws if the placeholder is evaluated.
414
+ * const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
415
+ * id,
416
+ * name: hole<string>()
417
+ * })
418
+ *
419
+ * console.log(typeof buildUser) // "function"
420
+ * ```
421
+ *
422
+ * @category utility types
423
+ * @since 2.0.0
424
+ */
425
+ const hole = cast(absurd);
139
426
  function getOrInsertComputed(map, key, callback) {
140
427
  if (map.has(key)) return map.get(key);
141
428
  const value = callback(key);
@@ -146,7 +433,7 @@ function getOrInsertComputed(map, key, callback) {
146
433
  //#endregion
147
434
  //#region src/regexp.ts
148
435
  /**
149
- * Regular expressions for matching a HTML tag name
436
+ * Regular expressions for matching a HTML tag name.
150
437
  */
151
438
  const RE_HTML_TAG = /^[a-z][^-]*$/u;
152
439
  /**
@@ -229,9 +516,9 @@ function toRegExp(string) {
229
516
  return { test: (s) => s === string };
230
517
  }
231
518
  /**
232
- * Check whether given string is regexp string
233
- * @param string The string to check
234
- * @returns boolean
519
+ * Check whether given string is regexp string.
520
+ * @param string The string to check.
521
+ * @returns boolean.
235
522
  */
236
523
  function isRegExp(string) {
237
524
  return RE_REGEXP_STR.test(string);
@@ -245,14 +532,14 @@ function isRegExp(string) {
245
532
  const ESLintReactSettingsSchema = z.object({
246
533
  /**
247
534
  * The source where React is imported from
248
- * Allows specifying a custom import location for React
535
+ * Allows specifying a custom import location for React.
249
536
  * @default "react"
250
537
  * @example "@pika/react"
251
538
  */
252
539
  importSource: z.optional(z.string()),
253
540
  /**
254
541
  * The React Compiler compilationMode that the project is using
255
- * Used to inform the rule about how components and hooks will be picked up by the compiler
542
+ * Used to inform the rule about how components and hooks will be picked up by the compiler.
256
543
  * @example "infer"
257
544
  */
258
545
  compilationMode: z.optional(z.enum([
@@ -263,24 +550,24 @@ const ESLintReactSettingsSchema = z.object({
263
550
  ])),
264
551
  /**
265
552
  * The prop name used for polymorphic components
266
- * Used to determine the component's type
553
+ * Used to determine the component's type.
267
554
  * @example "as"
268
555
  */
269
556
  polymorphicPropName: z.optional(z.string()),
270
557
  /**
271
558
  * React version to use
272
- * "detect" means auto-detect React version from project dependencies
559
+ * "detect" means auto-detect React version from project dependencies.
273
560
  * @example "18.3.1"
274
561
  * @default "detect"
275
562
  */
276
563
  version: z.optional(z.string()),
277
564
  /**
278
- * Regex pattern matching custom hooks that should be treated as state hooks
565
+ * Regex pattern matching custom hooks that should be treated as state hooks.
279
566
  * @example "useMyState|useCustomState"
280
567
  */
281
568
  additionalStateHooks: z.optional(z.string()),
282
569
  /**
283
- * Regex pattern matching custom hooks that should be treated as effect hooks
570
+ * Regex pattern matching custom hooks that should be treated as effect hooks.
284
571
  * @example "useMyEffect|useCustomEffect"
285
572
  */
286
573
  additionalEffectHooks: z.optional(z.string())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "5.16.1",
3
+ "version": "5.17.0",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -32,7 +32,7 @@
32
32
  "@typescript-eslint/utils": "^8.64.0",
33
33
  "ts-pattern": "^5.9.0",
34
34
  "zod": "^3.25.0 || ^4.0.0",
35
- "@eslint-react/eslint": "5.16.1"
35
+ "@eslint-react/eslint": "5.17.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@tsconfig/node24": "^24.0.4",