@eslint-react/shared 5.17.3 → 5.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +78 -62
- package/dist/index.js +74 -63
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,99 +1,69 @@
|
|
|
1
1
|
import { z } from "zod/v4";
|
|
2
2
|
import { RuleContext } from "@eslint-react/eslint";
|
|
3
3
|
//#region src/regexp.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* Regular expressions for matching a HTML tag name.
|
|
6
|
-
*/
|
|
4
|
+
/** Regular expression for matching an HTML tag name. */
|
|
7
5
|
declare const RE_HTML_TAG: RegExp;
|
|
8
|
-
/**
|
|
9
|
-
* Regular expression for matching a TypeScript file extension.
|
|
10
|
-
*/
|
|
6
|
+
/** Regular expression for matching a TypeScript file extension. */
|
|
11
7
|
declare const RE_TS_EXT: RegExp;
|
|
12
|
-
/**
|
|
13
|
-
* Regular expression for matching a JavaScript file extension.
|
|
14
|
-
*/
|
|
8
|
+
/** Regular expression for matching a JavaScript file extension. */
|
|
15
9
|
declare const RE_JS_EXT: RegExp;
|
|
16
|
-
/**
|
|
17
|
-
* Regular expression for matching a PascalCase string.
|
|
18
|
-
*/
|
|
10
|
+
/** Regular expression for matching a PascalCase string. */
|
|
19
11
|
declare const RE_PASCAL_CASE: RegExp;
|
|
20
|
-
/**
|
|
21
|
-
* Regular expression for matching a camelCase string.
|
|
22
|
-
*/
|
|
12
|
+
/** Regular expression for matching a camelCase string. */
|
|
23
13
|
declare const RE_CAMEL_CASE: RegExp;
|
|
24
|
-
/**
|
|
25
|
-
* Regular expression for matching a kebab-case string.
|
|
26
|
-
*/
|
|
14
|
+
/** Regular expression for matching a kebab-case string. */
|
|
27
15
|
declare const RE_KEBAB_CASE: RegExp;
|
|
28
|
-
/**
|
|
29
|
-
* Regular expression for matching a snake_case string.
|
|
30
|
-
*/
|
|
16
|
+
/** Regular expression for matching a snake_case string. */
|
|
31
17
|
declare const RE_SNAKE_CASE: RegExp;
|
|
32
|
-
/**
|
|
33
|
-
* Regular expression for matching a CONSTANT_CASE string.
|
|
34
|
-
*/
|
|
18
|
+
/** Regular expression for matching a CONSTANT_CASE string. */
|
|
35
19
|
declare const RE_CONSTANT_CASE: RegExp;
|
|
36
|
-
declare const RE_JAVASCRIPT_PROTOCOL: RegExp;
|
|
37
20
|
/**
|
|
38
|
-
* Regular expression for matching
|
|
21
|
+
* Regular expression for matching the `javascript:` protocol.
|
|
22
|
+
* @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
|
|
39
23
|
*/
|
|
24
|
+
declare const RE_JAVASCRIPT_PROTOCOL: RegExp;
|
|
25
|
+
/** Regular expression for matching a valid JavaScript identifier. */
|
|
40
26
|
declare const RE_JS_IDENTIFIER: RegExp;
|
|
41
|
-
/**
|
|
42
|
-
* Regular expression for matching a RegExp string.
|
|
43
|
-
*/
|
|
27
|
+
/** Regular expression for matching a RegExp string. */
|
|
44
28
|
declare const RE_REGEXP_STR: RegExp;
|
|
45
|
-
/**
|
|
46
|
-
* Regular expression for matching a `@jsx` annotation comment.
|
|
47
|
-
*/
|
|
29
|
+
/** Regular expression for matching a `@jsx` annotation comment. */
|
|
48
30
|
declare const RE_ANNOTATION_JSX: RegExp;
|
|
49
|
-
/**
|
|
50
|
-
* Regular expression for matching a `@jsxFrag` annotation comment.
|
|
51
|
-
*/
|
|
31
|
+
/** Regular expression for matching a `@jsxFrag` annotation comment. */
|
|
52
32
|
declare const RE_ANNOTATION_JSX_FRAG: RegExp;
|
|
53
|
-
/**
|
|
54
|
-
* Regular expression for matching a `@jsxRuntime` annotation comment.
|
|
55
|
-
*/
|
|
33
|
+
/** Regular expression for matching a `@jsxRuntime` annotation comment. */
|
|
56
34
|
declare const RE_ANNOTATION_JSX_RUNTIME: RegExp;
|
|
57
|
-
/**
|
|
58
|
-
* Regular expression for matching a `@jsxImportSource` annotation comment.
|
|
59
|
-
*/
|
|
35
|
+
/** Regular expression for matching a `@jsxImportSource` annotation comment. */
|
|
60
36
|
declare const RE_ANNOTATION_JSX_IMPORT_SOURCE: RegExp;
|
|
61
|
-
/**
|
|
62
|
-
* Regular expression for matching a React component name.
|
|
63
|
-
*/
|
|
37
|
+
/** Regular expression for matching a React component name. */
|
|
64
38
|
declare const RE_COMPONENT_NAME: RegExp;
|
|
65
|
-
/**
|
|
66
|
-
* Regular expression for matching a React component name (loose).
|
|
67
|
-
*/
|
|
39
|
+
/** Regular expression for matching a React component name (loose). */
|
|
68
40
|
declare const RE_COMPONENT_NAME_LOOSE: RegExp;
|
|
69
|
-
/**
|
|
70
|
-
* Regular expression for matching a React Hook name.
|
|
71
|
-
*/
|
|
41
|
+
/** Regular expression for matching a React Hook name. */
|
|
72
42
|
declare const RE_HOOK_NAME: RegExp;
|
|
73
|
-
/**
|
|
74
|
-
* A type represents RegExp-like object with `test` method.
|
|
75
|
-
*/
|
|
43
|
+
/** Represents a RegExp-like object with a `test` method. */
|
|
76
44
|
type RegExpLike = {
|
|
77
45
|
test: (s: string) => boolean;
|
|
78
46
|
};
|
|
79
47
|
/**
|
|
80
|
-
* Convert a string to
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
48
|
+
* Convert a string to a `RegExpLike` object.
|
|
49
|
+
*
|
|
50
|
+
* Normal strings (ex: `"foo"`) are converted to `/^foo$/`.
|
|
51
|
+
* RegExp strings (ex: `"/^foo/i"`) are converted to `/^foo/i`.
|
|
84
52
|
* @param string The string to convert.
|
|
85
|
-
* @returns
|
|
53
|
+
* @returns The converted `RegExpLike` object.
|
|
54
|
+
* @see https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/utils/regexp.ts
|
|
86
55
|
*/
|
|
87
56
|
declare function toRegExp(string: string | null | undefined): RegExpLike;
|
|
88
57
|
/**
|
|
89
|
-
* Check
|
|
58
|
+
* Check if the string is a RegExp string.
|
|
90
59
|
* @param string The string to check.
|
|
91
|
-
* @returns
|
|
60
|
+
* @returns `true` if the string is a RegExp string.
|
|
92
61
|
*/
|
|
93
62
|
declare function isRegExp(string: string): boolean;
|
|
94
63
|
//#endregion
|
|
95
64
|
//#region src/settings.d.ts
|
|
96
65
|
/**
|
|
66
|
+
* The zod schema for the ESLint React settings.
|
|
97
67
|
* @internal
|
|
98
68
|
*/
|
|
99
69
|
declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
@@ -106,30 +76,45 @@ declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
|
106
76
|
}>>;
|
|
107
77
|
polymorphicPropName: z.ZodOptional<z.ZodString>;
|
|
108
78
|
version: z.ZodOptional<z.ZodString>;
|
|
79
|
+
additionalRefHooks: z.ZodOptional<z.ZodString>;
|
|
109
80
|
additionalStateHooks: z.ZodOptional<z.ZodString>;
|
|
110
81
|
additionalEffectHooks: z.ZodOptional<z.ZodString>;
|
|
111
82
|
}, z.core.$strip>;
|
|
112
83
|
/**
|
|
84
|
+
* The zod schema for the ESLint settings.
|
|
113
85
|
* @internal
|
|
114
86
|
*/
|
|
115
87
|
declare const ESLintSettingsSchema: z.ZodOptional<z.ZodObject<{
|
|
116
88
|
"react-x": z.ZodOptional<z.ZodUnknown>;
|
|
117
89
|
}, z.core.$strip>>;
|
|
90
|
+
/** The ESLint settings inferred from `ESLintSettingsSchema`. */
|
|
118
91
|
type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
|
|
92
|
+
/** The ESLint React settings inferred from `ESLintReactSettingsSchema`. */
|
|
119
93
|
type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
|
|
94
|
+
/** Represents the normalized ESLint React settings used by rules. */
|
|
120
95
|
interface ESLintReactSettingsNormalized {
|
|
96
|
+
/** The React version. */
|
|
121
97
|
version: string;
|
|
98
|
+
/** The source where React is imported from. */
|
|
122
99
|
importSource: string;
|
|
100
|
+
/** The React Compiler compilation mode, or "off" when not used. */
|
|
123
101
|
compilationMode: ESLintReactSettings["compilationMode"] | "off";
|
|
102
|
+
/** The prop name used for polymorphic components. */
|
|
124
103
|
polymorphicPropName: string | null;
|
|
104
|
+
/** Regex pattern matching custom hooks that should be treated as ref hooks. */
|
|
105
|
+
additionalRefHooks: RegExpLike;
|
|
106
|
+
/** Regex pattern matching custom hooks that should be treated as state hooks. */
|
|
125
107
|
additionalStateHooks: RegExpLike;
|
|
108
|
+
/** Regex pattern matching custom hooks that should be treated as effect hooks. */
|
|
126
109
|
additionalEffectHooks: RegExpLike;
|
|
127
110
|
}
|
|
111
|
+
/** The default ESLint React settings. */
|
|
128
112
|
declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
129
113
|
readonly version: "detect";
|
|
130
114
|
readonly importSource: "react";
|
|
131
115
|
readonly polymorphicPropName: "as";
|
|
132
116
|
};
|
|
117
|
+
/** The default ESLint settings. */
|
|
133
118
|
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
134
119
|
readonly "react-x": {
|
|
135
120
|
readonly version: "detect";
|
|
@@ -137,24 +122,55 @@ declare const DEFAULT_ESLINT_SETTINGS: {
|
|
|
137
122
|
readonly polymorphicPropName: "as";
|
|
138
123
|
};
|
|
139
124
|
};
|
|
125
|
+
/**
|
|
126
|
+
* Check if the value is valid ESLint settings.
|
|
127
|
+
* @param settings The value to check.
|
|
128
|
+
* @returns `true` if the value is valid ESLint settings.
|
|
129
|
+
*/
|
|
140
130
|
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
131
|
+
/**
|
|
132
|
+
* Check if the value is valid ESLint React settings.
|
|
133
|
+
* @param settings The value to check.
|
|
134
|
+
* @returns `true` if the value is valid ESLint React settings.
|
|
135
|
+
*/
|
|
141
136
|
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
137
|
+
/**
|
|
138
|
+
* Decode the ESLint settings, falling back to the defaults when invalid.
|
|
139
|
+
* @param settings The value to decode.
|
|
140
|
+
* @returns The decoded ESLint settings.
|
|
141
|
+
*/
|
|
142
142
|
declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
|
|
143
|
+
/**
|
|
144
|
+
* Decode the ESLint React settings, falling back to the defaults when invalid.
|
|
145
|
+
* @param settings The value to decode.
|
|
146
|
+
* @returns The decoded ESLint React settings.
|
|
147
|
+
*/
|
|
143
148
|
declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
|
|
144
|
-
|
|
149
|
+
/**
|
|
150
|
+
* Normalize the ESLint React settings to the form used by rules.
|
|
151
|
+
* @param settings The ESLint React settings to normalize.
|
|
152
|
+
* @returns The normalized ESLint React settings.
|
|
153
|
+
*/
|
|
154
|
+
declare const normalizeSettings: ({ importSource, compilationMode, polymorphicPropName, version, additionalRefHooks, additionalStateHooks, additionalEffectHooks, ...rest }: ESLintReactSettings) => {
|
|
145
155
|
readonly importSource: string;
|
|
146
156
|
readonly compilationMode: "infer" | "annotation" | "syntax" | "all" | "off";
|
|
147
157
|
readonly polymorphicPropName: string;
|
|
148
158
|
readonly version: string;
|
|
159
|
+
readonly additionalRefHooks: RegExpLike;
|
|
149
160
|
readonly additionalStateHooks: RegExpLike;
|
|
150
161
|
readonly additionalEffectHooks: RegExpLike;
|
|
151
162
|
};
|
|
152
163
|
/**
|
|
153
|
-
*
|
|
164
|
+
* Get the React version from the project's dependencies.
|
|
154
165
|
* @param fallback The fallback version to return if React is not found.
|
|
155
166
|
* @returns The detected React version or the fallback version.
|
|
156
167
|
*/
|
|
157
168
|
declare function getReactVersion(fallback: string): string;
|
|
169
|
+
/**
|
|
170
|
+
* Get the normalized ESLint React settings from the rule context.
|
|
171
|
+
* @param context The rule context.
|
|
172
|
+
* @returns The normalized ESLint React settings.
|
|
173
|
+
*/
|
|
158
174
|
declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
|
|
159
175
|
declare module "@typescript-eslint/utils/ts-eslint" {
|
|
160
176
|
interface SharedConfigurationSettings {
|
package/dist/index.js
CHANGED
|
@@ -484,82 +484,53 @@ const takeWhile = dual(2, (xs, pred) => {
|
|
|
484
484
|
|
|
485
485
|
//#endregion
|
|
486
486
|
//#region src/regexp.ts
|
|
487
|
-
/**
|
|
488
|
-
* Regular expressions for matching a HTML tag name.
|
|
489
|
-
*/
|
|
487
|
+
/** Regular expression for matching an HTML tag name. */
|
|
490
488
|
const RE_HTML_TAG = /^[a-z][^-]*$/u;
|
|
491
|
-
/**
|
|
492
|
-
* Regular expression for matching a TypeScript file extension.
|
|
493
|
-
*/
|
|
489
|
+
/** Regular expression for matching a TypeScript file extension. */
|
|
494
490
|
const RE_TS_EXT = /^[cm]?tsx?$/u;
|
|
495
|
-
/**
|
|
496
|
-
* Regular expression for matching a JavaScript file extension.
|
|
497
|
-
*/
|
|
491
|
+
/** Regular expression for matching a JavaScript file extension. */
|
|
498
492
|
const RE_JS_EXT = /^[cm]?jsx?$/u;
|
|
499
|
-
/**
|
|
500
|
-
* Regular expression for matching a PascalCase string.
|
|
501
|
-
*/
|
|
493
|
+
/** Regular expression for matching a PascalCase string. */
|
|
502
494
|
const RE_PASCAL_CASE = /^[A-Z][\dA-Za-z]*$/u;
|
|
503
|
-
/**
|
|
504
|
-
* Regular expression for matching a camelCase string.
|
|
505
|
-
*/
|
|
495
|
+
/** Regular expression for matching a camelCase string. */
|
|
506
496
|
const RE_CAMEL_CASE = /^[a-z][\dA-Za-z]*$/u;
|
|
507
|
-
/**
|
|
508
|
-
* Regular expression for matching a kebab-case string.
|
|
509
|
-
*/
|
|
497
|
+
/** Regular expression for matching a kebab-case string. */
|
|
510
498
|
const RE_KEBAB_CASE = /^[a-z][\d\-a-z]*$/u;
|
|
511
|
-
/**
|
|
512
|
-
* Regular expression for matching a snake_case string.
|
|
513
|
-
*/
|
|
499
|
+
/** Regular expression for matching a snake_case string. */
|
|
514
500
|
const RE_SNAKE_CASE = /^[a-z][\d_a-z]*$/u;
|
|
515
|
-
/**
|
|
516
|
-
* Regular expression for matching a CONSTANT_CASE string.
|
|
517
|
-
*/
|
|
501
|
+
/** Regular expression for matching a CONSTANT_CASE string. */
|
|
518
502
|
const RE_CONSTANT_CASE = /^[A-Z][\d_A-Z]*$/u;
|
|
519
|
-
const RE_JAVASCRIPT_PROTOCOL = /^[\u0000-\u001F ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\r]*s[\t\n\r]*c[\t\n\r]*r[\t\n\r]*i[\t\n\r]*p[\t\n\r]*t[\t\n\r]*:/iu;
|
|
520
503
|
/**
|
|
521
|
-
* Regular expression for matching
|
|
504
|
+
* Regular expression for matching the `javascript:` protocol.
|
|
505
|
+
* @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
|
|
522
506
|
*/
|
|
507
|
+
const RE_JAVASCRIPT_PROTOCOL = /^[\u0000-\u001F ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\r]*s[\t\n\r]*c[\t\n\r]*r[\t\n\r]*i[\t\n\r]*p[\t\n\r]*t[\t\n\r]*:/iu;
|
|
508
|
+
/** Regular expression for matching a valid JavaScript identifier. */
|
|
523
509
|
const RE_JS_IDENTIFIER = /^[_$a-z][\w$]*$/i;
|
|
524
|
-
/**
|
|
525
|
-
* Regular expression for matching a RegExp string.
|
|
526
|
-
*/
|
|
510
|
+
/** Regular expression for matching a RegExp string. */
|
|
527
511
|
const RE_REGEXP_STR = /^\/(.+)\/([A-Za-z]*)$/u;
|
|
528
|
-
/**
|
|
529
|
-
* Regular expression for matching a `@jsx` annotation comment.
|
|
530
|
-
*/
|
|
512
|
+
/** Regular expression for matching a `@jsx` annotation comment. */
|
|
531
513
|
const RE_ANNOTATION_JSX = /@jsx\s+(\S+)/u;
|
|
532
|
-
/**
|
|
533
|
-
* Regular expression for matching a `@jsxFrag` annotation comment.
|
|
534
|
-
*/
|
|
514
|
+
/** Regular expression for matching a `@jsxFrag` annotation comment. */
|
|
535
515
|
const RE_ANNOTATION_JSX_FRAG = /@jsxFrag\s+(\S+)/u;
|
|
536
|
-
/**
|
|
537
|
-
* Regular expression for matching a `@jsxRuntime` annotation comment.
|
|
538
|
-
*/
|
|
516
|
+
/** Regular expression for matching a `@jsxRuntime` annotation comment. */
|
|
539
517
|
const RE_ANNOTATION_JSX_RUNTIME = /@jsxRuntime\s+(\S+)/u;
|
|
540
|
-
/**
|
|
541
|
-
* Regular expression for matching a `@jsxImportSource` annotation comment.
|
|
542
|
-
*/
|
|
518
|
+
/** Regular expression for matching a `@jsxImportSource` annotation comment. */
|
|
543
519
|
const RE_ANNOTATION_JSX_IMPORT_SOURCE = /@jsxImportSource\s+(\S+)/u;
|
|
544
|
-
/**
|
|
545
|
-
* Regular expression for matching a React component name.
|
|
546
|
-
*/
|
|
520
|
+
/** Regular expression for matching a React component name. */
|
|
547
521
|
const RE_COMPONENT_NAME = /^[A-Z]/u;
|
|
548
|
-
/**
|
|
549
|
-
* Regular expression for matching a React component name (loose).
|
|
550
|
-
*/
|
|
522
|
+
/** Regular expression for matching a React component name (loose). */
|
|
551
523
|
const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
|
|
552
|
-
/**
|
|
553
|
-
* Regular expression for matching a React Hook name.
|
|
554
|
-
*/
|
|
524
|
+
/** Regular expression for matching a React Hook name. */
|
|
555
525
|
const RE_HOOK_NAME = /^use/u;
|
|
556
526
|
/**
|
|
557
|
-
* Convert a string to
|
|
558
|
-
*
|
|
559
|
-
*
|
|
560
|
-
*
|
|
527
|
+
* Convert a string to a `RegExpLike` object.
|
|
528
|
+
*
|
|
529
|
+
* Normal strings (ex: `"foo"`) are converted to `/^foo$/`.
|
|
530
|
+
* RegExp strings (ex: `"/^foo/i"`) are converted to `/^foo/i`.
|
|
561
531
|
* @param string The string to convert.
|
|
562
|
-
* @returns
|
|
532
|
+
* @returns The converted `RegExpLike` object.
|
|
533
|
+
* @see https://github.com/sveltejs/eslint-plugin-svelte/blob/main/packages/eslint-plugin-svelte/src/utils/regexp.ts
|
|
563
534
|
*/
|
|
564
535
|
function toRegExp(string) {
|
|
565
536
|
if (string == null) return { test: constFalse };
|
|
@@ -568,9 +539,9 @@ function toRegExp(string) {
|
|
|
568
539
|
return { test: (s) => s === string };
|
|
569
540
|
}
|
|
570
541
|
/**
|
|
571
|
-
* Check
|
|
542
|
+
* Check if the string is a RegExp string.
|
|
572
543
|
* @param string The string to check.
|
|
573
|
-
* @returns
|
|
544
|
+
* @returns `true` if the string is a RegExp string.
|
|
574
545
|
*/
|
|
575
546
|
function isRegExp(string) {
|
|
576
547
|
return RE_REGEXP_STR.test(string);
|
|
@@ -579,18 +550,19 @@ function isRegExp(string) {
|
|
|
579
550
|
//#endregion
|
|
580
551
|
//#region src/settings.ts
|
|
581
552
|
/**
|
|
553
|
+
* The zod schema for the ESLint React settings.
|
|
582
554
|
* @internal
|
|
583
555
|
*/
|
|
584
556
|
const ESLintReactSettingsSchema = z.object({
|
|
585
557
|
/**
|
|
586
|
-
* The source where React is imported from
|
|
558
|
+
* The source where React is imported from.
|
|
587
559
|
* Allows specifying a custom import location for React.
|
|
588
560
|
* @default "react"
|
|
589
561
|
* @example "@pika/react"
|
|
590
562
|
*/
|
|
591
563
|
importSource: z.optional(z.string()),
|
|
592
564
|
/**
|
|
593
|
-
* The React Compiler compilationMode that the project is using
|
|
565
|
+
* The React Compiler compilationMode that the project is using.
|
|
594
566
|
* Used to inform the rule about how components and hooks will be picked up by the compiler.
|
|
595
567
|
* @example "infer"
|
|
596
568
|
*/
|
|
@@ -601,19 +573,24 @@ const ESLintReactSettingsSchema = z.object({
|
|
|
601
573
|
"all"
|
|
602
574
|
])),
|
|
603
575
|
/**
|
|
604
|
-
* The prop name used for polymorphic components
|
|
576
|
+
* The prop name used for polymorphic components.
|
|
605
577
|
* Used to determine the component's type.
|
|
606
578
|
* @example "as"
|
|
607
579
|
*/
|
|
608
580
|
polymorphicPropName: z.optional(z.string()),
|
|
609
581
|
/**
|
|
610
|
-
* React version to use
|
|
582
|
+
* React version to use.
|
|
611
583
|
* "detect" means auto-detect React version from project dependencies.
|
|
612
584
|
* @example "18.3.1"
|
|
613
585
|
* @default "detect"
|
|
614
586
|
*/
|
|
615
587
|
version: z.optional(z.string()),
|
|
616
588
|
/**
|
|
589
|
+
* Regex pattern matching custom hooks that should be treated as ref hooks.
|
|
590
|
+
* @example "useMyRef|useCustomRef"
|
|
591
|
+
*/
|
|
592
|
+
additionalRefHooks: z.optional(z.string()),
|
|
593
|
+
/**
|
|
617
594
|
* Regex pattern matching custom hooks that should be treated as state hooks.
|
|
618
595
|
* @example "useMyState|useCustomState"
|
|
619
596
|
*/
|
|
@@ -625,43 +602,72 @@ const ESLintReactSettingsSchema = z.object({
|
|
|
625
602
|
additionalEffectHooks: z.optional(z.string())
|
|
626
603
|
});
|
|
627
604
|
/**
|
|
605
|
+
* The zod schema for the ESLint settings.
|
|
628
606
|
* @internal
|
|
629
607
|
*/
|
|
630
608
|
const ESLintSettingsSchema = z.optional(z.object({ "react-x": z.optional(z.unknown()) }));
|
|
609
|
+
/** The default ESLint React settings. */
|
|
631
610
|
const DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
632
611
|
version: "detect",
|
|
633
612
|
importSource: "react",
|
|
634
613
|
polymorphicPropName: "as"
|
|
635
614
|
};
|
|
615
|
+
/** The default ESLint settings. */
|
|
636
616
|
const DEFAULT_ESLINT_SETTINGS = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
|
|
617
|
+
/**
|
|
618
|
+
* Check if the value is valid ESLint settings.
|
|
619
|
+
* @param settings The value to check.
|
|
620
|
+
* @returns `true` if the value is valid ESLint settings.
|
|
621
|
+
*/
|
|
637
622
|
function isESLintSettings(settings) {
|
|
638
623
|
return ESLintSettingsSchema.safeParse(settings).success;
|
|
639
624
|
}
|
|
625
|
+
/**
|
|
626
|
+
* Check if the value is valid ESLint React settings.
|
|
627
|
+
* @param settings The value to check.
|
|
628
|
+
* @returns `true` if the value is valid ESLint React settings.
|
|
629
|
+
*/
|
|
640
630
|
function isESLintReactSettings(settings) {
|
|
641
631
|
return ESLintReactSettingsSchema.safeParse(settings).success;
|
|
642
632
|
}
|
|
633
|
+
/**
|
|
634
|
+
* Decode the ESLint settings, falling back to the defaults when invalid.
|
|
635
|
+
* @param settings The value to decode.
|
|
636
|
+
* @returns The decoded ESLint settings.
|
|
637
|
+
*/
|
|
643
638
|
const decodeESLintSettings = (settings) => {
|
|
644
639
|
if (isESLintSettings(settings)) return settings;
|
|
645
640
|
return DEFAULT_ESLINT_SETTINGS;
|
|
646
641
|
};
|
|
642
|
+
/**
|
|
643
|
+
* Decode the ESLint React settings, falling back to the defaults when invalid.
|
|
644
|
+
* @param settings The value to decode.
|
|
645
|
+
* @returns The decoded ESLint React settings.
|
|
646
|
+
*/
|
|
647
647
|
const decodeSettings = (settings) => {
|
|
648
648
|
if (isESLintReactSettings(settings)) return settings;
|
|
649
649
|
return DEFAULT_ESLINT_REACT_SETTINGS;
|
|
650
650
|
};
|
|
651
|
-
|
|
651
|
+
/**
|
|
652
|
+
* Normalize the ESLint React settings to the form used by rules.
|
|
653
|
+
* @param settings The ESLint React settings to normalize.
|
|
654
|
+
* @returns The normalized ESLint React settings.
|
|
655
|
+
*/
|
|
656
|
+
const normalizeSettings = ({ importSource = "react", compilationMode, polymorphicPropName = "as", version, additionalRefHooks, additionalStateHooks, additionalEffectHooks, ...rest }) => {
|
|
652
657
|
return {
|
|
653
658
|
...rest,
|
|
654
659
|
importSource,
|
|
655
660
|
compilationMode: compilationMode ?? "off",
|
|
656
661
|
polymorphicPropName,
|
|
657
662
|
version: match(version).with(P.union(P.nullish, "", "detect"), () => getReactVersion("19.2.7")).otherwise(identity),
|
|
663
|
+
additionalRefHooks: toRegExp(additionalRefHooks),
|
|
658
664
|
additionalStateHooks: toRegExp(additionalStateHooks),
|
|
659
665
|
additionalEffectHooks: toRegExp(additionalEffectHooks)
|
|
660
666
|
};
|
|
661
667
|
};
|
|
662
668
|
const cache = /* @__PURE__ */ new Map();
|
|
663
669
|
/**
|
|
664
|
-
*
|
|
670
|
+
* Get the React version from the project's dependencies.
|
|
665
671
|
* @param fallback The fallback version to return if React is not found.
|
|
666
672
|
* @returns The detected React version or the fallback version.
|
|
667
673
|
*/
|
|
@@ -672,6 +678,11 @@ function getReactVersion(fallback) {
|
|
|
672
678
|
return fallback;
|
|
673
679
|
}
|
|
674
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Get the normalized ESLint React settings from the rule context.
|
|
683
|
+
* @param context The rule context.
|
|
684
|
+
* @returns The normalized ESLint React settings.
|
|
685
|
+
*/
|
|
675
686
|
function getSettingsFromContext(context) {
|
|
676
687
|
const settings = context.settings["react-x"];
|
|
677
688
|
return getOrInsertComputed(cache, settings, () => normalizeSettings(decodeSettings(settings)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.0",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,17 +29,17 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@typescript-eslint/utils": "^8.
|
|
32
|
+
"@typescript-eslint/utils": "^8.65.0",
|
|
33
33
|
"ts-pattern": "^5.9.0",
|
|
34
34
|
"zod": "^3.25.0 || ^4.0.0",
|
|
35
|
-
"@eslint-react/eslint": "5.
|
|
35
|
+
"@eslint-react/eslint": "5.18.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@tsconfig/node24": "^24.0.4",
|
|
39
39
|
"@types/node": "^26.1.1",
|
|
40
40
|
"@types/picomatch": "^4.0.3",
|
|
41
41
|
"eslint": "^10.7.0",
|
|
42
|
-
"tsdown": "^0.22.
|
|
42
|
+
"tsdown": "^0.22.13",
|
|
43
43
|
"typescript": "6.0.3",
|
|
44
44
|
"@local/configs": "0.0.0",
|
|
45
45
|
"@local/eff": "0.0.0"
|