@eslint-react/shared 2.0.0-beta.55 → 2.0.0-beta.58
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 +84 -46
- package/dist/index.js +56 -14
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -15,19 +15,6 @@ declare const getId: () => string;
|
|
|
15
15
|
*/
|
|
16
16
|
declare const _require: NodeJS.Require;
|
|
17
17
|
//#endregion
|
|
18
|
-
//#region src/compatibility-types.d.ts
|
|
19
|
-
interface CompatiblePlugin {
|
|
20
|
-
meta: {
|
|
21
|
-
name: string;
|
|
22
|
-
version: string;
|
|
23
|
-
};
|
|
24
|
-
rules: Record<string, any>;
|
|
25
|
-
}
|
|
26
|
-
interface CompatibleConfig {
|
|
27
|
-
name?: string;
|
|
28
|
-
rules?: Record<string, any>;
|
|
29
|
-
}
|
|
30
|
-
//#endregion
|
|
31
18
|
//#region src/constants.d.ts
|
|
32
19
|
/**
|
|
33
20
|
* The NPM scope for this project.
|
|
@@ -55,6 +42,9 @@ declare const getDocsUrl: (pluginName: string) => (ruleName: string) => string;
|
|
|
55
42
|
declare function getReactVersion(fallback: string): string;
|
|
56
43
|
//#endregion
|
|
57
44
|
//#region src/settings.d.ts
|
|
45
|
+
/**
|
|
46
|
+
* Schema for component prop mapping between user-defined components and host components
|
|
47
|
+
*/
|
|
58
48
|
declare const CustomComponentPropSchema: z.ZodObject<{
|
|
59
49
|
name: z.ZodString;
|
|
60
50
|
as: z.ZodOptional<z.ZodString>;
|
|
@@ -62,10 +52,9 @@ declare const CustomComponentPropSchema: z.ZodObject<{
|
|
|
62
52
|
defaultValue: z.ZodOptional<z.ZodString>;
|
|
63
53
|
}, z.core.$strip>;
|
|
64
54
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
|
|
55
|
+
* Schema for custom components configuration
|
|
56
|
+
* Provides key information about user-defined components before validation
|
|
57
|
+
* Example: Which prop is used as the `href` prop in a custom `Link` component
|
|
69
58
|
*/
|
|
70
59
|
declare const CustomComponentSchema: z.ZodObject<{
|
|
71
60
|
name: z.ZodString;
|
|
@@ -78,6 +67,9 @@ declare const CustomComponentSchema: z.ZodObject<{
|
|
|
78
67
|
}, z.core.$strip>>>;
|
|
79
68
|
selector: z.ZodOptional<z.ZodString>;
|
|
80
69
|
}, z.core.$strip>;
|
|
70
|
+
/**
|
|
71
|
+
* Schema for custom hooks aliases that should be treated as React Hooks
|
|
72
|
+
*/
|
|
81
73
|
declare const CustomHooksSchema: z.ZodObject<{
|
|
82
74
|
use: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
83
75
|
useActionState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -100,6 +92,7 @@ declare const CustomHooksSchema: z.ZodObject<{
|
|
|
100
92
|
useTransition: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
101
93
|
}, z.core.$strip>;
|
|
102
94
|
/**
|
|
95
|
+
* Schema for ESLint React settings configuration
|
|
103
96
|
* @internal
|
|
104
97
|
*/
|
|
105
98
|
declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
@@ -142,6 +135,7 @@ declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
|
142
135
|
}, z.core.$strip>>>;
|
|
143
136
|
}, z.core.$strip>;
|
|
144
137
|
/**
|
|
138
|
+
* Schema for ESLint settings
|
|
145
139
|
* @internal
|
|
146
140
|
*/
|
|
147
141
|
declare const ESLintSettingsSchema: z.ZodOptional<z.ZodObject<{
|
|
@@ -152,10 +146,39 @@ type CustomComponentProp = z.infer<typeof CustomComponentPropSchema>;
|
|
|
152
146
|
type CustomHooks = z.infer<typeof CustomHooksSchema>;
|
|
153
147
|
type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
|
|
154
148
|
type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
|
|
155
|
-
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
156
|
-
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
157
149
|
/**
|
|
158
|
-
*
|
|
150
|
+
* Normalized representation of a custom component prop
|
|
151
|
+
*/
|
|
152
|
+
interface CustomComponentPropNormalized {
|
|
153
|
+
name: string;
|
|
154
|
+
as: string;
|
|
155
|
+
defaultValue?: string | unit;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Normalized representation of a custom component with RegExp for matching
|
|
159
|
+
*/
|
|
160
|
+
interface CustomComponentNormalized {
|
|
161
|
+
name: string;
|
|
162
|
+
as: string;
|
|
163
|
+
attributes: CustomComponentPropNormalized[];
|
|
164
|
+
re: {
|
|
165
|
+
test(s: string): boolean;
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Normalized ESLint React settings with processed values
|
|
170
|
+
*/
|
|
171
|
+
interface ESLintReactSettingsNormalized {
|
|
172
|
+
additionalHooks: CustomHooks;
|
|
173
|
+
components: CustomComponentNormalized[];
|
|
174
|
+
importSource: string;
|
|
175
|
+
polymorphicPropName: string | unit;
|
|
176
|
+
skipImportCheck: boolean;
|
|
177
|
+
strict: boolean;
|
|
178
|
+
version: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Default ESLint React settings
|
|
159
182
|
*/
|
|
160
183
|
declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
161
184
|
readonly version: "detect";
|
|
@@ -169,6 +192,9 @@ declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
|
169
192
|
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
170
193
|
};
|
|
171
194
|
};
|
|
195
|
+
/**
|
|
196
|
+
* Default ESLint settings with React settings included
|
|
197
|
+
*/
|
|
172
198
|
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
173
199
|
readonly "react-x": {
|
|
174
200
|
readonly version: "detect";
|
|
@@ -183,32 +209,40 @@ declare const DEFAULT_ESLINT_SETTINGS: {
|
|
|
183
209
|
};
|
|
184
210
|
};
|
|
185
211
|
};
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
additionalHooks: CustomHooks;
|
|
201
|
-
components: CustomComponentNormalized[];
|
|
202
|
-
importSource: string;
|
|
203
|
-
polymorphicPropName: string | unit;
|
|
204
|
-
skipImportCheck: boolean;
|
|
205
|
-
strict: boolean;
|
|
206
|
-
version: string;
|
|
207
|
-
}
|
|
212
|
+
/**
|
|
213
|
+
* Checks if the provided settings conform to ESLintSettings schema
|
|
214
|
+
* @param settings The settings object to validate
|
|
215
|
+
*/
|
|
216
|
+
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
217
|
+
/**
|
|
218
|
+
* Checks if the provided settings conform to ESLintReactSettings schema
|
|
219
|
+
* @param settings The settings object to validate
|
|
220
|
+
*/
|
|
221
|
+
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
222
|
+
/**
|
|
223
|
+
* Coerces unknown input to ESLintSettings type
|
|
224
|
+
* @param settings The settings object to coerce
|
|
225
|
+
*/
|
|
208
226
|
declare const coerceESLintSettings: (settings: unknown) => PartialDeep<ESLintSettings>;
|
|
227
|
+
/**
|
|
228
|
+
* Decodes and validates ESLint settings, using defaults if invalid
|
|
229
|
+
* @param settings The settings object to decode
|
|
230
|
+
*/
|
|
209
231
|
declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
|
|
232
|
+
/**
|
|
233
|
+
* Coerces unknown input to ESLintReactSettings type
|
|
234
|
+
* @param settings The settings object to coerce
|
|
235
|
+
*/
|
|
210
236
|
declare const coerceSettings: (settings: unknown) => PartialDeep<ESLintReactSettings>;
|
|
237
|
+
/**
|
|
238
|
+
* Decodes and validates ESLint React settings, using defaults if invalid
|
|
239
|
+
* @param settings The settings object to decode
|
|
240
|
+
*/
|
|
211
241
|
declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
|
|
242
|
+
/**
|
|
243
|
+
* Normalizes ESLint React settings to a consistent internal format
|
|
244
|
+
* Transforms component definitions and resolves version information
|
|
245
|
+
*/
|
|
212
246
|
declare const normalizeSettings: ({
|
|
213
247
|
additionalComponents,
|
|
214
248
|
additionalHooks,
|
|
@@ -260,11 +294,15 @@ declare const normalizeSettings: ({
|
|
|
260
294
|
readonly strict: boolean;
|
|
261
295
|
readonly version: string;
|
|
262
296
|
};
|
|
297
|
+
/**
|
|
298
|
+
* Retrieves normalized ESLint React settings from the rule context
|
|
299
|
+
* Uses caching for performance optimization
|
|
300
|
+
* @param context The ESLint rule context
|
|
301
|
+
*/
|
|
263
302
|
declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
|
|
264
303
|
/**
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* @returns The settings.
|
|
304
|
+
* Helper function for defining typed settings for "react-x" in JavaScript files
|
|
305
|
+
* Provides type checking without runtime transformation
|
|
268
306
|
*/
|
|
269
307
|
declare const defineSettings: (settings: ESLintReactSettings) => ESLintReactSettings;
|
|
270
308
|
declare module "@typescript-eslint/utils/ts-eslint" {
|
|
@@ -273,4 +311,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
|
|
|
273
311
|
}
|
|
274
312
|
}
|
|
275
313
|
//#endregion
|
|
276
|
-
export {
|
|
314
|
+
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, _require, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineSettings, getDocsUrl, getId, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, normalizeSettings };
|
package/dist/index.js
CHANGED
|
@@ -59,6 +59,9 @@ function getReactVersion(fallback) {
|
|
|
59
59
|
|
|
60
60
|
//#endregion
|
|
61
61
|
//#region src/settings.ts
|
|
62
|
+
/**
|
|
63
|
+
* Schema for component prop mapping between user-defined components and host components
|
|
64
|
+
*/
|
|
62
65
|
const CustomComponentPropSchema = z.object({
|
|
63
66
|
name: z.string(),
|
|
64
67
|
as: z.optional(z.string()),
|
|
@@ -66,10 +69,9 @@ const CustomComponentPropSchema = z.object({
|
|
|
66
69
|
defaultValue: z.optional(z.string())
|
|
67
70
|
});
|
|
68
71
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
|
|
72
|
+
* Schema for custom components configuration
|
|
73
|
+
* Provides key information about user-defined components before validation
|
|
74
|
+
* Example: Which prop is used as the `href` prop in a custom `Link` component
|
|
73
75
|
*/
|
|
74
76
|
const CustomComponentSchema = z.object({
|
|
75
77
|
name: z.string(),
|
|
@@ -77,6 +79,9 @@ const CustomComponentSchema = z.object({
|
|
|
77
79
|
attributes: z.optional(z.array(CustomComponentPropSchema)),
|
|
78
80
|
selector: z.optional(z.string())
|
|
79
81
|
});
|
|
82
|
+
/**
|
|
83
|
+
* Schema for custom hooks aliases that should be treated as React Hooks
|
|
84
|
+
*/
|
|
80
85
|
const CustomHooksSchema = z.object({
|
|
81
86
|
use: z.optional(z.array(z.string())),
|
|
82
87
|
useActionState: z.optional(z.array(z.string())),
|
|
@@ -99,6 +104,7 @@ const CustomHooksSchema = z.object({
|
|
|
99
104
|
useTransition: z.optional(z.array(z.string()))
|
|
100
105
|
});
|
|
101
106
|
/**
|
|
107
|
+
* Schema for ESLint React settings configuration
|
|
102
108
|
* @internal
|
|
103
109
|
*/
|
|
104
110
|
const ESLintReactSettingsSchema = z.object({
|
|
@@ -111,17 +117,12 @@ const ESLintReactSettingsSchema = z.object({
|
|
|
111
117
|
additionalComponents: z.optional(z.array(CustomComponentSchema))
|
|
112
118
|
});
|
|
113
119
|
/**
|
|
120
|
+
* Schema for ESLint settings
|
|
114
121
|
* @internal
|
|
115
122
|
*/
|
|
116
123
|
const ESLintSettingsSchema = z.optional(z.object({ "react-x": z.optional(z.unknown()) }));
|
|
117
|
-
function isESLintSettings(settings) {
|
|
118
|
-
return ESLintSettingsSchema.safeParse(settings).success;
|
|
119
|
-
}
|
|
120
|
-
function isESLintReactSettings(settings) {
|
|
121
|
-
return ESLintReactSettingsSchema.safeParse(settings).success;
|
|
122
|
-
}
|
|
123
124
|
/**
|
|
124
|
-
*
|
|
125
|
+
* Default ESLint React settings
|
|
125
126
|
*/
|
|
126
127
|
const DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
127
128
|
version: "detect",
|
|
@@ -135,21 +136,58 @@ const DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
|
135
136
|
useLayoutEffect: ["useIsomorphicLayoutEffect"]
|
|
136
137
|
}
|
|
137
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* Default ESLint settings with React settings included
|
|
141
|
+
*/
|
|
138
142
|
const DEFAULT_ESLINT_SETTINGS = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
|
|
143
|
+
/**
|
|
144
|
+
* Checks if the provided settings conform to ESLintSettings schema
|
|
145
|
+
* @param settings The settings object to validate
|
|
146
|
+
*/
|
|
147
|
+
function isESLintSettings(settings) {
|
|
148
|
+
return ESLintSettingsSchema.safeParse(settings).success;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Checks if the provided settings conform to ESLintReactSettings schema
|
|
152
|
+
* @param settings The settings object to validate
|
|
153
|
+
*/
|
|
154
|
+
function isESLintReactSettings(settings) {
|
|
155
|
+
return ESLintReactSettingsSchema.safeParse(settings).success;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Coerces unknown input to ESLintSettings type
|
|
159
|
+
* @param settings The settings object to coerce
|
|
160
|
+
*/
|
|
139
161
|
const coerceESLintSettings = (settings) => {
|
|
140
162
|
return settings;
|
|
141
163
|
};
|
|
164
|
+
/**
|
|
165
|
+
* Decodes and validates ESLint settings, using defaults if invalid
|
|
166
|
+
* @param settings The settings object to decode
|
|
167
|
+
*/
|
|
142
168
|
const decodeESLintSettings = (settings) => {
|
|
143
169
|
if (isESLintSettings(settings)) return settings;
|
|
144
170
|
return DEFAULT_ESLINT_SETTINGS;
|
|
145
171
|
};
|
|
172
|
+
/**
|
|
173
|
+
* Coerces unknown input to ESLintReactSettings type
|
|
174
|
+
* @param settings The settings object to coerce
|
|
175
|
+
*/
|
|
146
176
|
const coerceSettings = (settings) => {
|
|
147
177
|
return settings;
|
|
148
178
|
};
|
|
179
|
+
/**
|
|
180
|
+
* Decodes and validates ESLint React settings, using defaults if invalid
|
|
181
|
+
* @param settings The settings object to decode
|
|
182
|
+
*/
|
|
149
183
|
const decodeSettings = (settings) => {
|
|
150
184
|
if (isESLintReactSettings(settings)) return settings;
|
|
151
185
|
return DEFAULT_ESLINT_REACT_SETTINGS;
|
|
152
186
|
};
|
|
187
|
+
/**
|
|
188
|
+
* Normalizes ESLint React settings to a consistent internal format
|
|
189
|
+
* Transforms component definitions and resolves version information
|
|
190
|
+
*/
|
|
153
191
|
const normalizeSettings = ({ additionalComponents = [], additionalHooks = {}, importSource = "react", polymorphicPropName = "as", skipImportCheck = true, strict = true, version,...rest }) => {
|
|
154
192
|
return {
|
|
155
193
|
...rest,
|
|
@@ -177,14 +215,18 @@ const normalizeSettings = ({ additionalComponents = [], additionalHooks = {}, im
|
|
|
177
215
|
};
|
|
178
216
|
};
|
|
179
217
|
const cache = /* @__PURE__ */ new Map();
|
|
218
|
+
/**
|
|
219
|
+
* Retrieves normalized ESLint React settings from the rule context
|
|
220
|
+
* Uses caching for performance optimization
|
|
221
|
+
* @param context The ESLint rule context
|
|
222
|
+
*/
|
|
180
223
|
function getSettingsFromContext(context) {
|
|
181
224
|
const settings = context.settings;
|
|
182
225
|
return getOrElseUpdate(cache, settings["react-x"], () => normalizeSettings(decodeSettings(settings["react-x"])));
|
|
183
226
|
}
|
|
184
227
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* @returns The settings.
|
|
228
|
+
* Helper function for defining typed settings for "react-x" in JavaScript files
|
|
229
|
+
* Provides type checking without runtime transformation
|
|
188
230
|
*/
|
|
189
231
|
const defineSettings = identity;
|
|
190
232
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.58",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@typescript-eslint/utils": "^8.41.0",
|
|
31
31
|
"ts-pattern": "^5.8.0",
|
|
32
|
-
"zod": "^4.1.
|
|
33
|
-
"@eslint-react/eff": "2.0.0-beta.
|
|
34
|
-
"@eslint-react/kit": "2.0.0-beta.
|
|
32
|
+
"zod": "^4.1.5",
|
|
33
|
+
"@eslint-react/eff": "2.0.0-beta.58",
|
|
34
|
+
"@eslint-react/kit": "2.0.0-beta.58"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@tsconfig/node22": "^22.0.2",
|