@eslint-react/jsx 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.
Files changed (2) hide show
  1. package/dist/index.js +24 -634
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -5,47 +5,6 @@ import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
5
5
  import { P, match } from "ts-pattern";
6
6
 
7
7
  //#region ../../.pkgs/eff/dist/index.js
8
- function or(a, b) {
9
- return (data) => a(data) || b(data);
10
- }
11
- /**
12
- * Applies a `pipe` method's variadic arguments to an initial value from left
13
- * to right.
14
- *
15
- * **When to use**
16
- *
17
- * Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
18
- * object.
19
- *
20
- * **Details**
21
- *
22
- * This helper is intended for implementing `Pipeable.pipe` methods that
23
- * receive JavaScript's `arguments` object. With no functions it returns the
24
- * original value; otherwise it feeds each result into the next function.
25
- *
26
- * **Example** (Implementing a pipe method)
27
- *
28
- * ```ts
29
- * import { Pipeable } from "effect"
30
- *
31
- * class NumberBox {
32
- * constructor(readonly value: number) {}
33
- *
34
- * pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
35
- * return Pipeable.pipeArguments(this.value, arguments) as number
36
- * }
37
- * }
38
- *
39
- * const result = new NumberBox(5).pipe(
40
- * (n) => n + 2,
41
- * (n) => n * 3
42
- * )
43
- * console.log(result) // 21
44
- * ```
45
- *
46
- * @category combinators
47
- * @since 2.0.0
48
- */
49
8
  const pipeArguments = (self, args) => {
50
9
  switch (args.length) {
51
10
  case 0: return self;
@@ -65,110 +24,14 @@ const pipeArguments = (self, args) => {
65
24
  }
66
25
  }
67
26
  };
68
- /**
69
- * Reusable prototype that implements `Pipeable.pipe`.
70
- *
71
- * **When to use**
72
- *
73
- * Use when classes or object prototypes can reuse this value when they need the
74
- * standard pipe implementation backed by `pipeArguments`.
75
- *
76
- * @category prototypes
77
- * @since 3.15.0
78
- */
79
27
  const Prototype = { pipe() {
80
28
  return pipeArguments(this, arguments);
81
29
  } };
82
- /**
83
- * Provides a base constructor whose instances implement the standard `Pipeable.pipe`
84
- * method.
85
- *
86
- * **When to use**
87
- *
88
- * Use when you need to define a class that supports Effect-style method
89
- * chaining through `.pipe(...)`.
90
- *
91
- * @category constructors
92
- * @since 3.15.0
93
- */
94
30
  const Class = (function() {
95
31
  function PipeableBase() {}
96
32
  PipeableBase.prototype = Prototype;
97
33
  return PipeableBase;
98
34
  })();
99
- /**
100
- * Provides small helpers for defining and reusing TypeScript functions.
101
- *
102
- * The main helpers are `pipe` and `flow` for left-to-right composition and
103
- * `dual` for APIs that support both direct and pipe-friendly call styles. The
104
- * module also contains small identity, constant, tuple, type-level, and
105
- * memoization helpers used across the library.
106
- *
107
- * @since 2.0.0
108
- */
109
- /**
110
- * Creates a function that can be called in data-first style or data-last
111
- * (`pipe`-friendly) style.
112
- *
113
- * **When to use**
114
- *
115
- * Use to expose one implementation through both direct and `pipe`-friendly
116
- * call styles.
117
- *
118
- * **Details**
119
- *
120
- * Pass either the arity of the uncurried function or a predicate that decides
121
- * whether the current call is data-first. Arity is the common case. Use a
122
- * predicate when optional arguments make arity ambiguous.
123
- *
124
- * **Example** (Selecting data-first or data-last style by arity)
125
- *
126
- * ```ts
127
- * import { Function, pipe } from "effect"
128
- *
129
- * const sum = Function.dual<
130
- * (that: number) => (self: number) => number,
131
- * (self: number, that: number) => number
132
- * >(2, (self, that) => self + that)
133
- *
134
- * console.log(sum(2, 3)) // 5
135
- * console.log(pipe(2, sum(3))) // 5
136
- * ```
137
- *
138
- * **Example** (Defining overloads with call signatures)
139
- *
140
- * ```ts
141
- * import { Function, pipe } from "effect"
142
- *
143
- * const sum: {
144
- * (that: number): (self: number) => number
145
- * (self: number, that: number): number
146
- * } = Function.dual(2, (self: number, that: number): number => self + that)
147
- *
148
- * console.log(sum(2, 3)) // 5
149
- * console.log(pipe(2, sum(3))) // 5
150
- * ```
151
- *
152
- * **Example** (Selecting data-first or data-last style with a predicate)
153
- *
154
- * ```ts
155
- * import { Function, pipe } from "effect"
156
- *
157
- * const sum = Function.dual<
158
- * (that: number) => (self: number) => number,
159
- * (self: number, that: number) => number
160
- * >(
161
- * (args) => args.length === 2,
162
- * (self, that) => self + that
163
- * )
164
- *
165
- * console.log(sum(2, 3)) // 5
166
- * console.log(pipe(2, sum(3))) // 5
167
- * ```
168
- *
169
- * @category combinators
170
- * @since 2.0.0
171
- */
172
35
  const dual = function(arity, body) {
173
36
  if (typeof arity === "function") return function() {
174
37
  return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
@@ -197,375 +60,71 @@ const dual = function(arity, body) {
197
60
  };
198
61
  }
199
62
  };
