@eslint-react/shared 2.0.0-next.155 → 2.0.0-next.157

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 CHANGED
@@ -55,6 +55,9 @@ declare const getDocsUrl: (pluginName: string) => (ruleName: string) => string;
55
55
  declare function getReactVersion(fallback: string): string;
56
56
  //#endregion
57
57
  //#region src/settings.d.ts
58
+ /**
59
+ * Schema for component prop mapping between user-defined components and host components
60
+ */
58
61
  declare const CustomComponentPropSchema: z.ZodObject<{
59
62
  name: z.ZodString;
60
63
  as: z.ZodOptional<z.ZodString>;
@@ -62,10 +65,9 @@ declare const CustomComponentPropSchema: z.ZodObject<{
62
65
  defaultValue: z.ZodOptional<z.ZodString>;
63
66
  }, z.core.$strip>;
64
67
  /**
65
- * @description
66
- * This will provide some key information to the rule before checking for user-defined components.
67
- * For example:
68
- * Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
68
+ * Schema for custom components configuration
69
+ * Provides key information about user-defined components before validation
70
+ * Example: Which prop is used as the `href` prop in a custom `Link` component
69
71
  */
70
72
  declare const CustomComponentSchema: z.ZodObject<{
71
73
  name: z.ZodString;
@@ -78,6 +80,9 @@ declare const CustomComponentSchema: z.ZodObject<{
78
80
  }, z.core.$strip>>>;
79
81
  selector: z.ZodOptional<z.ZodString>;
80
82
  }, z.core.$strip>;
83
+ /**
84
+ * Schema for custom hooks aliases that should be treated as React Hooks
85
+ */
81
86
  declare const CustomHooksSchema: z.ZodObject<{
82
87
  use: z.ZodOptional<z.ZodArray<z.ZodString>>;
83
88
  useActionState: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -100,6 +105,7 @@ declare const CustomHooksSchema: z.ZodObject<{
100
105
  useTransition: z.ZodOptional<z.ZodArray<z.ZodString>>;
101
106
  }, z.core.$strip>;
102
107
  /**
108
+ * Schema for ESLint React settings configuration
103
109
  * @internal
104
110
  */
105
111
  declare const ESLintReactSettingsSchema: z.ZodObject<{
@@ -142,6 +148,7 @@ declare const ESLintReactSettingsSchema: z.ZodObject<{
142
148
  }, z.core.$strip>>>;
143
149
  }, z.core.$strip>;
144
150
  /**
151
+ * Schema for ESLint settings
145
152
  * @internal
146
153
  */
147
154
  declare const ESLintSettingsSchema: z.ZodOptional<z.ZodObject<{
@@ -152,10 +159,39 @@ type CustomComponentProp = z.infer<typeof CustomComponentPropSchema>;
152
159
  type CustomHooks = z.infer<typeof CustomHooksSchema>;
153
160
  type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
154
161
  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
162
  /**
158
- * The default ESLint settings for "react-x".
163
+ * Normalized representation of a custom component prop
164
+ */
165
+ interface CustomComponentPropNormalized {
166
+ name: string;
167
+ as: string;
168
+ defaultValue?: string | unit;
169
+ }
170
+ /**
171
+ * Normalized representation of a custom component with RegExp for matching
172
+ */
173
+ interface CustomComponentNormalized {
174
+ name: string;
175
+ as: string;
176
+ attributes: CustomComponentPropNormalized[];
177
+ re: {
178
+ test(s: string): boolean;
179
+ };
180
+ }
181
+ /**
182
+ * Normalized ESLint React settings with processed values
183
+ */
184
+ interface ESLintReactSettingsNormalized {
185
+ additionalHooks: CustomHooks;
186
+ components: CustomComponentNormalized[];
187
+ importSource: string;
188
+ polymorphicPropName: string | unit;
189
+ skipImportCheck: boolean;
190
+ strict: boolean;
191
+ version: string;
192
+ }
193
+ /**
194
+ * Default ESLint React settings
159
195
  */
160
196
  declare const DEFAULT_ESLINT_REACT_SETTINGS: {
161
197
  readonly version: "detect";
@@ -169,6 +205,9 @@ declare const DEFAULT_ESLINT_REACT_SETTINGS: {
169
205
  readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
170
206
  };
171
207
  };
208
+ /**
209
+ * Default ESLint settings with React settings included
210
+ */
172
211
  declare const DEFAULT_ESLINT_SETTINGS: {
173
212
  readonly "react-x": {
174
213
  readonly version: "detect";
@@ -183,32 +222,40 @@ declare const DEFAULT_ESLINT_SETTINGS: {
183
222
  };
184
223
  };
185
224
  };
186
- interface CustomComponentPropNormalized {
187
- name: string;
188
- as: string;
189
- defaultValue?: string | unit;
190
- }
191
- interface CustomComponentNormalized {
192
- name: string;
193
- as: string;
194
- attributes: CustomComponentPropNormalized[];
195
- re: {
196
- test(s: string): boolean;
197
- };
198
- }
199
- interface ESLintReactSettingsNormalized {
200
- additionalHooks: CustomHooks;
201
- components: CustomComponentNormalized[];
202
- importSource: string;
203
- polymorphicPropName: string | unit;
204
- skipImportCheck: boolean;
205
- strict: boolean;
206
- version: string;
207
- }
225
+ /**
226
+ * Checks if the provided settings conform to ESLintSettings schema
227
+ * @param settings The settings object to validate
228
+ */
229
+ declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
230
+ /**
231
+ * Checks if the provided settings conform to ESLintReactSettings schema
232
+ * @param settings The settings object to validate
233
+ */
234
+ declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
235
+ /**
236
+ * Coerces unknown input to ESLintSettings type
237
+ * @param settings The settings object to coerce
238
+ */
208
239
  declare const coerceESLintSettings: (settings: unknown) => PartialDeep<ESLintSettings>;
240
+ /**
241
+ * Decodes and validates ESLint settings, using defaults if invalid
242
+ * @param settings The settings object to decode
243
+ */
209
244
  declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
245
+ /**
246
+ * Coerces unknown input to ESLintReactSettings type
247
+ * @param settings The settings object to coerce
248
+ */
210
249
  declare const coerceSettings: (settings: unknown) => PartialDeep<ESLintReactSettings>;
250
+ /**
251
+ * Decodes and validates ESLint React settings, using defaults if invalid
252
+ * @param settings The settings object to decode
253
+ */
211
254
  declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
255
+ /**
256
+ * Normalizes ESLint React settings to a consistent internal format
257
+ * Transforms component definitions and resolves version information
258
+ */
212
259
  declare const normalizeSettings: ({
213
260
  additionalComponents,
214
261
  additionalHooks,
@@ -260,11 +307,15 @@ declare const normalizeSettings: ({
260
307
  readonly strict: boolean;
261
308
  readonly version: string;
262
309
  };
310
+ /**
311
+ * Retrieves normalized ESLint React settings from the rule context
312
+ * Uses caching for performance optimization
313
+ * @param context The ESLint rule context
314
+ */
263
315
  declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
264
316
  /**
265
- * A helper function to define settings for "react-x" with type checking in JavaScript files.
266
- * @param settings The settings.
267
- * @returns The settings.
317
+ * Helper function for defining typed settings for "react-x" in JavaScript files
318
+ * Provides type checking without runtime transformation
268
319
  */
269
320
  declare const defineSettings: (settings: ESLintReactSettings) => ESLintReactSettings;
270
321
  declare module "@typescript-eslint/utils/ts-eslint" {
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
- * @description
70
- * This will provide some key information to the rule before checking for user-defined components.
71
- * For example:
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
- * The default ESLint settings for "react-x".
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
- * A helper function to define settings for "react-x" with type checking in JavaScript files.
186
- * @param settings The settings.
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-next.155",
3
+ "version": "2.0.0-next.157",
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.4",
33
- "@eslint-react/kit": "2.0.0-next.155",
34
- "@eslint-react/eff": "2.0.0-next.155"
32
+ "zod": "^4.1.5",
33
+ "@eslint-react/eff": "2.0.0-next.157",
34
+ "@eslint-react/kit": "2.0.0-next.157"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@tsconfig/node22": "^22.0.2",