@eslint-react/shared 5.24.0 → 5.24.2

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
@@ -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
@@ -4,44 +4,6 @@ import { P, match } from "ts-pattern";
4
4
  import { z } from "zod/v4";
5
5
 
6
6
  //#region ../../.pkgs/eff/dist/index.js
7
- /**
8
- * Applies a `pipe` method's variadic arguments to an initial value from left
9
- * to right.
10
- *
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
44
- */
45
7
  const pipeArguments = (self, args) => {
46
8
  switch (args.length) {
47
9
  case 0: return self;
@@ -61,110 +23,14 @@ const pipeArguments = (self, args) => {
61
23
  }
62
24
  }
63
25
  };
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
26
  const Prototype = { pipe() {
76
27
  return pipeArguments(this, arguments);
77
28
  } };
78
- /**
79
- * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
80
- * method.
81
- *
82
- * **When to use**
83
- *
84
- * Use when you need to define a class that supports Effect-style method
85
- * chaining through `.pipe(...)`.
86
- *
87
- * @category constructors
88
- * @since 3.15.0
89
- */
90
29
  const Class = (function() {
91
30
  function PipeableBase() {}
92
31
  PipeableBase.prototype = Prototype;
93
32
  return PipeableBase;
94
33
  })();
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.
108
- *
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)
121
- *
122
- * ```ts
123
- * import { Function, pipe } from "effect"
124
- *
125
- * const sum = Function.dual<
126
- * (that: number) => (self: number) => number,
127
- * (self: number, that: number) => number
128
- * >(2, (self, that) => self + that)
129
- *
130
- * console.log(sum(2, 3)) // 5
131
- * console.log(pipe(2, sum(3))) // 5
132
- * ```
133
- *
134
- * **Example** (Defining overloads with call signatures)
135
- *
136
- * ```ts
137
- * import { Function, pipe } from "effect"
138
- *
139
- * const sum: {
140
- * (that: number): (self: number) => number
141
- * (self: number, that: number): number
142
- * } = Function.dual(2, (self: number, that: number): number => self + that)
143
- *
144
- * console.log(sum(2, 3)) // 5
145
- * console.log(pipe(2, sum(3))) // 5
146
- * ```
147
- *
148
- * **Example** (Selecting data-first or data-last style with a predicate)
149
- *
150
- * ```ts
151
- * import { Function, pipe } from "effect"
152
- *
153
- * const sum = Function.dual<
154
- * (that: number) => (self: number) => number,
155
- * (self: number, that: number) => number
156
- * >(
157
- * (args) => args.length === 2,
158
- * (self, that) => self + that
159
- * )
160
- *
161
- * console.log(sum(2, 3)) // 5
162
- * console.log(pipe(2, sum(3))) // 5
163
- * ```
164
- *
165
- * @category combinators
166
- * @since 2.0.0
167
- */
168
34
  const dual = function(arity, body) {
169
35
  if (typeof arity === "function") return function() {
170
36
  return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
@@ -193,466 +59,124 @@ const dual = function(arity, body) {
193
59
  };
194
60
  }
195
61
  };
196
- /**
197
- * Returns its input argument unchanged.
198
- *
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
214
- */
215
62
  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
63
  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
64
  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
65
  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
66
  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
67
  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
68
  const constUndefined = constant(void 0);
339
- /**
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`.
341
- * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
342
- *
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
- *
349
- * ```ts
350
- * import { Function } from "effect"
351
- * import * as assert from "node:assert"
352
- *
353
- * const increment = (n: number) => n + 1
354
- * const square = (n: number) => n * n
355
- *
356
- * assert.strictEqual(Function.compose(increment, square)(2), 9)
357
- * ```
358
- *
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
364
- */
365
69
  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
70
  const absurd = (_) => {
394
71
  throw new Error("Called `absurd` function which should be uncallable");
395
72
  };
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
73
  const hole = cast(absurd);