200
- /**
201
- * Returns its input argument unchanged.
202
- *
203
- * **When to use**
204
- *
205
- * Use to return a value unchanged where a function is required.
206
- *
207
- * **Example** (Returning the same value)
208
- *
209
- * ```ts
210
- * import { identity } from "effect"
211
- * import * as assert from "node:assert"
212
- *
213
- * assert.deepStrictEqual(identity(5), 5)
214
- * ```
215
- *
216
- * @category combinators
217
- * @since 2.0.0
218
- */
219
63
  const identity = (a) => a;
220
- /**
221
- * Returns the input value with a different static type.
222
- *
223
- * **When to use**
224
- *
225
- * Use when you need an explicit type-level cast and accept that the value is
226
- * returned unchanged at runtime.
227
- *
228
- * **Gotchas**
229
- *
230
- * This is a type-level cast only; it performs no runtime validation or
231
- * conversion.
232
- *
233
- * @see {@link satisfies} for checking assignability without changing the resulting type
234
- *
235
- * @category utility types
236
- * @since 4.0.0
237
- */
238
64
  const cast = identity;
239
- /**
240
- * Creates a zero-argument function that always returns the provided value.
241
- *
242
- * **When to use**
243
- *
244
- * Use when you need a thunk or callback that returns the same value on every
245
- * invocation.
246
- *
247
- * **Example** (Creating a constant thunk)
248
- *
249
- * ```ts
250
- * import { Function } from "effect"
251
- * import * as assert from "node:assert"
252
- *
253
- * const constNull = Function.constant(null)
254
- *
255
- * assert.deepStrictEqual(constNull(), null)
256
- * assert.deepStrictEqual(constNull(), null)
257
- * ```
258
- *
259
- * @category constructors
260
- * @since 2.0.0
261
- */
262
65
  const constant = (value) => () => value;
263
- /**
264
- * Returns `true` when called.
265
- *
266
- * **When to use**
267
- *
268
- * Use when you need a thunk that returns `true` on every invocation.
269
- *
270
- * **Example** (Returning true from a thunk)
271
- *
272
- * ```ts
273
- * import { Function } from "effect"
274
- * import * as assert from "node:assert"
275
- *
276
- * assert.deepStrictEqual(Function.constTrue(), true)
277
- * ```
278
- *
279
- * @category constants
280
- * @since 2.0.0
281
- */
282
66
  const constTrue = constant(true);
283
- /**
284
- * Returns `false` when called.
285
- *
286
- * **When to use**
287
- *
288
- * Use when you need a thunk that returns `false` on every invocation.
289
- *
290
- * **Example** (Returning false from a thunk)
291
- *
292
- * ```ts
293
- * import { Function } from "effect"
294
- * import * as assert from "node:assert"
295
- *
296
- * assert.deepStrictEqual(Function.constFalse(), false)
297
- * ```
298
- *
299
- * @category constants
300
- * @since 2.0.0
301
- */
302
67
  const constFalse = constant(false);
