@eslint-react/shared 1.52.9 → 1.52.10-beta.1

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