426
- function getOrInsertComputed(map, key, callback) {
427
- if (map.has(key)) return map.get(key);
428
- const value = callback(key);
429
- map.set(key, value);
430
- return value;
74
+ function memoize(f) {
75
+ const cache = /* @__PURE__ */ new WeakMap();
76
+ return (a) => {
77
+ const cached = cache.get(a);
78
+ if (cached !== void 0) return cached;
79
+ const result = f(a);
80
+ cache.set(a, result);
81
+ return result;
82
+ };
83
+ }
84
+ const and = dual(2, (a, b) => (data) => a(data) && b(data));
85
+ const or = dual(2, (a, b) => (data) => a(data) || b(data));
86
+ const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
87
+ const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
88
+ const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
89
+ const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
90
+ const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
91
+ function isFunction(input) {
92
+ return typeof input === "function";
93
+ }
94
+ function isObjectKeyword(input) {
95
+ return typeof input === "object" && input !== null || isFunction(input);
431
96
  }
432
- /**
433
- * Drops the longest prefix of elements from an array that satisfy the given predicate.
434
- *
435
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
436
- *
437
- * @param pred - The predicate to test each element with.
438
- * @returns A new array without the matching prefix.
439
- * @example
440
- * ```ts
441
- * import * as assert from "node:assert"
442
- * import { dropWhile, pipe } from "@local/eff"
443
- *
444
- * // data-first
445
- * assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
446
- *
447
- * // data-last
448
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
449
- * ```
450
- * @category array
451
- */
452
- const dropWhile = dual(2, (xs, pred) => {
453
- const len = xs.length;
97
+ const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
98
+ const dropWhile = dual(2, (self, predicate) => {
99
+ const input = Array.isArray(self) ? self : Array.from(self);
100
+ const len = input.length;
454
101
  let idx = 0;
455
- while (idx < len && pred(xs[idx])) idx++;
456
- return xs.slice(idx);
102
+ while (idx < len && predicate(input[idx], idx)) idx++;
103
+ return input.slice(idx);
457
104
  });
458
- /**
459
- * Takes the longest prefix of elements from an array that satisfy the given predicate.
460
- *
461
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
462
- *
463
- * @param pred - The predicate to test each element with.
464
- * @returns A new array containing only the matching prefix.
465
- * @example
466
- * ```ts
467
- * import * as assert from "node:assert"
468
- * import { pipe, takeWhile } from "@local/eff"
469
- *
470
- * // data-first
471
- * assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
472
- *
473
- * // data-last
474
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
475
- * ```
476
- * @category array
477
- */
478
- const takeWhile = dual(2, (xs, pred) => {
479
- const len = xs.length;
105
+ const takeWhile = dual(2, (self, predicate) => {
106
+ const input = Array.isArray(self) ? self : Array.from(self);
107
+ const len = input.length;
480
108
  let idx = 0;
481
- while (idx < len && pred(xs[idx])) idx++;
482
- return xs.slice(0, idx);
109
+ while (idx < len && predicate(input[idx], idx)) idx++;
110
+ return input.slice(0, idx);
483
111
  });
484
112
 
485
113
  //#endregion
486
114
  //#region src/regexp.ts
487
- /** Regular expression for matching an HTML tag name. */
488
115
  const RE_HTML_TAG = /^[a-z][^-]*$/u;
489
- /** Regular expression for matching a TypeScript file extension. */
490
116
  const RE_TS_EXT = /^[cm]?tsx?$/u;
491
- /** Regular expression for matching a JavaScript file extension. */
492
117
  const RE_JS_EXT = /^[cm]?jsx?$/u;
493
- /** Regular expression for matching a PascalCase string. */
494
118
  const RE_PASCAL_CASE = /^[A-Z][\dA-Za-z]*$/u;
495
- /** Regular expression for matching a camelCase string. */
496
119
  const RE_CAMEL_CASE = /^[a-z][\dA-Za-z]*$/u;
497
- /** Regular expression for matching a kebab-case string. */
498
120
  const RE_KEBAB_CASE = /^[a-z][\d\-a-z]*$/u;
499
- /** Regular expression for matching a snake_case string. */
500
121
  const RE_SNAKE_CASE = /^[a-z][\d_a-z]*$/u;
501
- /** Regular expression for matching a CONSTANT_CASE string. */
502
122
  const RE_CONSTANT_CASE = /^[A-Z][\d_A-Z]*$/u;
503
- /**
504
- * Regular expression for matching the `javascript:` protocol.
505
- * @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
506
- */
507
123
  const RE_JAVASCRIPT_PROTOCOL = /^[\u0000-\u001F ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\r]*s[\t\n\r]*c[\t\n\r]*r[\t\n\r]*i[\t\n\r]*p[\t\n\r]*t[\t\n\r]*:/iu;
508
- /** Regular expression for matching a valid JavaScript identifier. */
509
124
  const RE_JS_IDENTIFIER = /^[_$a-z][\w$]*$/i;
510
- /** Regular expression for matching a RegExp string. */
511
125
  const RE_REGEXP_STR = /^\/(.+)\/([A-Za-z]*)$/u;
512
- /** Regular expression for matching a `@jsx` annotation comment. */
513
126
  const RE_ANNOTATION_JSX = /@jsx\s+(\S+)/u;
514
- /** Regular expression for matching a `@jsxFrag` annotation comment. */
515
127
  const RE_ANNOTATION_JSX_FRAG = /@jsxFrag\s+(\S+)/u;
516
- /** Regular expression for matching a `@jsxRuntime` annotation comment. */
517
128
  const RE_ANNOTATION_JSX_RUNTIME = /@jsxRuntime\s+(\S+)/u;
518
- /** Regular expression for matching a `@jsxImportSource` annotation comment. */
519
129
  const RE_ANNOTATION_JSX_IMPORT_SOURCE = /@jsxImportSource\s+(\S+)/u;
520
- /** Regular expression for matching a React component name. */
521
130
  const RE_COMPONENT_NAME = /^[A-Z]/u;
522
- /** Regular expression for matching a React component name (loose). */
523
131
  const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
524
- /** Regular expression for matching a React Hook name. */
525
132
  const RE_HOOK_NAME = /^use/u;
526
- /**
527
- * Convert a string to a `RegExpLike` object.
528
- *
529
- * Normal strings (ex: `"foo"`) are converted to `/^foo$/`.
530
- * RegExp strings (ex: `"/^foo/i"`) are converted to `/^foo/i`.
531
- * @param string The string to convert.
532
- * @returns The converted `RegExpLike` object.
533
- * @see https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/utils/regexp.ts
534
- */
535
133
  function toRegExp(string) {
536
134
  if (string == null) return { test: constFalse };
537
135
  const [, pattern, flags = "u"] = RE_REGEXP_STR.exec(string) ?? [];
538
136
  if (pattern != null) return new RegExp(pattern, flags);
539
137
  return { test: (s) => s === string };
540
138
  }
541
- /**
542
- * Check if the string is a RegExp string.
543
- * @param string The string to check.
544
- * @returns `true` if the string is a RegExp string.
545
- */
546
139
  function isRegExp(string) {
547
140
  return RE_REGEXP_STR.test(string);
548
141
  }
549
142
 
550
143
  //#endregion
551
144
  //#region src/settings.ts
552
- /**
553
- * The zod schema for the ESLint React settings.
554
- * @internal
555
- */
556
145
  const ESLintReactSettingsSchema = z.object({
557
- /**
558
- * The source where React is imported from.
559
- * Allows specifying a custom import location for React.
560
- * @default "react"
561
- * @example "@pika/react"
562
- */
563
146
  importSource: z.optional(z.string()),
564
- /**
565
- * The React Compiler compilationMode that the project is using.
566
- * Used to inform the rule about how components and hooks will be picked up by the compiler.
567
- * @example "infer"
568
- */
569
147
  compilationMode: z.optional(z.enum([
570
148
  "infer",
571
149
  "annotation",
572
150
  "syntax",
573
151
  "all"
574
152
  ])),
575
- /**
576
- * The prop name used for polymorphic components.
577
- * Used to determine the component's type.
578
- * @example "as"
579
- */
580
153
  polymorphicPropName: z.optional(z.string()),
581
- /**
582
- * React version to use.
583
- * "detect" means auto-detect React version from project dependencies.
584
- * @example "18.3.1"
585
- * @default "detect"
586
- */
587
154
  version: z.optional(z.string()),
588
- /**
589
- * Regex pattern matching custom hooks that should be treated as ref hooks.
590
- * @example "useMyRef|useCustomRef"
591
- */
592
155
  additionalRefHooks: z.optional(z.string()),
593
- /**
594
- * Regex pattern matching custom hooks that should be treated as state hooks.
595
- * @example "useMyState|useCustomState"
596
- */
597
156
  additionalStateHooks: z.optional(z.string()),
598
- /**
599
- * Regex pattern matching custom hooks that should be treated as effect hooks.
600
- * @example "useMyEffect|useCustomEffect"
601
- */
602
157
  additionalEffectHooks: z.optional(z.string())
603
158
  });
604
- /**
605
- * The zod schema for the ESLint settings.
606
- * @internal
607
- */
608
159
  const ESLintSettingsSchema = z.optional(z.object({ "react-x": z.optional(z.unknown()) }));
609
- /** The default ESLint React settings. */
610
160
  const DEFAULT_ESLINT_REACT_SETTINGS = {
611
161
  version: "detect",
612
162
  importSource: "react",
613
163
  polymorphicPropName: "as"
614
164
  };
615
- /** The default ESLint settings. */
616
165
  const DEFAULT_ESLINT_SETTINGS = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
617
- /**
618
- * Check if the value is valid ESLint settings.
619
- * @param settings The value to check.
620
- * @returns `true` if the value is valid ESLint settings.
621
- */
622
166
  function isESLintSettings(settings) {
623
167
  return ESLintSettingsSchema.safeParse(settings).success;
624
168
  }
625
- /**
626
- * Check if the value is valid ESLint React settings.
627
- * @param settings The value to check.
628
- * @returns `true` if the value is valid ESLint React settings.
629
- */
630
169
  function isESLintReactSettings(settings) {
631
170
  return ESLintReactSettingsSchema.safeParse(settings).success;
632
171
  }
633
- /**
634
- * Decode the ESLint settings, falling back to the defaults when invalid.
635
- * @param settings The value to decode.
636
- * @returns The decoded ESLint settings.
637
- */
638
172
  const decodeESLintSettings = (settings) => {
639
173
  if (isESLintSettings(settings)) return settings;
640
174
  return DEFAULT_ESLINT_SETTINGS;
641
175
  };
642
- /**
643
- * Decode the ESLint React settings, falling back to the defaults when invalid.
644
- * @param settings The value to decode.
645
- * @returns The decoded ESLint React settings.
646
- */
647
176
  const decodeSettings = (settings) => {
648
177
  if (isESLintReactSettings(settings)) return settings;
649
178
  return DEFAULT_ESLINT_REACT_SETTINGS;
650
179
  };
651
- /**
652
- * Normalize the ESLint React settings to the form used by rules.
653
- * @param settings The ESLint React settings to normalize.
654
- * @returns The normalized ESLint React settings.
655
- */
656
180
  const normalizeSettings = ({ importSource = "react", compilationMode, polymorphicPropName = "as", version, additionalRefHooks, additionalStateHooks, additionalEffectHooks, ...rest }) => {
657
181
  return {
658
182
  ...rest,
@@ -665,12 +189,6 @@ const normalizeSettings = ({ importSource = "react", compilationMode, polymorphi
665
189
  additionalEffectHooks: toRegExp(additionalEffectHooks)
666
190
  };
667
191
  };
668
- const cache = /* @__PURE__ */ new Map();
669
- /**
670
- * Get the React version from the project's dependencies.
671
- * @param fallback The fallback version to return if React is not found.
672
- * @returns The detected React version or the fallback version.
673
- */
674
192
  function getReactVersion(fallback) {
675
193
  try {
676
194
  return match(module.createRequire(process.cwd() + path.sep)("react")).with({ version: P.select(P.string) }, identity).otherwise(() => fallback);
@@ -678,15 +196,11 @@ function getReactVersion(fallback) {
678
196
  return fallback;
679
197
  }
680
198
  }
681
- /**
682
- * Get the normalized ESLint React settings from the rule context.
683
- * @param context The rule context.
684
- * @returns The normalized ESLint React settings.
685
- */
199
+ const getNormalizedSettings = memoize((settings) => normalizeSettings(decodeSettings(settings)));
686
200
  function getSettingsFromContext(context) {
687
201
  const settings = context.settings["react-x"];
688
- return getOrInsertComputed(cache, settings, () => normalizeSettings(decodeSettings(settings)));
202
+ return getNormalizedSettings(isObjectKeyword(settings) ? settings : DEFAULT_ESLINT_REACT_SETTINGS);
689
203
  }
690
204
 
691
205
  //#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 };
206
+ 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.0",
3
+ "version": "5.24.2",
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.0",
32
+ "@eslint-react/eslint": "5.24.2",
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.11.0",
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",