303
- /**
304
- * Returns `null` when called.
305
- *
306
- * **When to use**
307
- *
308
- * Use when you need a thunk that returns `null` on every invocation.
309
- *
310
- * **Example** (Returning null from a thunk)
311
- *
312
- * ```ts
313
- * import { Function } from "effect"
314
- * import * as assert from "node:assert"
315
- *
316
- * assert.deepStrictEqual(Function.constNull(), null)
317
- * ```
318
- *
319
- * @category constants
320
- * @since 2.0.0
321
- */
322
68
  const constNull = constant(null);
323
- /**
324
- * Returns `undefined` when called.
325
- *
326
- * **When to use**
327
- *
328
- * Use when you need a thunk that returns `undefined` on every invocation.
329
- *
330
- * **Example** (Returning undefined from a thunk)
331
- *
332
- * ```ts
333
- * import { Function } from "effect"
334
- * import * as assert from "node:assert"
335
- *
336
- * assert.deepStrictEqual(Function.constUndefined(), undefined)
337
- * ```
338
- *
339
- * @category constants
340
- * @since 2.0.0
341
- */
342
69
  const constUndefined = constant(void 0);
343
- /**
344
- * 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`.
345
- * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
346
- *
347
- * **When to use**
348
- *
349
- * Use to compose exactly two unary functions into a reusable unary function.
350
- *
351
- * **Example** (Composing two functions)
352
- *
353
- * ```ts
354
- * import { Function } from "effect"
355
- * import * as assert from "node:assert"
356
- *
357
- * const increment = (n: number) => n + 1
358
- * const square = (n: number) => n * n
359
- *
360
- * assert.strictEqual(Function.compose(increment, square)(2), 9)
361
- * ```
362
- *
363
- * @see {@link flow} for composing a left-to-right sequence of functions
364
- * @see {@link pipe} for applying a value through a left-to-right sequence immediately
365
- *
366
- * @category combinators
367
- * @since 2.0.0
368
- */
369
70
  const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
370
- /**
371
- * Marks an impossible branch by accepting a `never` value and returning any
372
- * type.
373
- *
374
- * **When to use**
375
- *
376
- * Use when you need a return value in a branch that exhaustive checks prove
377
- * cannot be reached.
378
- *
379
- * **Gotchas**
380
- *
381
- * Calling `absurd` throws, because a value of type `never` should be
382
- * impossible at runtime.
383
- *
384
- * **Example** (Handling impossible values)
385
- *
386
- * ```ts
387
- * import { absurd } from "effect"
388
- *
389
- * const handleNever = (value: never) => {
390
- * return absurd(value) // This will throw an error if called
391
- * }
392
- * ```
393
- *
394
- * @category utility types
395
- * @since 2.0.0
396
- */
397
71
  const absurd = (_) => {
398
72
  throw new Error("Called `absurd` function which should be uncallable");
399
73
  };
400
- /**
401
- * Creates a compile-time placeholder for a value of any type.
402
- *
403
- * **When to use**
404
- *
405
- * Use as a temporary typed placeholder while developing incomplete code.
406
- *
407
- * **Gotchas**
408
- *
409
- * `hole` is intended for temporary development use. If the placeholder is
410
- * evaluated at runtime, it throws.
411
- *
412
- * **Example** (Creating a development placeholder)
413
- *
414
- * ```ts
415
- * import { hole } from "effect"
416
- *
417
- * // Intentionally not called: `hole` throws if the placeholder is evaluated.
418
- * const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
419
- * id,
420
- * name: hole<string>()
421
- * })
422
- *
423
- * console.log(typeof buildUser) // "function"
424
- * ```
425
- *
426
- * @category utility types
427
- * @since 2.0.0
428
- */
429
74
  const hole = cast(absurd);
