@eslint-react/shared 2.0.0-next.0 → 2.0.0-next.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.mts DELETED
@@ -1,1078 +0,0 @@
1
- import { _ } from '@eslint-react/eff';
2
- import { RuleContext } from '@eslint-react/kit';
3
- import * as z from '@zod/mini';
4
-
5
- /**
6
- * The NPM scope for this project.
7
- */
8
- declare const NPM_SCOPE = "@eslint-react";
9
- /**
10
- * The GitHub repository for this project.
11
- */
12
- declare const GITHUB_URL = "https://github.com/Rel1cx/eslint-react";
13
- /**
14
- * The URL to the project's website.
15
- */
16
- declare const WEBSITE_URL = "https://eslint-react.xyz";
17
-
18
- /**
19
- * Get the URL for the documentation of a rule in a plugin.
20
- * @internal
21
- * @param pluginName The name of the plugin.
22
- * @returns The URL for the documentation of a rule.
23
- */
24
- declare const getDocsUrl: (pluginName: string) => (ruleName: string) => string;
25
-
26
- declare const getId: () => string;
27
-
28
- declare function getReactVersion(fallback: string): string;
29
-
30
- /**
31
- Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
32
-
33
- @category Type
34
- */
35
- type Primitive =
36
- | null
37
- | undefined
38
- | string
39
- | number
40
- | boolean
41
- | symbol
42
- | bigint;
43
-
44
- declare global {
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
46
- interface SymbolConstructor {
47
- readonly observable: symbol;
48
- }
49
- }
50
-
51
- /**
52
- Extract all optional keys from the given type.
53
-
54
- This is useful when you want to create a new type that contains different type values for the optional keys only.
55
-
56
- @example
57
- ```
58
- import type {OptionalKeysOf, Except} from 'type-fest';
59
-
60
- interface User {
61
- name: string;
62
- surname: string;
63
-
64
- luckyNumber?: number;
65
- }
66
-
67
- const REMOVE_FIELD = Symbol('remove field symbol');
68
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
69
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
70
- };
71
-
72
- const update1: UpdateOperation<User> = {
73
- name: 'Alice'
74
- };
75
-
76
- const update2: UpdateOperation<User> = {
77
- name: 'Bob',
78
- luckyNumber: REMOVE_FIELD
79
- };
80
- ```
81
-
82
- @category Utilities
83
- */
84
- type OptionalKeysOf<BaseType extends object> =
85
- BaseType extends unknown // For distributing `BaseType`
86
- ? (keyof {
87
- [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
88
- }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
89
- : never; // Should never happen
90
-
91
- /**
92
- Extract all required keys from the given type.
93
-
94
- This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
95
-
96
- @example
97
- ```
98
- import type {RequiredKeysOf} from 'type-fest';
99
-
100
- declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
101
-
102
- interface User {
103
- name: string;
104
- surname: string;
105
-
106
- luckyNumber?: number;
107
- }
108
-
109
- const validator1 = createValidation<User>('name', value => value.length < 25);
110
- const validator2 = createValidation<User>('surname', value => value.length < 25);
111
- ```
112
-
113
- @category Utilities
114
- */
115
- type RequiredKeysOf<BaseType extends object> =
116
- BaseType extends unknown // For distributing `BaseType`
117
- ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
118
- : never; // Should never happen
119
-
120
- /**
121
- Returns a boolean for whether the given type is `never`.
122
-
123
- @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
124
- @link https://stackoverflow.com/a/53984913/10292952
125
- @link https://www.zhenghao.io/posts/ts-never
126
-
127
- Useful in type utilities, such as checking if something does not occur.
128
-
129
- @example
130
- ```
131
- import type {IsNever, And} from 'type-fest';
132
-
133
- // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
134
- type AreStringsEqual<A extends string, B extends string> =
135
- And<
136
- IsNever<Exclude<A, B>> extends true ? true : false,
137
- IsNever<Exclude<B, A>> extends true ? true : false
138
- >;
139
-
140
- type EndIfEqual<I extends string, O extends string> =
141
- AreStringsEqual<I, O> extends true
142
- ? never
143
- : void;
144
-
145
- function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
146
- if (input === output) {
147
- process.exit(0);
148
- }
149
- }
150
-
151
- endIfEqual('abc', 'abc');
152
- //=> never
153
-
154
- endIfEqual('abc', '123');
155
- //=> void
156
- ```
157
-
158
- @category Type Guard
159
- @category Utilities
160
- */
161
- type IsNever<T> = [T] extends [never] ? true : false;
162
-
163
- /**
164
- An if-else-like type that resolves depending on whether the given type is `never`.
165
-
166
- @see {@link IsNever}
167
-
168
- @example
169
- ```
170
- import type {IfNever} from 'type-fest';
171
-
172
- type ShouldBeTrue = IfNever<never>;
173
- //=> true
174
-
175
- type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
176
- //=> 'bar'
177
- ```
178
-
179
- @category Type Guard
180
- @category Utilities
181
- */
182
- type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
183
- IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
184
- );
185
-
186
- // Can eventually be replaced with the built-in once this library supports
187
- // TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
188
- type NoInfer<T> = T extends infer U ? U : never;
189
-
190
- /**
191
- Returns a boolean for whether the given type is `any`.
192
-
193
- @link https://stackoverflow.com/a/49928360/1490091
194
-
195
- Useful in type utilities, such as disallowing `any`s to be passed to a function.
196
-
197
- @example
198
- ```
199
- import type {IsAny} from 'type-fest';
200
-
201
- const typedObject = {a: 1, b: 2} as const;
202
- const anyObject: any = {a: 1, b: 2};
203
-
204
- function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
205
- return obj[key];
206
- }
207
-
208
- const typedA = get(typedObject, 'a');
209
- //=> 1
210
-
211
- const anyA = get(anyObject, 'a');
212
- //=> any
213
- ```
214
-
215
- @category Type Guard
216
- @category Utilities
217
- */
218
- type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
219
-
220
- /**
221
- Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
222
-
223
- @example
224
- ```
225
- import type {Simplify} from 'type-fest';
226
-
227
- type PositionProps = {
228
- top: number;
229
- left: number;
230
- };
231
-
232
- type SizeProps = {
233
- width: number;
234
- height: number;
235
- };
236
-
237
- // In your editor, hovering over `Props` will show a flattened object with all the properties.
238
- type Props = Simplify<PositionProps & SizeProps>;
239
- ```
240
-
241
- Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
242
-
243
- If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
244
-
245
- @example
246
- ```
247
- import type {Simplify} from 'type-fest';
248
-
249
- interface SomeInterface {
250
- foo: number;
251
- bar?: string;
252
- baz: number | undefined;
253
- }
254
-
255
- type SomeType = {
256
- foo: number;
257
- bar?: string;
258
- baz: number | undefined;
259
- };
260
-
261
- const literal = {foo: 123, bar: 'hello', baz: 456};
262
- const someType: SomeType = literal;
263
- const someInterface: SomeInterface = literal;
264
-
265
- function fn(object: Record<string, unknown>): void {}
266
-
267
- fn(literal); // Good: literal object type is sealed
268
- fn(someType); // Good: type is sealed
269
- fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
270
- fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
271
- ```
272
-
273
- @link https://github.com/microsoft/TypeScript/issues/15300
274
- @see SimplifyDeep
275
- @category Object
276
- */
277
- type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
278
-
279
- /**
280
- Omit any index signatures from the given object type, leaving only explicitly defined properties.
281
-
282
- This is the counterpart of `PickIndexSignature`.
283
-
284
- Use-cases:
285
- - Remove overly permissive signatures from third-party types.
286
-
287
- This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
288
-
289
- It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
290
-
291
- (The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
292
-
293
- ```
294
- const indexed: Record<string, unknown> = {}; // Allowed
295
-
296
- const keyed: Record<'foo', unknown> = {}; // Error
297
- // => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
298
- ```
299
-
300
- Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
301
-
302
- ```
303
- type Indexed = {} extends Record<string, unknown>
304
- ? '✅ `{}` is assignable to `Record<string, unknown>`'
305
- : '❌ `{}` is NOT assignable to `Record<string, unknown>`';
306
- // => '✅ `{}` is assignable to `Record<string, unknown>`'
307
-
308
- type Keyed = {} extends Record<'foo' | 'bar', unknown>
309
- ? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
310
- : "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
311
- // => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
312
- ```
313
-
314
- Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
315
-
316
- ```
317
- import type {OmitIndexSignature} from 'type-fest';
318
-
319
- type OmitIndexSignature<ObjectType> = {
320
- [KeyType in keyof ObjectType // Map each key of `ObjectType`...
321
- ]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
322
- };
323
- ```
324
-
325
- ...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
326
-
327
- ```
328
- import type {OmitIndexSignature} from 'type-fest';
329
-
330
- type OmitIndexSignature<ObjectType> = {
331
- [KeyType in keyof ObjectType
332
- // Is `{}` assignable to `Record<KeyType, unknown>`?
333
- as {} extends Record<KeyType, unknown>
334
- ? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
335
- : ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
336
- ]: ObjectType[KeyType];
337
- };
338
- ```
339
-
340
- If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
341
-
342
- @example
343
- ```
344
- import type {OmitIndexSignature} from 'type-fest';
345
-
346
- interface Example {
347
- // These index signatures will be removed.
348
- [x: string]: any
349
- [x: number]: any
350
- [x: symbol]: any
351
- [x: `head-${string}`]: string
352
- [x: `${string}-tail`]: string
353
- [x: `head-${string}-tail`]: string
354
- [x: `${bigint}`]: string
355
- [x: `embedded-${number}`]: string
356
-
357
- // These explicitly defined keys will remain.
358
- foo: 'bar';
359
- qux?: 'baz';
360
- }
361
-
362
- type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
363
- // => { foo: 'bar'; qux?: 'baz' | undefined; }
364
- ```
365
-
366
- @see PickIndexSignature
367
- @category Object
368
- */
369
- type OmitIndexSignature<ObjectType> = {
370
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
371
- ? never
372
- : KeyType]: ObjectType[KeyType];
373
- };
374
-
375
- /**
376
- Pick only index signatures from the given object type, leaving out all explicitly defined properties.
377
-
378
- This is the counterpart of `OmitIndexSignature`.
379
-
380
- @example
381
- ```
382
- import type {PickIndexSignature} from 'type-fest';
383
-
384
- declare const symbolKey: unique symbol;
385
-
386
- type Example = {
387
- // These index signatures will remain.
388
- [x: string]: unknown;
389
- [x: number]: unknown;
390
- [x: symbol]: unknown;
391
- [x: `head-${string}`]: string;
392
- [x: `${string}-tail`]: string;
393
- [x: `head-${string}-tail`]: string;
394
- [x: `${bigint}`]: string;
395
- [x: `embedded-${number}`]: string;
396
-
397
- // These explicitly defined keys will be removed.
398
- ['kebab-case-key']: string;
399
- [symbolKey]: string;
400
- foo: 'bar';
401
- qux?: 'baz';
402
- };
403
-
404
- type ExampleIndexSignature = PickIndexSignature<Example>;
405
- // {
406
- // [x: string]: unknown;
407
- // [x: number]: unknown;
408
- // [x: symbol]: unknown;
409
- // [x: `head-${string}`]: string;
410
- // [x: `${string}-tail`]: string;
411
- // [x: `head-${string}-tail`]: string;
412
- // [x: `${bigint}`]: string;
413
- // [x: `embedded-${number}`]: string;
414
- // }
415
- ```
416
-
417
- @see OmitIndexSignature
418
- @category Object
419
- */
420
- type PickIndexSignature<ObjectType> = {
421
- [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
422
- ? KeyType
423
- : never]: ObjectType[KeyType];
424
- };
425
-
426
- // Merges two objects without worrying about index signatures.
427
- type SimpleMerge<Destination, Source> = {
428
- [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
429
- } & Source;
430
-
431
- /**
432
- Merge two types into a new type. Keys of the second type overrides keys of the first type.
433
-
434
- @example
435
- ```
436
- import type {Merge} from 'type-fest';
437
-
438
- interface Foo {
439
- [x: string]: unknown;
440
- [x: number]: unknown;
441
- foo: string;
442
- bar: symbol;
443
- }
444
-
445
- type Bar = {
446
- [x: number]: number;
447
- [x: symbol]: unknown;
448
- bar: Date;
449
- baz: boolean;
450
- };
451
-
452
- export type FooBar = Merge<Foo, Bar>;
453
- // => {
454
- // [x: string]: unknown;
455
- // [x: number]: number;
456
- // [x: symbol]: unknown;
457
- // foo: string;
458
- // bar: Date;
459
- // baz: boolean;
460
- // }
461
- ```
462
-
463
- @category Object
464
- */
465
- type Merge<Destination, Source> =
466
- Simplify<
467
- SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
468
- & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
469
- >;
470
-
471
- /**
472
- An if-else-like type that resolves depending on whether the given type is `any`.
473
-
474
- @see {@link IsAny}
475
-
476
- @example
477
- ```
478
- import type {IfAny} from 'type-fest';
479
-
480
- type ShouldBeTrue = IfAny<any>;
481
- //=> true
482
-
483
- type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
484
- //=> 'bar'
485
- ```
486
-
487
- @category Type Guard
488
- @category Utilities
489
- */
490
- type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
491
- IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
492
- );
493
-
494
- /**
495
- Matches any primitive, `void`, `Date`, or `RegExp` value.
496
- */
497
- type BuiltIns = Primitive | void | Date | RegExp;
498
-
499
- /**
500
- Merges user specified options with default options.
501
-
502
- @example
503
- ```
504
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
505
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
506
- type SpecifiedOptions = {leavesOnly: true};
507
-
508
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
509
- //=> {maxRecursionDepth: 10; leavesOnly: true}
510
- ```
511
-
512
- @example
513
- ```
514
- // Complains if default values are not provided for optional options
515
-
516
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
517
- type DefaultPathsOptions = {maxRecursionDepth: 10};
518
- type SpecifiedOptions = {};
519
-
520
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
521
- // ~~~~~~~~~~~~~~~~~~~
522
- // Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
523
- ```
524
-
525
- @example
526
- ```
527
- // Complains if an option's default type does not conform to the expected type
528
-
529
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
530
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
531
- type SpecifiedOptions = {};
532
-
533
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
534
- // ~~~~~~~~~~~~~~~~~~~
535
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
536
- ```
537
-
538
- @example
539
- ```
540
- // Complains if an option's specified type does not conform to the expected type
541
-
542
- type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
543
- type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
544
- type SpecifiedOptions = {leavesOnly: 'yes'};
545
-
546
- type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
547
- // ~~~~~~~~~~~~~~~~
548
- // Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
549
- ```
550
- */
551
- type ApplyDefaultOptions<
552
- Options extends object,
553
- Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
554
- SpecifiedOptions extends Options,
555
- > =
556
- IfAny<SpecifiedOptions, Defaults,
557
- IfNever<SpecifiedOptions, Defaults,
558
- Simplify<Merge<Defaults, {
559
- [Key in keyof SpecifiedOptions
560
- as Key extends OptionalKeysOf<Options>
561
- ? Extract<SpecifiedOptions[Key], undefined> extends never
562
- ? Key
563
- : never
564
- : Key
565
- ]: SpecifiedOptions[Key]
566
- }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
567
- >>;
568
-
569
- /**
570
- @see {@link PartialDeep}
571
- */
572
- type PartialDeepOptions = {
573
- /**
574
- Whether to affect the individual elements of arrays and tuples.
575
-
576
- @default false
577
- */
578
- readonly recurseIntoArrays?: boolean;
579
-
580
- /**
581
- Allows `undefined` values in non-tuple arrays.
582
-
583
- - When set to `true`, elements of non-tuple arrays can be `undefined`.
584
- - When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
585
-
586
- @default true
587
-
588
- @example
589
- You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
590
-
591
- ```
592
- import type {PartialDeep} from 'type-fest';
593
-
594
- type Settings = {
595
- languages: string[];
596
- };
597
-
598
- declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
599
-
600
- partialSettings.languages = [undefined]; // Error
601
- partialSettings.languages = []; // Ok
602
- ```
603
- */
604
- readonly allowUndefinedInNonTupleArrays?: boolean;
605
- };
606
-
607
- type DefaultPartialDeepOptions = {
608
- recurseIntoArrays: false;
609
- allowUndefinedInNonTupleArrays: true;
610
- };
611
-
612
- /**
613
- Create a type from another type with all keys and nested keys set to optional.
614
-
615
- Use-cases:
616
- - Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
617
- - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
618
-
619
- @example
620
- ```
621
- import type {PartialDeep} from 'type-fest';
622
-
623
- const settings: Settings = {
624
- textEditor: {
625
- fontSize: 14,
626
- fontColor: '#000000',
627
- fontWeight: 400
628
- },
629
- autocomplete: false,
630
- autosave: true
631
- };
632
-
633
- const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
634
- return {...settings, ...savedSettings};
635
- }
636
-
637
- settings = applySavedSettings({textEditor: {fontWeight: 500}});
638
- ```
639
-
640
- By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
641
-
642
- ```
643
- import type {PartialDeep} from 'type-fest';
644
-
645
- type Settings = {
646
- languages: string[];
647
- }
648
-
649
- const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
650
- languages: [undefined]
651
- };
652
- ```
653
-
654
- @see {@link PartialDeepOptions}
655
-
656
- @category Object
657
- @category Array
658
- @category Set
659
- @category Map
660
- */
661
- type PartialDeep<T, Options extends PartialDeepOptions = {}> =
662
- _PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
663
-
664
- type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | (((...arguments_: any[]) => unknown)) | (new (...arguments_: any[]) => unknown)
665
- ? T
666
- : T extends Map<infer KeyType, infer ValueType>
667
- ? PartialMapDeep<KeyType, ValueType, Options>
668
- : T extends Set<infer ItemType>
669
- ? PartialSetDeep<ItemType, Options>
670
- : T extends ReadonlyMap<infer KeyType, infer ValueType>
671
- ? PartialReadonlyMapDeep<KeyType, ValueType, Options>
672
- : T extends ReadonlySet<infer ItemType>
673
- ? PartialReadonlySetDeep<ItemType, Options>
674
- : T extends object
675
- ? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
676
- ? Options['recurseIntoArrays'] extends true
677
- ? ItemType[] extends T // Test for arrays (non-tuples) specifically
678
- ? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
679
- ? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
680
- : Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
681
- : PartialObjectDeep<T, Options> // Tuples behave properly
682
- : T // If they don't opt into array testing, just use the original type
683
- : PartialObjectDeep<T, Options>
684
- : unknown;
685
-
686
- /**
687
- Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
688
- */
689
- type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
690
-
691
- /**
692
- Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
693
- */
694
- type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
695
-
696
- /**
697
- Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
698
- */
699
- type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
700
-
701
- /**
702
- Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
703
- */
704
- type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
705
-
706
- /**
707
- Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
708
- */
709
- type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> = {
710
- [KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
711
- };
712
-
713
- declare const CustomComponentPropSchema: z.ZodMiniObject<{
714
- /**
715
- * The name of the prop in the user-defined component.
716
- * @example
717
- * "to"
718
- */
719
- name: z.ZodMiniString<string>;
720
- /**
721
- * The name of the prop in the host component.
722
- * @example
723
- * "href"
724
- */
725
- as: z.ZodMiniOptional<z.ZodMiniString<string>>;
726
- /**
727
- * Whether the prop is controlled or not in the user-defined component.
728
- * @internal
729
- * @example
730
- * `true`
731
- */
732
- controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
733
- /**
734
- * The default value of the prop in the user-defined component.
735
- * @example
736
- * `"/"`
737
- */
738
- defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
739
- }, {}>;
740
- /**
741
- * @description
742
- * This will provide some key information to the rule before checking for user-defined components.
743
- * For example:
744
- * Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
745
- */
746
- declare const CustomComponentSchema: z.ZodMiniObject<{
747
- /**
748
- * The name of the user-defined component.
749
- * @example
750
- * "Link"
751
- */
752
- name: z.ZodMiniString<string>;
753
- /**
754
- * The name of the host component that the user-defined component represents.
755
- * @example
756
- * "a"
757
- */
758
- as: z.ZodMiniOptional<z.ZodMiniString<string>>;
759
- /**
760
- * Attributes mapping between the user-defined component and the host component.
761
- * @example
762
- * `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
763
- */
764
- attributes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
765
- /**
766
- * The name of the prop in the user-defined component.
767
- * @example
768
- * "to"
769
- */
770
- name: z.ZodMiniString<string>;
771
- /**
772
- * The name of the prop in the host component.
773
- * @example
774
- * "href"
775
- */
776
- as: z.ZodMiniOptional<z.ZodMiniString<string>>;
777
- /**
778
- * Whether the prop is controlled or not in the user-defined component.
779
- * @internal
780
- * @example
781
- * `true`
782
- */
783
- controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
784
- /**
785
- * The default value of the prop in the user-defined component.
786
- * @example
787
- * `"/"`
788
- */
789
- defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
790
- }, {}>>>;
791
- /**
792
- * The ESQuery selector to select the component precisely.
793
- * @internal
794
- * @example
795
- * `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
796
- */
797
- selector: z.ZodMiniOptional<z.ZodMiniString<string>>;
798
- }, {}>;
799
- declare const CustomHooksSchema: z.ZodMiniObject<{
800
- use: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
801
- useActionState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
802
- useCallback: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
803
- useContext: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
804
- useDebugValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
805
- useDeferredValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
806
- useEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
807
- useFormStatus: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
808
- useId: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
809
- useImperativeHandle: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
810
- useInsertionEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
811
- useLayoutEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
812
- useMemo: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
813
- useOptimistic: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
814
- useReducer: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
815
- useRef: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
816
- useState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
817
- useSyncExternalStore: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
818
- useTransition: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
819
- }, {}>;
820
- /**
821
- * @internal
822
- */
823
- declare const ESLintReactSettingsSchema: z.ZodMiniObject<{
824
- /**
825
- * The source where React is imported from.
826
- * @description This allows to specify a custom import location for React when not using the official distribution.
827
- * @default `"react"`
828
- * @example `"@pika/react"`
829
- */
830
- importSource: z.ZodMiniOptional<z.ZodMiniString<string>>;
831
- /**
832
- * The identifier that's used for JSX Element creation.
833
- * @default `"createElement"`
834
- * @deprecated
835
- */
836
- jsxPragma: z.ZodMiniOptional<z.ZodMiniString<string>>;
837
- /**
838
- * The identifier that's used for JSX fragment elements.
839
- * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
840
- * @default `"Fragment"`
841
- * @deprecated
842
- */
843
- jsxPragmaFrag: z.ZodMiniOptional<z.ZodMiniString<string>>;
844
- /**
845
- * The name of the prop that is used for polymorphic components.
846
- * @description This is used to determine the type of the component.
847
- * @example `"as"`
848
- */
849
- polymorphicPropName: z.ZodMiniOptional<z.ZodMiniString<string>>;
850
- /**
851
- * @default `true`
852
- * @internal
853
- */
854
- strict: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
855
- /**
856
- * Check both the shape and the import to determine if an API is from React.
857
- * @default `true`
858
- * @internal
859
- */
860
- skipImportCheck: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
861
- /**
862
- * React version to use, "detect" means auto detect React version from the project's dependencies.
863
- * If `importSource` is specified, an equivalent version of React should be provided here.
864
- * @example `"18.3.1"`
865
- * @default `"detect"`
866
- */
867
- version: z.ZodMiniOptional<z.ZodMiniString<string>>;
868
- /**
869
- * A object to define additional hooks that are equivalent to the built-in React Hooks.
870
- * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
871
- * @example `{ useEffect: ["useIsomorphicLayoutEffect"] }`
872
- */
873
- additionalHooks: z.ZodMiniOptional<z.ZodMiniObject<{
874
- use: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
875
- useActionState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
876
- useCallback: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
877
- useContext: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
878
- useDebugValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
879
- useDeferredValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
880
- useEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
881
- useFormStatus: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
882
- useId: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
883
- useImperativeHandle: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
884
- useInsertionEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
885
- useLayoutEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
886
- useMemo: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
887
- useOptimistic: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
888
- useReducer: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
889
- useRef: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
890
- useState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
891
- useSyncExternalStore: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
892
- useTransition: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
893
- }, {}>>;
894
- /**
895
- * An array of user-defined components
896
- * @description This is used to inform the ESLint React plugins how to treat these components during checks.
897
- * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
898
- */
899
- additionalComponents: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
900
- /**
901
- * The name of the user-defined component.
902
- * @example
903
- * "Link"
904
- */
905
- name: z.ZodMiniString<string>;
906
- /**
907
- * The name of the host component that the user-defined component represents.
908
- * @example
909
- * "a"
910
- */
911
- as: z.ZodMiniOptional<z.ZodMiniString<string>>;
912
- /**
913
- * Attributes mapping between the user-defined component and the host component.
914
- * @example
915
- * `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
916
- */
917
- attributes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
918
- /**
919
- * The name of the prop in the user-defined component.
920
- * @example
921
- * "to"
922
- */
923
- name: z.ZodMiniString<string>;
924
- /**
925
- * The name of the prop in the host component.
926
- * @example
927
- * "href"
928
- */
929
- as: z.ZodMiniOptional<z.ZodMiniString<string>>;
930
- /**
931
- * Whether the prop is controlled or not in the user-defined component.
932
- * @internal
933
- * @example
934
- * `true`
935
- */
936
- controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
937
- /**
938
- * The default value of the prop in the user-defined component.
939
- * @example
940
- * `"/"`
941
- */
942
- defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
943
- }, {}>>>;
944
- /**
945
- * The ESQuery selector to select the component precisely.
946
- * @internal
947
- * @example
948
- * `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
949
- */
950
- selector: z.ZodMiniOptional<z.ZodMiniString<string>>;
951
- }, {}>>>;
952
- }, {}>;
953
- /**
954
- * @internal
955
- */
956
- declare const ESLintSettingsSchema: z.ZodMiniOptional<z.ZodMiniObject<{
957
- "react-x": z.ZodMiniOptional<z.ZodMiniUnknown>;
958
- }, {}>>;
959
- type CustomComponent = z.infer<typeof CustomComponentSchema>;
960
- type CustomComponentProp = z.infer<typeof CustomComponentPropSchema>;
961
- type CustomHooks = z.infer<typeof CustomHooksSchema>;
962
- type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
963
- type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
964
- declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
965
- declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
966
- /**
967
- * The default ESLint settings for "react-x".
968
- */
969
- declare const DEFAULT_ESLINT_REACT_SETTINGS: {
970
- readonly version: "detect";
971
- readonly importSource: "react";
972
- readonly strict: true;
973
- readonly skipImportCheck: true;
974
- readonly polymorphicPropName: "as";
975
- readonly additionalComponents: [];
976
- readonly additionalHooks: {
977
- readonly useEffect: ["useIsomorphicLayoutEffect"];
978
- readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
979
- };
980
- };
981
- declare const DEFAULT_ESLINT_SETTINGS: {
982
- readonly "react-x": {
983
- readonly version: "detect";
984
- readonly importSource: "react";
985
- readonly strict: true;
986
- readonly skipImportCheck: true;
987
- readonly polymorphicPropName: "as";
988
- readonly additionalComponents: [];
989
- readonly additionalHooks: {
990
- readonly useEffect: ["useIsomorphicLayoutEffect"];
991
- readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
992
- };
993
- };
994
- };
995
- interface CustomComponentPropNormalized {
996
- name: string;
997
- as: string;
998
- defaultValue?: string | _;
999
- }
1000
- interface CustomComponentNormalized {
1001
- name: string;
1002
- as: string;
1003
- attributes: CustomComponentPropNormalized[];
1004
- re: {
1005
- test(s: string): boolean;
1006
- };
1007
- }
1008
- interface ESLintReactSettingsNormalized {
1009
- additionalHooks: CustomHooks;
1010
- components: CustomComponentNormalized[];
1011
- importSource: string;
1012
- polymorphicPropName: string | _;
1013
- skipImportCheck: boolean;
1014
- strict: boolean;
1015
- version: string;
1016
- }
1017
- declare const coerceESLintSettings: (settings: unknown) => PartialDeep<ESLintSettings>;
1018
- declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
1019
- declare const coerceSettings: (settings: unknown) => PartialDeep<ESLintReactSettings>;
1020
- declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
1021
- declare const normalizeSettings: ({ additionalComponents, additionalHooks, importSource, polymorphicPropName, skipImportCheck, strict, version, ...rest }: ESLintReactSettings) => {
1022
- readonly components: {
1023
- name: string;
1024
- re: {
1025
- test(s: string): boolean;
1026
- };
1027
- as: string;
1028
- attributes: {
1029
- name: string;
1030
- as: string;
1031
- controlled?: boolean | undefined;
1032
- defaultValue?: string | undefined;
1033
- }[];
1034
- selector?: string | undefined;
1035
- }[];
1036
- readonly additionalHooks: {
1037
- use?: string[] | undefined;
1038
- useActionState?: string[] | undefined;
1039
- useCallback?: string[] | undefined;
1040
- useContext?: string[] | undefined;
1041
- useDebugValue?: string[] | undefined;
1042
- useDeferredValue?: string[] | undefined;
1043
- useEffect?: string[] | undefined;
1044
- useFormStatus?: string[] | undefined;
1045
- useId?: string[] | undefined;
1046
- useImperativeHandle?: string[] | undefined;
1047
- useInsertionEffect?: string[] | undefined;
1048
- useLayoutEffect?: string[] | undefined;
1049
- useMemo?: string[] | undefined;
1050
- useOptimistic?: string[] | undefined;
1051
- useReducer?: string[] | undefined;
1052
- useRef?: string[] | undefined;
1053
- useState?: string[] | undefined;
1054
- useSyncExternalStore?: string[] | undefined;
1055
- useTransition?: string[] | undefined;
1056
- };
1057
- readonly importSource: string;
1058
- readonly polymorphicPropName: string;
1059
- readonly skipImportCheck: boolean;
1060
- readonly strict: boolean;
1061
- readonly version: string;
1062
- readonly jsxPragma?: string | undefined;
1063
- readonly jsxPragmaFrag?: string | undefined;
1064
- };
1065
- declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
1066
- /**
1067
- * A helper function to define settings for "react-x" with type checking in JavaScript files.
1068
- * @param settings The settings.
1069
- * @returns The settings.
1070
- */
1071
- declare const defineSettings: (settings: ESLintReactSettings) => ESLintReactSettings;
1072
- declare module "@typescript-eslint/utils/ts-eslint" {
1073
- interface SharedConfigurationSettings {
1074
- ["react-x"]?: Partial<ESLintReactSettings>;
1075
- }
1076
- }
1077
-
1078
- export { type CustomComponent, type CustomComponentNormalized, type CustomComponentProp, type CustomComponentPropNormalized, CustomComponentPropSchema, CustomComponentSchema, type CustomHooks, CustomHooksSchema, DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, NPM_SCOPE, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineSettings, getDocsUrl, getId, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, normalizeSettings };