eslint-plugin-react-jsx 5.24.1 → 5.24.3
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.js +1 -734
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
26
26
|
//#endregion
|
|
27
27
|
//#region package.json
|
|
28
28
|
var name$2 = "eslint-plugin-react-jsx";
|
|
29
|
-
var version = "5.24.
|
|
29
|
+
var version = "5.24.3";
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region src/utils/create-rule.ts
|
|
@@ -37,13 +37,6 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/utils/remove-jsx-attribute.ts
|
|
40
|
-
/**
|
|
41
|
-
* Builds a fix that removes a JSX attribute along with the whitespace before it.
|
|
42
|
-
* @param context The rule context
|
|
43
|
-
* @param fixer The rule fixer
|
|
44
|
-
* @param attribute The `JSXAttribute` node to remove
|
|
45
|
-
* @returns A fix that removes the attribute and its preceding whitespace
|
|
46
|
-
*/
|
|
47
40
|
function removeJsxAttribute(context, fixer, attribute) {
|
|
48
41
|
let start = attribute.range[0];
|
|
49
42
|
while (start > 0 && /\s/.test(context.sourceCode.text[start - 1] ?? "")) start--;
|
|
@@ -171,12 +164,6 @@ function create$6(context) {
|
|
|
171
164
|
}
|
|
172
165
|
};
|
|
173
166
|
}
|
|
174
|
-
/**
|
|
175
|
-
* Turns the value of a 'children' JSXAttribute into text usable as element content
|
|
176
|
-
* @param context The rule context
|
|
177
|
-
* @param attribute The 'children' JSXAttribute node
|
|
178
|
-
* @returns The text to insert as element content, or `null` when no usable value exists
|
|
179
|
-
*/
|
|
180
167
|
function getChildrenText(context, attribute) {
|
|
181
168
|
const { value } = attribute;
|
|
182
169
|
if (value?.type === AST_NODE_TYPES.Literal) return escapeJsxText(String(value.value));
|
|
@@ -186,22 +173,9 @@ function getChildrenText(context, attribute) {
|
|
|
186
173
|
}
|
|
187
174
|
return null;
|
|
188
175
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Escapes characters that would be parsed as markup in JSX text
|
|
191
|
-
* @param text The raw string value
|
|
192
|
-
* @returns The escaped text safe for insertion as JSX content
|
|
193
|
-
*/
|
|
194
176
|
function escapeJsxText(text) {
|
|
195
177
|
return text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("{", "{").replaceAll("}", "}");
|
|
196
178
|
}
|
|
197
|
-
/**
|
|
198
|
-
* Builds the fix that moves the 'children' prop value into the element's content
|
|
199
|
-
* @param context The rule context object
|
|
200
|
-
* @param node The JSXElement node being reported
|
|
201
|
-
* @param prop The 'children' JSXAttribute to remove
|
|
202
|
-
* @param childrenText The text to insert as element content
|
|
203
|
-
* @returns A fixer function that applies the changes
|
|
204
|
-
*/
|
|
205
179
|
function buildFix$1(context, node, prop, childrenText) {
|
|
206
180
|
return (fixer) => {
|
|
207
181
|
const sourceCode = context.sourceCode;
|
|
@@ -246,44 +220,6 @@ function create$5(context) {
|
|
|
246
220
|
|
|
247
221
|
//#endregion
|
|
248
222
|
//#region ../../.pkgs/eff/dist/index.js
|
|
249
|
-
/**
|
|
250
|
-
* Applies a `pipe` method's variadic arguments to an initial value from left
|
|
251
|
-
* to right.
|
|
252
|
-
*
|
|
253
|
-
* **When to use**
|
|
254
|
-
*
|
|
255
|
-
* Use to implement a custom `.pipe(...)` method from JavaScript's `arguments`
|
|
256
|
-
* object.
|
|
257
|
-
*
|
|
258
|
-
* **Details**
|
|
259
|
-
*
|
|
260
|
-
* This helper is intended for implementing `Pipeable.pipe` methods that
|
|
261
|
-
* receive JavaScript's `arguments` object. With no functions it returns the
|
|
262
|
-
* original value; otherwise it feeds each result into the next function.
|
|
263
|
-
*
|
|
264
|
-
* **Example** (Implementing a pipe method)
|
|
265
|
-
*
|
|
266
|
-
* ```ts
|
|
267
|
-
* import { Pipeable } from "effect"
|
|
268
|
-
*
|
|
269
|
-
* class NumberBox {
|
|
270
|
-
* constructor(readonly value: number) {}
|
|
271
|
-
*
|
|
272
|
-
* pipe(..._fns: ReadonlyArray<(value: number) => number>): number {
|
|
273
|
-
* return Pipeable.pipeArguments(this.value, arguments) as number
|
|
274
|
-
* }
|
|
275
|
-
* }
|
|
276
|
-
*
|
|
277
|
-
* const result = new NumberBox(5).pipe(
|
|
278
|
-
* (n) => n + 2,
|
|
279
|
-
* (n) => n * 3
|
|
280
|
-
* )
|
|
281
|
-
* result // => 21
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
* @category combinators
|
|
285
|
-
* @since 2.0.0
|
|
286
|
-
*/
|
|
287
223
|
const pipeArguments = (self, args) => {
|
|
288
224
|
switch (args.length) {
|
|
289
225
|
case 0: return self;
|
|
@@ -303,100 +239,14 @@ const pipeArguments = (self, args) => {
|
|
|
303
239
|
}
|
|
304
240
|
}
|
|
305
241
|
};
|
|
306
|
-
/**
|
|
307
|
-
* Reusable prototype that implements `Pipeable.pipe`.
|
|
308
|
-
*
|
|
309
|
-
* **When to use**
|
|
310
|
-
*
|
|
311
|
-
* Use when classes or object prototypes can reuse this value when they need the
|
|
312
|
-
* standard pipe implementation backed by `pipeArguments`.
|
|
313
|
-
*
|
|
314
|
-
* @category prototypes
|
|
315
|
-
* @since 3.15.0
|
|
316
|
-
*/
|
|
317
242
|
const Prototype = { pipe() {
|
|
318
243
|
return pipeArguments(this, arguments);
|
|
319
244
|
} };
|
|
320
|
-
/**
|
|
321
|
-
* Provides a base constructor whose instances implement the standard `Pipeable.pipe`
|
|
322
|
-
* method.
|
|
323
|
-
*
|
|
324
|
-
* **When to use**
|
|
325
|
-
*
|
|
326
|
-
* Use when you need to define a class that supports Effect-style method
|
|
327
|
-
* chaining through `.pipe(...)`.
|
|
328
|
-
*
|
|
329
|
-
* @category constructors
|
|
330
|
-
* @since 3.15.0
|
|
331
|
-
*/
|
|
332
245
|
const Class = (function() {
|
|
333
246
|
function PipeableBase() {}
|
|
334
247
|
PipeableBase.prototype = Prototype;
|
|
335
248
|
return PipeableBase;
|
|
336
249
|
})();
|
|
337
|
-
/**
|
|
338
|
-
* Creates a function that can be called in data-first style or data-last
|
|
339
|
-
* (`pipe`-friendly) style.
|
|
340
|
-
*
|
|
341
|
-
* **When to use**
|
|
342
|
-
*
|
|
343
|
-
* Use to expose one implementation through both direct and `pipe`-friendly
|
|
344
|
-
* call styles.
|
|
345
|
-
*
|
|
346
|
-
* **Details**
|
|
347
|
-
*
|
|
348
|
-
* Pass either the arity of the uncurried function or a predicate that decides
|
|
349
|
-
* whether the current call is data-first. Arity is the common case. Use a
|
|
350
|
-
* predicate when optional arguments make arity ambiguous.
|
|
351
|
-
*
|
|
352
|
-
* **Example** (Selecting data-first or data-last style by arity)
|
|
353
|
-
*
|
|
354
|
-
* ```ts
|
|
355
|
-
* import { Function, pipe } from "effect"
|
|
356
|
-
*
|
|
357
|
-
* const sum = Function.dual<
|
|
358
|
-
* (that: number) => (self: number) => number,
|
|
359
|
-
* (self: number, that: number) => number
|
|
360
|
-
* >(2, (self, that) => self + that)
|
|
361
|
-
*
|
|
362
|
-
* sum(2, 3) // => 5
|
|
363
|
-
* pipe(2, sum(3)) // => 5
|
|
364
|
-
* ```
|
|
365
|
-
*
|
|
366
|
-
* **Example** (Defining overloads with call signatures)
|
|
367
|
-
*
|
|
368
|
-
* ```ts
|
|
369
|
-
* import { Function, pipe } from "effect"
|
|
370
|
-
*
|
|
371
|
-
* const sum: {
|
|
372
|
-
* (that: number): (self: number) => number
|
|
373
|
-
* (self: number, that: number): number
|
|
374
|
-
* } = Function.dual(2, (self: number, that: number): number => self + that)
|
|
375
|
-
*
|
|
376
|
-
* sum(2, 3) // => 5
|
|
377
|
-
* pipe(2, sum(3)) // => 5
|
|
378
|
-
* ```
|
|
379
|
-
*
|
|
380
|
-
* **Example** (Selecting data-first or data-last style with a predicate)
|
|
381
|
-
*
|
|
382
|
-
* ```ts
|
|
383
|
-
* import { Function, pipe } from "effect"
|
|
384
|
-
*
|
|
385
|
-
* const sum = Function.dual<
|
|
386
|
-
* (that: number) => (self: number) => number,
|
|
387
|
-
* (self: number, that: number) => number
|
|
388
|
-
* >(
|
|
389
|
-
* (args) => args.length === 2,
|
|
390
|
-
* (self, that) => self + that
|
|
391
|
-
* )
|
|
392
|
-
*
|
|
393
|
-
* sum(2, 3) // => 5
|
|
394
|
-
* pipe(2, sum(3)) // => 5
|
|
395
|
-
* ```
|
|
396
|
-
*
|
|
397
|
-
* @category combinators
|
|
398
|
-
* @since 2.0.0
|
|
399
|
-
*/
|
|
400
250
|
const dual = function(arity, body) {
|
|
401
251
|
if (typeof arity === "function") return function() {
|
|
402
252
|
return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
|
|
@@ -425,558 +275,35 @@ const dual = function(arity, body) {
|
|
|
425
275
|
};
|
|
426
276
|
}
|
|
427
277
|
};
|
|
428
|
-
/**
|
|
429
|
-
* Returns its input argument unchanged.
|
|
430
|
-
*
|
|
431
|
-
* **When to use**
|
|
432
|
-
*
|
|
433
|
-
* Use to return a value unchanged where a function is required.
|
|
434
|
-
*
|
|
435
|
-
* **Example** (Returning the same value)
|
|
436
|
-
*
|
|
437
|
-
* ```ts
|
|
438
|
-
* import { identity } from "effect"
|
|
439
|
-
*
|
|
440
|
-
* identity(5) // => 5
|
|
441
|
-
* ```
|
|
442
|
-
*
|
|
443
|
-
* @category combinators
|
|
444
|
-
* @since 2.0.0
|
|
445
|
-
*/
|
|
446
278
|
const identity = (a) => a;
|
|
447
|
-
/**
|
|
448
|
-
* Returns the input value with a different static type.
|
|
449
|
-
*
|
|
450
|
-
* **When to use**
|
|
451
|
-
*
|
|
452
|
-
* Use when you need an explicit type-level cast and accept that the value is
|
|
453
|
-
* returned unchanged at runtime.
|
|
454
|
-
*
|
|
455
|
-
* **Gotchas**
|
|
456
|
-
*
|
|
457
|
-
* This is a type-level cast only; it performs no runtime validation or
|
|
458
|
-
* conversion.
|
|
459
|
-
*
|
|
460
|
-
* @see {@link satisfies} for checking assignability without changing the resulting type
|
|
461
|
-
*
|
|
462
|
-
* @category utility types
|
|
463
|
-
* @since 4.0.0
|
|
464
|
-
*/
|
|
465
279
|
const cast = identity;
|
|
466
|
-
/**
|
|
467
|
-
* Creates a zero-argument function that always returns the provided value.
|
|
468
|
-
*
|
|
469
|
-
* **When to use**
|
|
470
|
-
*
|
|
471
|
-
* Use when you need a thunk or callback that returns the same value on every
|
|
472
|
-
* invocation.
|
|
473
|
-
*
|
|
474
|
-
* **Example** (Creating a constant thunk)
|
|
475
|
-
*
|
|
476
|
-
* ```ts
|
|
477
|
-
* import { Function } from "effect"
|
|
478
|
-
*
|
|
479
|
-
* const constNull = Function.constant(null)
|
|
480
|
-
*
|
|
481
|
-
* constNull() // => null
|
|
482
|
-
* constNull() // => null
|
|
483
|
-
* ```
|
|
484
|
-
*
|
|
485
|
-
* @category constructors
|
|
486
|
-
* @since 2.0.0
|
|
487
|
-
*/
|
|
488
280
|
const constant = (value) => () => value;
|
|
489
|
-
/**
|
|
490
|
-
* Returns `true` when called.
|
|
491
|
-
*
|
|
492
|
-
* **When to use**
|
|
493
|
-
*
|
|
494
|
-
* Use when you need a thunk that returns `true` on every invocation.
|
|
495
|
-
*
|
|
496
|
-
* **Example** (Returning true from a thunk)
|
|
497
|
-
*
|
|
498
|
-
* ```ts
|
|
499
|
-
* import { Function } from "effect"
|
|
500
|
-
*
|
|
501
|
-
* Function.constTrue() // => true
|
|
502
|
-
* ```
|
|
503
|
-
*
|
|
504
|
-
* @category constants
|
|
505
|
-
* @since 2.0.0
|
|
506
|
-
*/
|
|
507
281
|
const constTrue = constant(true);
|
|
508
|
-
/**
|
|
509
|
-
* Returns `false` when called.
|
|
510
|
-
*
|
|
511
|
-
* **When to use**
|
|
512
|
-
*
|
|
513
|
-
* Use when you need a thunk that returns `false` on every invocation.
|
|
514
|
-
*
|
|
515
|
-
* **Example** (Returning false from a thunk)
|
|
516
|
-
*
|
|
517
|
-
* ```ts
|
|
518
|
-
* import { Function } from "effect"
|
|
519
|
-
*
|
|
520
|
-
* Function.constFalse() // => false
|
|
521
|
-
* ```
|
|
522
|
-
*
|
|
523
|
-
* @category constants
|
|
524
|
-
* @since 2.0.0
|
|
525
|
-
*/
|
|
526
282
|
const constFalse = constant(false);
|
|
527
|
-
/**
|
|
528
|
-
* Returns `null` when called.
|
|
529
|
-
*
|
|
530
|
-
* **When to use**
|
|
531
|
-
*
|
|
532
|
-
* Use when you need a thunk that returns `null` on every invocation.
|
|
533
|
-
*
|
|
534
|
-
* **Example** (Returning null from a thunk)
|
|
535
|
-
*
|
|
536
|
-
* ```ts
|
|
537
|
-
* import { Function } from "effect"
|
|
538
|
-
*
|
|
539
|
-
* Function.constNull() // => null
|
|
540
|
-
* ```
|
|
541
|
-
*
|
|
542
|
-
* @category constants
|
|
543
|
-
* @since 2.0.0
|
|
544
|
-
*/
|
|
545
283
|
const constNull = constant(null);
|
|
546
|
-
/**
|
|
547
|
-
* Returns `undefined` when called.
|
|
548
|
-
*
|
|
549
|
-
* **When to use**
|
|
550
|
-
*
|
|
551
|
-
* Use when you need a thunk that returns `undefined` on every invocation.
|
|
552
|
-
*
|
|
553
|
-
* **Example** (Returning undefined from a thunk)
|
|
554
|
-
*
|
|
555
|
-
* ```ts
|
|
556
|
-
* import { Function } from "effect"
|
|
557
|
-
*
|
|
558
|
-
* Function.constUndefined() // => undefined
|
|
559
|
-
* ```
|
|
560
|
-
*
|
|
561
|
-
* @category constants
|
|
562
|
-
* @since 2.0.0
|
|
563
|
-
*/
|
|
564
284
|
const constUndefined = constant(void 0);
|
|
565
|
-
/**
|
|
566
|
-
* 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`.
|
|
567
|
-
* The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
|
|
568
|
-
*
|
|
569
|
-
* **When to use**
|
|
570
|
-
*
|
|
571
|
-
* Use to compose exactly two unary functions into a reusable unary function.
|
|
572
|
-
*
|
|
573
|
-
* **Example** (Composing two functions)
|
|
574
|
-
*
|
|
575
|
-
* ```ts
|
|
576
|
-
* import { Function } from "effect"
|
|
577
|
-
*
|
|
578
|
-
* const increment = (n: number) => n + 1
|
|
579
|
-
* const square = (n: number) => n * n
|
|
580
|
-
*
|
|
581
|
-
* Function.compose(increment, square)(2) // => 9
|
|
582
|
-
* ```
|
|
583
|
-
*
|
|
584
|
-
* @see {@link flow} for composing a left-to-right sequence of functions
|
|
585
|
-
* @see {@link pipe} for applying a value through a left-to-right sequence immediately
|
|
586
|
-
*
|
|
587
|
-
* @category combinators
|
|
588
|
-
* @since 2.0.0
|
|
589
|
-
*/
|
|
590
285
|
const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
591
|
-
/**
|
|
592
|
-
* Marks an impossible branch by accepting a `never` value and returning any
|
|
593
|
-
* type.
|
|
594
|
-
*
|
|
595
|
-
* **When to use**
|
|
596
|
-
*
|
|
597
|
-
* Use when you need a return value in a branch that exhaustive checks prove
|
|
598
|
-
* cannot be reached.
|
|
599
|
-
*
|
|
600
|
-
* **Gotchas**
|
|
601
|
-
*
|
|
602
|
-
* Calling `absurd` throws, because a value of type `never` should be
|
|
603
|
-
* impossible at runtime.
|
|
604
|
-
*
|
|
605
|
-
* **Example** (Handling impossible values)
|
|
606
|
-
*
|
|
607
|
-
* ```ts
|
|
608
|
-
* import { absurd } from "effect"
|
|
609
|
-
*
|
|
610
|
-
* const handleNever = (value: never) => {
|
|
611
|
-
* return absurd(value) // This will throw an error if called
|
|
612
|
-
* }
|
|
613
|
-
* ```
|
|
614
|
-
*
|
|
615
|
-
* @category utility types
|
|
616
|
-
* @since 2.0.0
|
|
617
|
-
*/
|
|
618
286
|
const absurd = (_) => {
|
|
619
287
|
throw new Error("Called `absurd` function which should be uncallable");
|
|
620
288
|
};
|
|
621
|
-
/**
|
|
622
|
-
* Creates a compile-time placeholder for a value of any type.
|
|
623
|
-
*
|
|
624
|
-
* **When to use**
|
|
625
|
-
*
|
|
626
|
-
* Use as a temporary typed placeholder while developing incomplete code.
|
|
627
|
-
*
|
|
628
|
-
* **Gotchas**
|
|
629
|
-
*
|
|
630
|
-
* `hole` is intended for temporary development use. If the placeholder is
|
|
631
|
-
* evaluated at runtime, it throws.
|
|
632
|
-
*
|
|
633
|
-
* **Example** (Creating a development placeholder)
|
|
634
|
-
*
|
|
635
|
-
* ```ts
|
|
636
|
-
* import { hole } from "effect"
|
|
637
|
-
*
|
|
638
|
-
* // Intentionally not called: `hole` throws if the placeholder is evaluated.
|
|
639
|
-
* const buildUser = (id: number): { readonly id: number; readonly name: string } => ({
|
|
640
|
-
* id,
|
|
641
|
-
* name: hole<string>()
|
|
642
|
-
* })
|
|
643
|
-
*
|
|
644
|
-
* ```
|
|
645
|
-
*
|
|
646
|
-
* @category utility types
|
|
647
|
-
* @since 2.0.0
|
|
648
|
-
*/
|
|
649
289
|
const hole = cast(absurd);
|
|
650
290
|
function not(predicate) {
|
|
651
291
|
return (data) => !predicate(data);
|
|
652
292
|
}
|
|
653
|
-
/**
|
|
654
|
-
* Creates a predicate that returns `true` only if both predicates are `true`.
|
|
655
|
-
*
|
|
656
|
-
* **When to use**
|
|
657
|
-
*
|
|
658
|
-
* Use when you want to combine `Predicate`s with AND, accepting values that
|
|
659
|
-
* satisfy multiple conditions, including refinements that narrow to an
|
|
660
|
-
* intersection.
|
|
661
|
-
*
|
|
662
|
-
* **Details**
|
|
663
|
-
*
|
|
664
|
-
* Evaluation short-circuits on the first `false`. For refinements, the output
|
|
665
|
-
* type is an intersection.
|
|
666
|
-
*
|
|
667
|
-
* **Example** (Checking both conditions)
|
|
668
|
-
*
|
|
669
|
-
* ```ts
|
|
670
|
-
* import { Predicate } from "effect"
|
|
671
|
-
*
|
|
672
|
-
* const hasAAndB = Predicate.and(
|
|
673
|
-
* Predicate.hasProperty("a"),
|
|
674
|
-
* Predicate.hasProperty("b")
|
|
675
|
-
* )
|
|
676
|
-
*
|
|
677
|
-
* const input: unknown = JSON.parse(`{"a":1,"b":"ok"}`)
|
|
678
|
-
* if (hasAAndB(input)) {
|
|
679
|
-
* // input has both properties at this point
|
|
680
|
-
* const a = input.a
|
|
681
|
-
* const b = input.b
|
|
682
|
-
*
|
|
683
|
-
* const values = [a, b] // => [1, "ok"]
|
|
684
|
-
* }
|
|
685
|
-
* ```
|
|
686
|
-
*
|
|
687
|
-
* @see {@link or}
|
|
688
|
-
* @see {@link not}
|
|
689
|
-
* @category combinators
|
|
690
|
-
* @since 2.0.0
|
|
691
|
-
*/
|
|
692
293
|
const and = dual(2, (a, b) => (data) => a(data) && b(data));
|
|
693
|
-
/**
|
|
694
|
-
* Creates a predicate that returns `true` if either predicate is `true`.
|
|
695
|
-
*
|
|
696
|
-
* **When to use**
|
|
697
|
-
*
|
|
698
|
-
* Use when you want to combine `Predicate`s with OR, accepting values that
|
|
699
|
-
* satisfy at least one condition, including refinements that narrow to a union.
|
|
700
|
-
*
|
|
701
|
-
* **Details**
|
|
702
|
-
*
|
|
703
|
-
* Evaluation short-circuits on the first `true`. For refinements, the output
|
|
704
|
-
* type is a union.
|
|
705
|
-
*
|
|
706
|
-
* **Example** (Checking either condition)
|
|
707
|
-
*
|
|
708
|
-
* ```ts
|
|
709
|
-
* import { Predicate } from "effect"
|
|
710
|
-
*
|
|
711
|
-
* const isStringOrNumber = Predicate.or(Predicate.isString, Predicate.isNumber)
|
|
712
|
-
*
|
|
713
|
-
* isStringOrNumber("a") // => true
|
|
714
|
-
* ```
|
|
715
|
-
*
|
|
716
|
-
* @see {@link and}
|
|
717
|
-
* @see {@link xor}
|
|
718
|
-
* @category combinators
|
|
719
|
-
* @since 2.0.0
|
|
720
|
-
*/
|
|
721
294
|
const or = dual(2, (a, b) => (data) => a(data) || b(data));
|
|
722
|
-
/**
|
|
723
|
-
* Creates a predicate that returns `true` if exactly one predicate is `true`.
|
|
724
|
-
*
|
|
725
|
-
* **When to use**
|
|
726
|
-
*
|
|
727
|
-
* Use when you want to combine two `Predicate`s with exclusive-or semantics.
|
|
728
|
-
*
|
|
729
|
-
* **Details**
|
|
730
|
-
*
|
|
731
|
-
* Returns `true` when results differ.
|
|
732
|
-
*
|
|
733
|
-
* **Example** (Checking exclusive-or conditions)
|
|
734
|
-
*
|
|
735
|
-
* ```ts
|
|
736
|
-
* import { Predicate } from "effect"
|
|
737
|
-
*
|
|
738
|
-
* const isEven = (n: number) => n % 2 === 0
|
|
739
|
-
* const isPositive = (n: number) => n > 0
|
|
740
|
-
* const either = Predicate.xor(isEven, isPositive)
|
|
741
|
-
*
|
|
742
|
-
* either(-2) // => true
|
|
743
|
-
* ```
|
|
744
|
-
*
|
|
745
|
-
* @see {@link or}
|
|
746
|
-
* @see {@link and}
|
|
747
|
-
* @category combinators
|
|
748
|
-
* @since 2.0.0
|
|
749
|
-
*/
|
|
750
295
|
const xor = dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
751
|
-
/**
|
|
752
|
-
* Creates a predicate that returns `true` when both predicates agree.
|
|
753
|
-
*
|
|
754
|
-
* **When to use**
|
|
755
|
-
*
|
|
756
|
-
* Use when you want to check equivalence of two `Predicate`s.
|
|
757
|
-
*
|
|
758
|
-
* **Details**
|
|
759
|
-
*
|
|
760
|
-
* Returns `true` when both results are equal.
|
|
761
|
-
*
|
|
762
|
-
* **Example** (Defining equivalence)
|
|
763
|
-
*
|
|
764
|
-
* ```ts
|
|
765
|
-
* import { Predicate } from "effect"
|
|
766
|
-
*
|
|
767
|
-
* const isEven = (n: number) => n % 2 === 0
|
|
768
|
-
* const same = Predicate.eqv(isEven, isEven)
|
|
769
|
-
*
|
|
770
|
-
* same(3) // => true
|
|
771
|
-
* ```
|
|
772
|
-
*
|
|
773
|
-
* @see {@link xor}
|
|
774
|
-
* @category combinators
|
|
775
|
-
* @since 2.0.0
|
|
776
|
-
*/
|
|
777
296
|
const eqv = dual(2, (a, b) => (data) => a(data) === b(data));
|
|
778
|
-
/**
|
|
779
|
-
* Creates a predicate representing logical implication: if `antecedent`, then `consequent`.
|
|
780
|
-
*
|
|
781
|
-
* **When to use**
|
|
782
|
-
*
|
|
783
|
-
* Use when you need to encode logical implication between `Predicate` rules,
|
|
784
|
-
* where one rule only applies when a precondition holds.
|
|
785
|
-
*
|
|
786
|
-
* **Details**
|
|
787
|
-
*
|
|
788
|
-
* Models constraints like "if A then B" and returns `true` when the antecedent
|
|
789
|
-
* is `false`.
|
|
790
|
-
*
|
|
791
|
-
* **Example** (Checking implication)
|
|
792
|
-
*
|
|
793
|
-
* ```ts
|
|
794
|
-
* import { Predicate } from "effect"
|
|
795
|
-
*
|
|
796
|
-
* const isAdult = (age: number) => age >= 18
|
|
797
|
-
* const canVote = (age: number) => age >= 18
|
|
798
|
-
* const implies = Predicate.implies(isAdult, canVote)
|
|
799
|
-
*
|
|
800
|
-
* implies(16) // => true
|
|
801
|
-
* ```
|
|
802
|
-
*
|
|
803
|
-
* @see {@link and}
|
|
804
|
-
* @see {@link or}
|
|
805
|
-
* @category combinators
|
|
806
|
-
* @since 2.0.0
|
|
807
|
-
*/
|
|
808
297
|
const implies = dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
809
|
-
/**
|
|
810
|
-
* Creates a predicate that returns `true` when neither predicate is `true`.
|
|
811
|
-
*
|
|
812
|
-
* **When to use**
|
|
813
|
-
*
|
|
814
|
-
* Use when you want to combine two `Predicate`s with logical NOR semantics.
|
|
815
|
-
*
|
|
816
|
-
* **Details**
|
|
817
|
-
*
|
|
818
|
-
* Returns the negation of `or`.
|
|
819
|
-
*
|
|
820
|
-
* **Example** (Checking NOR conditions)
|
|
821
|
-
*
|
|
822
|
-
* ```ts
|
|
823
|
-
* import { Predicate } from "effect"
|
|
824
|
-
*
|
|
825
|
-
* const neither = Predicate.nor(Predicate.isString, Predicate.isNumber)
|
|
826
|
-
*
|
|
827
|
-
* neither(true) // => true
|
|
828
|
-
* ```
|
|
829
|
-
*
|
|
830
|
-
* @see {@link or}
|
|
831
|
-
* @see {@link not}
|
|
832
|
-
* @category combinators
|
|
833
|
-
* @since 2.0.0
|
|
834
|
-
*/
|
|
835
298
|
const nor = dual(2, (a, b) => (data) => !a(data) && !b(data));
|
|
836
|
-
/**
|
|
837
|
-
* Creates a predicate that returns `true` unless both predicates are `true`.
|
|
838
|
-
*
|
|
839
|
-
* **When to use**
|
|
840
|
-
*
|
|
841
|
-
* Use when you want to combine two `Predicate`s with logical NAND semantics.
|
|
842
|
-
*
|
|
843
|
-
* **Details**
|
|
844
|
-
*
|
|
845
|
-
* Returns the negation of `and`.
|
|
846
|
-
*
|
|
847
|
-
* **Example** (Checking NAND conditions)
|
|
848
|
-
*
|
|
849
|
-
* ```ts
|
|
850
|
-
* import { Predicate } from "effect"
|
|
851
|
-
*
|
|
852
|
-
* const notBoth = Predicate.nand(Predicate.isString, Predicate.isNumber)
|
|
853
|
-
*
|
|
854
|
-
* notBoth("a") // => true
|
|
855
|
-
* ```
|
|
856
|
-
*
|
|
857
|
-
* @see {@link and}
|
|
858
|
-
* @see {@link not}
|
|
859
|
-
* @category combinators
|
|
860
|
-
* @since 2.0.0
|
|
861
|
-
*/
|
|
862
299
|
const nand = dual(2, (a, b) => (data) => !a(data) || !b(data));
|
|
863
|
-
/**
|
|
864
|
-
* Checks whether a value is a `function`.
|
|
865
|
-
*
|
|
866
|
-
* **When to use**
|
|
867
|
-
*
|
|
868
|
-
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
869
|
-
* callable function.
|
|
870
|
-
*
|
|
871
|
-
* **Details**
|
|
872
|
-
*
|
|
873
|
-
* Uses `typeof input === "function"`.
|
|
874
|
-
*
|
|
875
|
-
* **Example** (Guarding functions)
|
|
876
|
-
*
|
|
877
|
-
* ```ts
|
|
878
|
-
* import { Predicate } from "effect"
|
|
879
|
-
*
|
|
880
|
-
* const data: unknown = () => 1
|
|
881
|
-
*
|
|
882
|
-
* if (Predicate.isFunction(data)) {
|
|
883
|
-
* data() // => 1
|
|
884
|
-
* }
|
|
885
|
-
* ```
|
|
886
|
-
*
|
|
887
|
-
* @see {@link isObjectKeyword}
|
|
888
|
-
* @category guards
|
|
889
|
-
* @since 2.0.0
|
|
890
|
-
*/
|
|
891
300
|
function isFunction(input) {
|
|
892
301
|
return typeof input === "function";
|
|
893
302
|
}
|
|
894
|
-
/**
|
|
895
|
-
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
896
|
-
*
|
|
897
|
-
* **When to use**
|
|
898
|
-
*
|
|
899
|
-
* Use when you need a `Predicate` guard that accepts arrays and functions as
|
|
900
|
-
* well as objects.
|
|
901
|
-
*
|
|
902
|
-
* **Details**
|
|
903
|
-
*
|
|
904
|
-
* Returns `true` for arrays and functions, and `false` for `null`.
|
|
905
|
-
*
|
|
906
|
-
* **Example** (Checking object keywords)
|
|
907
|
-
*
|
|
908
|
-
* ```ts
|
|
909
|
-
* import { Predicate } from "effect"
|
|
910
|
-
*
|
|
911
|
-
* Predicate.isObjectKeyword(() => 1) // => true
|
|
912
|
-
* Predicate.isObjectKeyword(null) // => false
|
|
913
|
-
* ```
|
|
914
|
-
*
|
|
915
|
-
* @see {@link isObject}
|
|
916
|
-
* @see {@link isObjectOrArray}
|
|
917
|
-
* @category guards
|
|
918
|
-
* @since 4.0.0
|
|
919
|
-
*/
|
|
920
303
|
function isObjectKeyword(input) {
|
|
921
304
|
return typeof input === "object" && input !== null || isFunction(input);
|
|
922
305
|
}
|
|
923
|
-
/**
|
|
924
|
-
* Checks whether a value has a given property key.
|
|
925
|
-
*
|
|
926
|
-
* **When to use**
|
|
927
|
-
*
|
|
928
|
-
* Use when you need a `Predicate` guard for property access on `unknown`
|
|
929
|
-
* values with a simple structural object check.
|
|
930
|
-
*
|
|
931
|
-
* **Details**
|
|
932
|
-
*
|
|
933
|
-
* Uses the `in` operator and `isObjectKeyword`. This does not check property
|
|
934
|
-
* value types.
|
|
935
|
-
*
|
|
936
|
-
* **Example** (Guarding object properties)
|
|
937
|
-
*
|
|
938
|
-
* ```ts
|
|
939
|
-
* import { Predicate } from "effect"
|
|
940
|
-
*
|
|
941
|
-
* const hasName = Predicate.hasProperty("name")
|
|
942
|
-
* const data: unknown = { name: "Ada" }
|
|
943
|
-
*
|
|
944
|
-
* if (hasName(data)) {
|
|
945
|
-
* data.name // => "Ada"
|
|
946
|
-
* }
|
|
947
|
-
* ```
|
|
948
|
-
*
|
|
949
|
-
* @see {@link isTagged}
|
|
950
|
-
* @see {@link isObjectKeyword}
|
|
951
|
-
* @category guards
|
|
952
|
-
* @since 2.0.0
|
|
953
|
-
*/
|
|
954
306
|
const hasProperty = dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
955
|
-
/**
|
|
956
|
-
* Drops elements from the start while the predicate holds, returning the rest.
|
|
957
|
-
*
|
|
958
|
-
* **When to use**
|
|
959
|
-
*
|
|
960
|
-
* Use to remove a leading prefix of elements that satisfy a predicate.
|
|
961
|
-
*
|
|
962
|
-
* **Details**
|
|
963
|
-
*
|
|
964
|
-
* The predicate receives `(element, index)`.
|
|
965
|
-
*
|
|
966
|
-
* **Example** (Dropping while condition holds)
|
|
967
|
-
*
|
|
968
|
-
* ```ts
|
|
969
|
-
* import { Array } from "effect"
|
|
970
|
-
*
|
|
971
|
-
* Array.dropWhile([1, 2, 3, 4, 5], (x) => x < 4) // => [4, 5]
|
|
972
|
-
* ```
|
|
973
|
-
*
|
|
974
|
-
* @see {@link takeWhile} — keep the matching prefix instead
|
|
975
|
-
* @see {@link drop} — drop a fixed count
|
|
976
|
-
*
|
|
977
|
-
* @category getters
|
|
978
|
-
* @since 2.0.0
|
|
979
|
-
*/
|
|
980
307
|
const dropWhile = dual(2, (self, predicate) => {
|
|
981
308
|
const input = Array.isArray(self) ? self : Array.from(self);
|
|
982
309
|
const len = input.length;
|
|
@@ -984,35 +311,6 @@ const dropWhile = dual(2, (self, predicate) => {
|
|
|
984
311
|
while (idx < len && predicate(input[idx], idx)) idx++;
|
|
985
312
|
return input.slice(idx);
|
|
986
313
|
});
|
|
987
|
-
/**
|
|
988
|
-
* Takes elements from the start while the predicate holds, stopping at the
|
|
989
|
-
* first element that fails.
|
|
990
|
-
*
|
|
991
|
-
* **When to use**
|
|
992
|
-
*
|
|
993
|
-
* Use to keep the leading elements of an iterable while each element satisfies
|
|
994
|
-
* a predicate, returning the retained prefix as an array.
|
|
995
|
-
*
|
|
996
|
-
* **Details**
|
|
997
|
-
*
|
|
998
|
-
* Supports refinements for type narrowing. The predicate receives
|
|
999
|
-
* `(element, index)`.
|
|
1000
|
-
*
|
|
1001
|
-
* **Example** (Taking while condition holds)
|
|
1002
|
-
*
|
|
1003
|
-
* ```ts
|
|
1004
|
-
* import { Array } from "effect"
|
|
1005
|
-
*
|
|
1006
|
-
* Array.takeWhile([1, 3, 2, 4, 1, 2], (x) => x < 4) // => [1, 3, 2]
|
|
1007
|
-
* ```
|
|
1008
|
-
*
|
|
1009
|
-
* @see {@link take} for keeping a fixed number of leading elements
|
|
1010
|
-
* @see {@link dropWhile} for removing the matching prefix and keeping the rest
|
|
1011
|
-
* @see {@link span} for splitting the matching prefix from the remaining elements
|
|
1012
|
-
*
|
|
1013
|
-
* @category getters
|
|
1014
|
-
* @since 2.0.0
|
|
1015
|
-
*/
|
|
1016
314
|
const takeWhile = dual(2, (self, predicate) => {
|
|
1017
315
|
const input = Array.isArray(self) ? self : Array.from(self);
|
|
1018
316
|
const len = input.length;
|
|
@@ -1097,11 +395,6 @@ function create$3(context) {
|
|
|
1097
395
|
JSXFragment: visit
|
|
1098
396
|
};
|
|
1099
397
|
}
|
|
1100
|
-
/**
|
|
1101
|
-
* Whether a JSX child carries no renderable content: padding whitespace, an
|
|
1102
|
-
* empty expression (ex: `{}` or a comment), or an empty string expression.
|
|
1103
|
-
* @param child The JSX child node to check.
|
|
1104
|
-
*/
|
|
1105
398
|
const isWhitespaceOrEmptyStringExpression = or(isWhitespaceText, isEmptyStringExpression);
|
|
1106
399
|
function isNonSubstantiveChild(child) {
|
|
1107
400
|
if (isWhitespaceOrEmptyStringExpression(child)) return true;
|
|
@@ -1220,16 +513,6 @@ function create(context, [option]) {
|
|
|
1220
513
|
}
|
|
1221
514
|
};
|
|
1222
515
|
}
|
|
1223
|
-
/**
|
|
1224
|
-
* Inspect a fragment node and report if it is useless.
|
|
1225
|
-
*
|
|
1226
|
-
* A fragment may be reported for **two independent reasons** on the same
|
|
1227
|
-
* node (e.g. `<p><>foo</></p>` is both "placed inside a host component"
|
|
1228
|
-
* and "contains less than two children").
|
|
1229
|
-
* @param context The rule context.
|
|
1230
|
-
* @param node The fragment node to inspect.
|
|
1231
|
-
* @param options The resolved rule options.
|
|
1232
|
-
*/
|
|
1233
516
|
function visitFragment(context, node, options) {
|
|
1234
517
|
const reasons = [];
|
|
1235
518
|
if (isHostElement(node.parent)) reasons.push("placed inside a host component");
|
|
@@ -1243,12 +526,6 @@ function visitFragment(context, node, options) {
|
|
|
1243
526
|
node
|
|
1244
527
|
});
|
|
1245
528
|
}
|
|
1246
|
-
/**
|
|
1247
|
-
* Whether the fragment has too few meaningful children to justify its
|
|
1248
|
-
* existence (the "contains less than two children" reason).
|
|
1249
|
-
* @param node The fragment node to check.
|
|
1250
|
-
* @param options The resolved rule options.
|
|
1251
|
-
*/
|
|
1252
529
|
function isContentUseless(node, options) {
|
|
1253
530
|
const { allowEmptyFragment, allowExpressions } = options;
|
|
1254
531
|
if (node.children.length === 0) return !allowEmptyFragment;
|
|
@@ -1260,10 +537,6 @@ function isContentUseless(node, options) {
|
|
|
1260
537
|
if (meaningful[0]?.type === AST_NODE_TYPES.JSXExpressionContainer) return !allowExpressions;
|
|
1261
538
|
return true;
|
|
1262
539
|
}
|
|
1263
|
-
/**
|
|
1264
|
-
* Whether it is safe to auto-fix the fragment by unwrapping it.
|
|
1265
|
-
* @param node The fragment node to check.
|
|
1266
|
-
*/
|
|
1267
540
|
function isSafeToFix(node) {
|
|
1268
541
|
if (node.type === AST_NODE_TYPES.JSXElement && node.openingElement.attributes.some((attr) => attr.type === AST_NODE_TYPES.JSXSpreadAttribute)) return false;
|
|
1269
542
|
if (Check.isJSXElementOrFragment(node.parent)) return isHostElement(node.parent);
|
|
@@ -1273,12 +546,6 @@ function isSafeToFix(node) {
|
|
|
1273
546
|
return child.type === AST_NODE_TYPES.JSXText && isWhitespaceText(child);
|
|
1274
547
|
});
|
|
1275
548
|
}
|
|
1276
|
-
/**
|
|
1277
|
-
* Build an autofix that unwraps the fragment, replacing it with its
|
|
1278
|
-
* meaningful children content. Returns `null` when the fix is unsafe.
|
|
1279
|
-
* @param context The rule context.
|
|
1280
|
-
* @param node The fragment node to fix.
|
|
1281
|
-
*/
|
|
1282
549
|
function buildFix(context, node) {
|
|
1283
550
|
if (!isSafeToFix(node)) return null;
|
|
1284
551
|
return (fixer) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-jsx",
|
|
3
|
-
"version": "5.24.
|
|
3
|
+
"version": "5.24.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@eslint-react/ast": "5.24.
|
|
41
|
-
"@eslint-react/core": "5.24.
|
|
42
|
-
"@eslint-react/eslint": "5.24.
|
|
43
|
-
"@eslint-react/jsx": "5.24.
|
|
44
|
-
"@eslint-react/shared": "5.24.
|
|
40
|
+
"@eslint-react/ast": "5.24.3",
|
|
41
|
+
"@eslint-react/core": "5.24.3",
|
|
42
|
+
"@eslint-react/eslint": "5.24.3",
|
|
43
|
+
"@eslint-react/jsx": "5.24.3",
|
|
44
|
+
"@eslint-react/shared": "5.24.3",
|
|
45
45
|
"@typescript-eslint/types": "^8.71.0",
|
|
46
46
|
"@typescript-eslint/utils": "^8.71.0"
|
|
47
47
|
},
|