430
- /**
431
- * Drops the longest prefix of elements from an array that satisfy the given predicate.
432
- *
433
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
434
- *
435
- * @param pred - The predicate to test each element with.
436
- * @returns A new array without the matching prefix.
437
- * @example
438
- * ```ts
439
- * import * as assert from "node:assert"
440
- * import { dropWhile, pipe } from "@local/eff"
441
- *
442
- * // data-first
443
- * assert.deepStrictEqual(dropWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [3, 2, 1])
444
- *
445
- * // data-last
446
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], dropWhile((n: number) => n < 3)), [3, 2, 1])
447
- * ```
448
- * @category array
449
- */
450
- const dropWhile = dual(2, (xs, pred) => {
451
- const len = xs.length;
75
+ const and = dual(2, (a, b) => (data) => a(data) && b(data));
76
+ const or = dual(2, (a, b) => (data) => a(data) || b(data));
77
+ const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
78
+ const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
79
+ const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
80
+ const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
81
+ const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
82
+ function isFunction(input) {
83
+ return typeof input === "function";
84
+ }
85
+ function isObjectKeyword(input) {
86
+ return typeof input === "object" && input !== null || isFunction(input);
87
+ }
88
+ const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
89
+ const dropWhile = dual(2, (self, predicate) => {
90
+ const input = Array.isArray(self) ? self : Array.from(self);
91
+ const len = input.length;
452
92
  let idx = 0;
453
- while (idx < len && pred(xs[idx])) idx++;
454
- return xs.slice(idx);
93
+ while (idx < len && predicate(input[idx], idx)) idx++;
94
+ return input.slice(idx);
455
95
  });
456
- /**
457
- * Takes the longest prefix of elements from an array that satisfy the given predicate.
458
- *
459
- * Supports both data-first and data-last (`pipe`-friendly) call styles.
460
- *
461
- * @param pred - The predicate to test each element with.
462
- * @returns A new array containing only the matching prefix.
463
- * @example
464
- * ```ts
465
- * import * as assert from "node:assert"
466
- * import { pipe, takeWhile } from "@local/eff"
467
- *
468
- * // data-first
469
- * assert.deepStrictEqual(takeWhile([1, 2, 3, 2, 1], (n: number) => n < 3), [1, 2])
470
- *
471
- * // data-last
472
- * assert.deepStrictEqual(pipe([1, 2, 3, 2, 1], takeWhile((n: number) => n < 3)), [1, 2])
473
- * ```
474
- * @category array
475
- */
476
- const takeWhile = dual(2, (xs, pred) => {
477
- const len = xs.length;
96
+ const takeWhile = dual(2, (self, predicate) => {
97
+ const input = Array.isArray(self) ? self : Array.from(self);
98
+ const len = input.length;
478
99
  let idx = 0;
479
- while (idx < len && pred(xs[idx])) idx++;
480
- return xs.slice(0, idx);
100
+ while (idx < len && predicate(input[idx], idx)) idx++;
101
+ return input.slice(0, idx);
481
102
  });
482
103
 
483
104
  //#endregion
484
105
  //#region src/attribute-name.ts
485
- /**
486
- * Get the stringified name of a `JSXAttribute` node.
487
- *
488
- * - `className` -> `"className"`
489
- * - `aria-label` -> `"aria-label"`
490
- * - `xml:space` -> `"xml:space"`.
491
- * @param node The `JSXAttribute` node to get the name from.
492
- * @returns The attribute name as a plain string.
493
- */
494
106
  function getAttributeName(node) {
495
107
  if (node.name.type === AST_NODE_TYPES.JSXIdentifier) return node.name.name;
496
108
  return node.name.namespace.name + ":" + node.name.name.name;
497
109
  }
498
- /**
499
- * Check if the node is a `JSXAttribute` with the given name.
500
- *
501
- * Only plain identifier names are matched (ex: `className`); namespaced
502
- * attributes (ex: `xml:space`) do not match.
503
- *
504
- * Supports both data-first and data-last (curried) call styles:
505
- * - `isAttribute(node, "className")`
506
- * - `isAttribute("className")(node)`.
507
- * @param node The node to check.
508
- * @param name The attribute name to match (ex: "className").
509
- * @returns `true` if the node is a `JSXAttribute` named `name`.
510
- */
511
110
  const isAttribute = dual(2, (node, name) => {
512
111
  return node.type === AST_NODE_TYPES.JSXAttribute && node.name.type === AST_NODE_TYPES.JSXIdentifier && node.name.name === name;
513
112
  });
514
113
 
515
114
  //#endregion
516
115
  //#region src/attribute-find.ts
517
- /**
518
- * Find a JSX attribute (or a spread attribute containing the property) by name.
519
- *
520
- * Returns the last matching attribute to mirror React's behavior where later props win.
521
- * Spread attributes are resolved when possible: if the spread argument is an identifier
522
- * that resolves to an object expression, the object's properties are searched for a
523
- * matching key (see {@link findSpreadProperty}).
524
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
525
- * @param element The `JSXElement` node to search.
526
- * @param name The attribute name to look for (ex: "className").
527
- * @returns The matching `JSXAttribute` or `JSXSpreadAttribute`, or `undefined` when not found.
528
- */
529
116
  function findAttribute(context, element, name) {
530
117
  return element.openingElement.attributes.findLast((attr) => {
531
118
  if (attr.type === AST_NODE_TYPES.JSXAttribute) return getAttributeName(attr) === name;
532
119
  return findSpreadProperty(context, attr.argument, name) != null;
533
120
  });
534
121
  }
535
- /**
536
- * Walk up the AST from `node` to find the nearest `JSXAttribute` ancestor, optionally matching a predicate.
537
- * @param node The starting node for the upward search.
538
- * @param test Optional predicate to filter candidate `JSXAttribute` nodes.
539
- * @returns The first matching `JSXAttribute` ancestor, or `undefined` when none is found.
540
- */
541
122
  function findParentAttribute(node, test = () => true) {
542
123
  const guard = (n) => {
543
124
  return n.type === AST_NODE_TYPES.JSXAttribute && test(n);
544
125
  };
545
126
  return Traverse.findParent(node, guard) ?? void 0;
546
127
  }
547
- /**
548
- * Find the `Property` node that provides a given key inside a spread argument.
549
- *
550
- * This is the single resolution routine shared by {@link findAttribute} (existence
551
- * checks) and the `spreadProps` variant of `resolveAttributeValue` (value extraction):
552
- *
553
- * - An `Identifier` argument is resolved to its initializer via variable
554
- * resolution, following alias chains (`const b = a`) like `getStaticValue`
555
- * does; an `ObjectExpression` argument is searched directly.
556
- * - Properties are walked **in reverse** so that later entries win, matching
557
- * JavaScript object semantics (`{ ...a, k: 1 }` -> the literal `k`).
558
- * - Nested `SpreadElement`s (identifiers or inline object expressions) are
559
- * searched recursively; a `seen` set guards against circular references.
560
- * - Plain identifier keys and string literal keys are matched directly;
561
- * computed keys are matched when they are statically evaluable
562
- * (ex: `{ ["class" + "Name"]: 1 }`).
563
- * @param context The ESLint rule context (needed for variable resolution).
564
- * @param argument The spread argument expression to search.
565
- * @param name The property name to look for.
566
- * @param seen Internal set of already-visited nodes (cycle guard).
567
- * @returns The matching `Property` node, or `undefined` when the key is not found.
568
- */
569
128
  function findSpreadProperty(context, argument, name, seen = /* @__PURE__ */ new Set()) {
570
129
  let objectExpression;
571
130
  if (Check.isIdentifier(argument)) {
@@ -600,81 +159,27 @@ function findSpreadProperty(context, argument, name, seen = /* @__PURE__ */ new
600
159
 
601
160
  //#endregion
602
161
  //#region src/attribute-has.ts
603
- /**
604
- * Check if the element has an attribute with the given name.
605
- *
606
- * Spread attributes are taken into account: `<Comp {...{ disabled: true }} />`
607
- * reports `true` for `"disabled"` (see {@link findAttribute}).
608
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
609
- * @param element The `JSXElement` node to check.
610
- * @param name The attribute name to look for (ex: "className").
611
- * @returns `true` if the attribute is present on the element.
612
- */
613
162
  function hasAttribute(context, element, name) {
614
163
  return findAttribute(context, element, name) != null;
615
164
  }
616
- /**
617
- * Check if the element has at least one of the given attributes.
618
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
619
- * @param element The `JSXElement` node to check.
620
- * @param names The attribute names to look for.
621
- * @returns `true` if at least one of the attributes is present.
622
- */
623
165
  function hasAnyAttribute(context, element, names) {
624
166
  return names.some((name) => findAttribute(context, element, name) != null);
625
167
  }
626
- /**
627
- * Check if the element has all of the given attributes.
628
- * @param context The ESLint rule context (needed for variable resolution in spread attributes).
629
- * @param element The `JSXElement` node to check.
630
- * @param names The attribute names to look for.
631
- * @returns `true` if every attribute is present on the element.
632
- */
633
168
  function hasEveryAttribute(context, element, names) {
634
169
  return names.every((name) => findAttribute(context, element, name) != null);
635
170
  }
636
171
 
637
172
  //#endregion
638
173
  //#region src/attribute-value.ts
639
- /**
640
- * Resolve the value of a JSX attribute (or spread attribute) into an {@link AttributeValue} descriptor.
641
- *
642
- * When the attribute is a `JSXSpreadAttribute`, passing `name` (typically the name
643
- * the attribute was found by) makes `toStatic()` return the static value of that
644
- * named property. For the higher-level "find by name and resolve" combo, see {@link getAttributeValue}.
645
- * @param context The ESLint rule context (needed for scope look-ups).
646
- * @param attribute A `JSXAttribute` or `JSXSpreadAttribute` node.
647
- * @param name Optional property name used to resolve `toStatic()` for spread attributes.
648
- * @returns A discriminated-union descriptor of the attribute's value.
649
- */
650
174
  function resolveAttributeValue(context, attribute, name) {
651
175
  if (attribute.type === AST_NODE_TYPES.JSXAttribute) return resolveJsxAttribute(context, attribute);
652
176
  return resolveJsxSpreadAttribute(context, attribute, name);
653
177
  }
654
- /**
655
- * Find an attribute by name on a JSX element and resolve its value in a single call.
656
- *
657
- * Convenience composition of {@link findAttribute} and {@link resolveAttributeValue}.
658
- * @param context The ESLint rule context.
659
- * @param element The `JSXElement` node to search.
660
- * @param name The attribute name to look up (ex: "className").
661
- * @returns An {@link AttributeValue} descriptor, or `undefined` when the attribute is not present.
662
- */
663
178
  function getAttributeValue(context, element, name) {
664
179
  const attr = findAttribute(context, element, name);
665
180
  if (attr == null) return void 0;
666
181
  return resolveAttributeValue(context, attr, name);
667
182
  }
668
- /**
669
- * Find an attribute by name on a JSX element and collapse its value to a plain JavaScript value.
670
- *
671
- * Returns `undefined` both when the attribute is absent and when its value cannot
672
- * be statically determined; use {@link hasAttribute} when presence itself matters.
673
- * @param context The ESLint rule context.
674
- * @param element The `JSXElement` node to check.
675
- * @param name The attribute name to look up (ex: "className").
676
- * @returns The static value of the attribute, or `undefined` when absent or indeterminate.
677
- */
678
183
  function getAttributeStaticValue(context, element, name) {
679
184
  return getAttributeValue(context, element, name)?.toStatic();
680
185
  }
@@ -744,19 +249,6 @@ function resolveJsxSpreadAttribute(context, node, name) {
744
249
 
745
250
  //#endregion
746
251
  //#region src/text.ts
747
- /**
748
- * Collapse a multiline JSX text string following React's whitespace rules.
749
- *
750
- * Mirrors Babel's `cleanJSXElementLiteralChild` algorithm:
751
- * 1. Split the raw text into lines.
752
- * 2. Find the last non-empty line.
753
- * 3. Trim leading spaces on non-first lines and trailing spaces on non-last lines.
754
- * 4. Collapse tabs into spaces.
755
- * 5. Append a single space after each non-last non-empty line.
756
- * @param text The raw JSX text string to collapse.
757
- * @returns The collapsed string, or `null` when the text contains only whitespace.
758
- * @see https://github.com/babel/babel/blob/main/packages/babel-types/src/utils/react/cleanJSXElementLiteralChild.ts
759
- */
760
252
  function collapseMultilineText(text) {
761
253
  const lines = text.split(/\r\n|\n|\r/);
762
254
  let lastNonEmptyLine = 0;
@@ -777,40 +269,14 @@ function collapseMultilineText(text) {
777
269
  }
778
270
  return str === "" ? null : str;
779
271
  }
780
- /**
781
- * Check if the node is whitespace padding that React would trim away during
782
- * rendering, that is, a `JSXText` node that cleans to nothing (see
783
- * {@link collapseMultilineText}) and contains a newline.
784
- *
785
- * For the looser "any whitespace-only text" check, see {@link isWhitespaceText}.
786
- * @param node The JSX child node to check.
787
- * @returns `true` if the node is purely formatting whitespace.
788
- */
789
272
  function isPaddingWhitespace(node) {
790
273
  if (node.type !== AST_NODE_TYPES.JSXText) return false;
791
274
  return collapseMultilineText(node.value) == null && node.value.includes("\n");
792
275
  }
793
- /**
794
- * Check if the node is whitespace-only text.
795
- *
796
- * Looser variant of {@link isPaddingWhitespace}; matches every `JSXText` node
797
- * whose raw content is empty after trimming, regardless of newlines.
798
- * @param node The JSX child node to check.
799
- * @returns `true` if the node is a whitespace-only `JSXText`.
800
- */
801
276
  function isWhitespaceText(node) {
802
277
  if (node.type !== AST_NODE_TYPES.JSXText) return false;
803
278
  return node.raw.trim() === "";
804
279
  }
805
- /**
806
- * Check if the node is an empty string expression (`{""}`).
807
- *
808
- * React's reconciler and SSR renderer explicitly skip empty strings, producing no
809
- * DOM node, so such expressions are treated as non-rendered children, same as
810
- * whitespace padding.
811
- * @param node The JSX child node to check.
812
- * @returns `true` if the node is a `{""}` expression container.
813
- */
814
280
  function isEmptyStringExpression(node) {
815
281
  if (node.type !== AST_NODE_TYPES.JSXExpressionContainer) return false;
816
282
  const expr = node.expression;
@@ -820,18 +286,6 @@ function isEmptyStringExpression(node) {
820
286
 
821
287
  //#endregion
822
288
  //#region src/children.ts
823
- /**
824
- * Get the meaningful children of a JSX element or fragment.
825
- *
826
- * Mirrors Babel's `buildChildren` helper:
827
- * 1. Iterate over `element.children`.
828
- * 2. Skip `JSXText` nodes that clean to nothing (padding whitespace).
829
- * 3. Skip `JSXExpressionContainer` nodes whose expression is empty.
830
- * 4. Skip empty string expressions (`{""}`), which produce no DOM node.
831
- * 5. Collect everything else.
832
- * @param element A `JSXElement` or `JSXFragment` node.
833
- * @returns The children nodes that contribute to rendered output.
834
- */
835
289
  function getChildren(element) {
836
290
  const children = [];
837
291
  for (const child of element.children) {
@@ -844,16 +298,6 @@ function getChildren(element) {
844
298
  }
845
299
  return children;
846
300
  }
847
- /**
848
- * Check if the element has at least one meaningful child, that is, a child that
849
- * is not purely whitespace text or an empty string expression (`{""}`).
850
- *
851
- * Unlike {@link getChildren} (which only filters whitespace containing a newline),
852
- * this check treats any whitespace-only text as non-meaningful, so `hasChildren(node)`
853
- * is not always equal to `getChildren(node).length > 0` (ex: `<div> </div>`).
854
- * @param element A `JSXElement` or `JSXFragment` node.
855
- * @returns `true` if the element has at least one meaningful child.
856
- */
857
301
  function hasChildren(element) {
858
302
  if (element.children.length === 0) return false;
859
303
  return !element.children.every(or(isWhitespaceText, isEmptyStringExpression));
@@ -861,17 +305,6 @@ function hasChildren(element) {
861
305
 
862
306
  //#endregion
863
307
  //#region src/element-type.ts
864
- /**
865
- * Get the string representation of a JSX element's type.
866
- *
867
- * - `<div>` -> `"div"`
868
- * - `<Foo.Bar>` -> `"Foo.Bar"`
869
- * - `<React.Fragment>` -> `"React.Fragment"`
870
- * - `<xml:space>` -> `"xml:space"`
871
- * - `<></>` -> `""`.
872
- * @param node The `JSXElement` or `JSXFragment` node.
873
- * @returns The fully qualified element type string.
874
- */
875
308
  function getElementFullType(node) {
876
309
  if (node.type === AST_NODE_TYPES.JSXFragment) return "";
877
310
  function getQualifiedName(node) {
@@ -883,31 +316,12 @@ function getElementFullType(node) {
883
316
  }
884
317
  return getQualifiedName(node.openingElement.name);
885
318
  }
886
- /**
887
- * Get the self name (last dot-separated segment) of a JSX element type.
888
- *
889
- * - `<Foo.Bar.Baz>` -> `"Baz"`
890
- * - `<div>` -> `"div"`
891
- * - `<></>` -> `""`
892
- * @param node The `JSXElement` or `JSXFragment` node.
893
- * @returns The last segment of the element type, or `""` for fragments.
894
- */
895
319
  function getElementSelfType(node) {
896
320
  return getElementFullType(node).split(".").at(-1) ?? "";
897
321
  }
898
322
 
899
323
  //#endregion
900
324
  //#region src/element-is.ts
901
- /**
902
- * Check if the node is a `JSXElement` (or `JSXFragment`), optionally matching a given test.
903
- *
904
- * Modelled after [`hast-util-is-element`](https://github.com/syntax-tree/hast-util-is-element):
905
- * the `test` parameter controls what counts as a match. When called without a test,
906
- * the function acts as a simple type guard for `JSXElement | JSXFragment`.
907
- * @param node The node to check.
908
- * @param test Optional test to match the element type against.
909
- * @returns `true` if the node is a matching JSX element.
910
- */
911
325
  function isElement(node, test) {
912
326
  if (node == null) return false;
913
327
  if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
@@ -915,36 +329,12 @@ function isElement(node, test) {
915
329
  const type = getElementFullType(node);
916
330
  return match(test).with(P.string, (t) => type === t).with(P.array(), (t) => t.includes(type)).with(P.instanceOf(Function), (t) => t(type, node)).exhaustive();
917
331
  }
918
- /**
919
- * Check if the node is a React Fragment element.
920
- *
921
- * Recognizes both the shorthand `<>...</>` syntax (`JSXFragment`) and the explicit
922
- * `<Fragment>` / `<React.Fragment>` form (`JSXElement`). The comparison is performed
923
- * against the self name (last dot-separated segment) of both the node and the
924
- * configured factory, so `<React.Fragment>` matches `"React.Fragment"` and
925
- * `<Fragment>` matches `"Fragment"`.
926
- *
927
- * The factory is a required parameter (no implicit `"React.Fragment"` default) so
928
- * that callers always pass the project-configured pragma — see `getJsxConfig` in
929
- * `@eslint-react/core` — and cannot silently use the wrong factory under a custom
930
- * JSX runtime (ex: Preact). Note the self-name comparison is a heuristic: any
931
- * `<*.Fragment>` member expression matches, regardless of the qualifier.
932
- * @param node The node to check.
933
- * @param jsxFragmentFactory The configured fragment factory string (ex: "React.Fragment").
934
- * @returns `true` if the node represents a React Fragment.
935
- */
936
332
  function isFragmentElement(node, jsxFragmentFactory) {
937
333
  if (node.type === AST_NODE_TYPES.JSXFragment) return true;
938
334
  if (node.type !== AST_NODE_TYPES.JSXElement) return false;
939
335
  const fragment = jsxFragmentFactory.split(".").at(-1) ?? "Fragment";
940
336
  return getElementFullType(node).split(".").at(-1) === fragment;
941
337
  }
942
- /**
943
- * Check if the node is a host (intrinsic / DOM) element, that is, a `JSXElement`
944
- * whose tag name starts with a lowercase letter (ex: `<div>` vs `<MyComponent>`).
945
- * @param node The node to check.
946
- * @returns `true` if the node is a `JSXElement` with a lowercase tag name.
947
- */
948
338
  function isHostElement(node) {
949
339
  if (node.type !== AST_NODE_TYPES.JSXElement) return false;
950
340
  const name = node.openingElement.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/jsx",
3
- "version": "5.24.0",
3
+ "version": "5.24.2",
4
4
  "description": "ESLint React's TSESTree JSX utility module for static analysis of JSX patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -29,9 +29,9 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@eslint-react/ast": "5.24.0",
33
- "@eslint-react/eslint": "5.24.0",
34
- "@eslint-react/var": "5.24.0",
32
+ "@eslint-react/ast": "5.24.2",
33
+ "@eslint-react/eslint": "5.24.2",
34
+ "@eslint-react/var": "5.24.2",
35
35
  "@typescript-eslint/types": "^8.71.0",
36
36
  "@typescript-eslint/utils": "^8.71.0",
37
37
  "ts-pattern": "^5.9.0"
@@ -40,7 +40,7 @@
40
40
  "@local/configs": "0.0.0",
41
41
  "@local/eff": "0.0.0",
42
42
  "@local/testkit": "0.0.0",
43
- "eslint": "^10.11.0",
43
+ "eslint": "^10.12.0",
44
44
  "tsdown": "^0.23.0",
45
45
  "typescript": "6.0.3"
46
46
  },