@eslint-react/shared 1.52.10-beta.0 → 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.js CHANGED
@@ -1,282 +1,230 @@
1
- 'use strict';
2
-
3
- var module$1 = require('module');
4
- var eff = require('@eslint-react/eff');
5
- var tsPattern = require('ts-pattern');
6
- var kit = require('@eslint-react/kit');
7
- var v4 = require('zod/v4');
8
-
9
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
11
22
 
12
- var module__default = /*#__PURE__*/_interopDefault(module$1);
23
+ //#endregion
24
+ const node_module = __toESM(require("node:module"));
25
+ const __eslint_react_eff = __toESM(require("@eslint-react/eff"));
26
+ const ts_pattern = __toESM(require("ts-pattern"));
27
+ const __eslint_react_kit = __toESM(require("@eslint-react/kit"));
28
+ const zod_v4 = __toESM(require("zod/v4"));
13
29
 
14
- // src/constants.ts
15
- var NPM_SCOPE = "@eslint-react";
16
- var GITHUB_URL = "https://github.com/Rel1cx/eslint-react";
17
- var WEBSITE_URL = "https://eslint-react.xyz";
30
+ //#region src/constants.ts
31
+ /**
32
+ * The NPM scope for this project.
33
+ */
34
+ const NPM_SCOPE = "@eslint-react";
35
+ /**
36
+ * The GitHub repository for this project.
37
+ */
38
+ const GITHUB_URL = "https://github.com/Rel1cx/eslint-react";
39
+ /**
40
+ * The URL to the project's website.
41
+ */
42
+ const WEBSITE_URL = "https://eslint-react.xyz";
18
43
 
19
- // src/get-config-adapters.ts
44
+ //#endregion
45
+ //#region src/get-config-adapters.ts
20
46
  function getConfigAdapters(pluginName, plugin) {
21
- function toFlatConfig(config) {
22
- return {
23
- ...config,
24
- plugins: {
25
- [pluginName]: plugin
26
- }
27
- };
28
- }
29
- function toLegacyConfig({ rules }) {
30
- return {
31
- plugins: [pluginName],
32
- rules
33
- };
34
- }
35
- return { toFlatConfig, toLegacyConfig };
47
+ function toFlatConfig(config) {
48
+ return {
49
+ ...config,
50
+ plugins: { [pluginName]: plugin }
51
+ };
52
+ }
53
+ function toLegacyConfig({ rules }) {
54
+ return {
55
+ plugins: [pluginName],
56
+ rules
57
+ };
58
+ }
59
+ return {
60
+ toFlatConfig,
61
+ toLegacyConfig
62
+ };
36
63
  }
37
64
 
38
- // src/get-doc-url.ts
39
- var getDocsUrl = (pluginName) => (ruleName) => {
40
- if (pluginName === "x") {
41
- return `${WEBSITE_URL}/docs/rules/${ruleName}`;
42
- }
43
- return `${WEBSITE_URL}/docs/rules/${pluginName}-${ruleName}`;
65
+ //#endregion
66
+ //#region src/get-doc-url.ts
67
+ /**
68
+ * Get the URL for the documentation of a rule in a plugin.
69
+ * @internal
70
+ * @param pluginName The name of the plugin.
71
+ * @returns The URL for the documentation of a rule.
72
+ */
73
+ const getDocsUrl = (pluginName) => (ruleName) => {
74
+ if (pluginName === "x") return `${WEBSITE_URL}/docs/rules/${ruleName}`;
75
+ return `${WEBSITE_URL}/docs/rules/${pluginName}-${ruleName}`;
44
76
  };
45
77
 
46
- // src/get-id.ts
47
- var id = 0n;
48
- var getId = () => (id++).toString();
49
- var _require = module__default.default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)));
78
+ //#endregion
79
+ //#region src/get-id.ts
80
+ let id = 0n;
81
+ const getId = () => (id++).toString();
82
+
83
+ //#endregion
84
+ //#region src/get-react-version.ts
85
+ const _require = node_module.default.createRequire(require("url").pathToFileURL(__filename).href);
50
86
  function getReactVersion(fallback) {
51
- try {
52
- return tsPattern.match(_require("react")).with({ version: tsPattern.P.select(tsPattern.P.string) }, eff.identity).otherwise(() => fallback);
53
- } catch {
54
- return fallback;
55
- }
87
+ try {
88
+ return (0, ts_pattern.match)(_require("react")).with({ version: ts_pattern.P.select(ts_pattern.P.string) }, __eslint_react_eff.identity).otherwise(() => fallback);
89
+ } catch {
90
+ return fallback;
91
+ }
56
92
  }
57
- var CustomComponentPropSchema = v4.z.object({
58
- /**
59
- * The name of the prop in the user-defined component.
60
- * @example
61
- * "to"
62
- */
63
- name: v4.z.string(),
64
- /**
65
- * The name of the prop in the host component.
66
- * @example
67
- * "href"
68
- */
69
- as: v4.z.optional(v4.z.string()),
70
- /**
71
- * Whether the prop is controlled or not in the user-defined component.
72
- * @internal
73
- * @example
74
- * `true`
75
- */
76
- controlled: v4.z.optional(v4.z.boolean()),
77
- /**
78
- * The default value of the prop in the user-defined component.
79
- * @example
80
- * `"/"`
81
- */
82
- defaultValue: v4.z.optional(v4.z.string())
93
+
94
+ //#endregion
95
+ //#region src/settings.ts
96
+ const CustomComponentPropSchema = zod_v4.z.object({
97
+ name: zod_v4.z.string(),
98
+ as: zod_v4.z.optional(zod_v4.z.string()),
99
+ controlled: zod_v4.z.optional(zod_v4.z.boolean()),
100
+ defaultValue: zod_v4.z.optional(zod_v4.z.string())
83
101
  });
84
- var CustomComponentSchema = v4.z.object({
85
- /**
86
- * The name of the user-defined component.
87
- * @example
88
- * "Link"
89
- */
90
- name: v4.z.string(),
91
- /**
92
- * The name of the host component that the user-defined component represents.
93
- * @example
94
- * "a"
95
- */
96
- as: v4.z.optional(v4.z.string()),
97
- /**
98
- * Attributes mapping between the user-defined component and the host component.
99
- * @example
100
- * `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
101
- */
102
- attributes: v4.z.optional(v4.z.array(CustomComponentPropSchema)),
103
- /**
104
- * The ESQuery selector to select the component precisely.
105
- * @internal
106
- * @example
107
- * `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
108
- */
109
- selector: v4.z.optional(v4.z.string())
102
+ /**
103
+ * @description
104
+ * This will provide some key information to the rule before checking for user-defined components.
105
+ * For example:
106
+ * Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
107
+ */
108
+ const CustomComponentSchema = zod_v4.z.object({
109
+ name: zod_v4.z.string(),
110
+ as: zod_v4.z.optional(zod_v4.z.string()),
111
+ attributes: zod_v4.z.optional(zod_v4.z.array(CustomComponentPropSchema)),
112
+ selector: zod_v4.z.optional(zod_v4.z.string())
110
113
  });
111
- var CustomHooksSchema = v4.z.object({
112
- use: v4.z.optional(v4.z.array(v4.z.string())),
113
- useActionState: v4.z.optional(v4.z.array(v4.z.string())),
114
- useCallback: v4.z.optional(v4.z.array(v4.z.string())),
115
- useContext: v4.z.optional(v4.z.array(v4.z.string())),
116
- useDebugValue: v4.z.optional(v4.z.array(v4.z.string())),
117
- useDeferredValue: v4.z.optional(v4.z.array(v4.z.string())),
118
- useEffect: v4.z.optional(v4.z.array(v4.z.string())),
119
- useFormStatus: v4.z.optional(v4.z.array(v4.z.string())),
120
- useId: v4.z.optional(v4.z.array(v4.z.string())),
121
- useImperativeHandle: v4.z.optional(v4.z.array(v4.z.string())),
122
- useInsertionEffect: v4.z.optional(v4.z.array(v4.z.string())),
123
- useLayoutEffect: v4.z.optional(v4.z.array(v4.z.string())),
124
- useMemo: v4.z.optional(v4.z.array(v4.z.string())),
125
- useOptimistic: v4.z.optional(v4.z.array(v4.z.string())),
126
- useReducer: v4.z.optional(v4.z.array(v4.z.string())),
127
- useRef: v4.z.optional(v4.z.array(v4.z.string())),
128
- useState: v4.z.optional(v4.z.array(v4.z.string())),
129
- useSyncExternalStore: v4.z.optional(v4.z.array(v4.z.string())),
130
- useTransition: v4.z.optional(v4.z.array(v4.z.string()))
114
+ const CustomHooksSchema = zod_v4.z.object({
115
+ use: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
116
+ useActionState: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
117
+ useCallback: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
118
+ useContext: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
119
+ useDebugValue: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
120
+ useDeferredValue: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
121
+ useEffect: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
122
+ useFormStatus: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
123
+ useId: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
124
+ useImperativeHandle: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
125
+ useInsertionEffect: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
126
+ useLayoutEffect: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
127
+ useMemo: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
128
+ useOptimistic: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
129
+ useReducer: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
130
+ useRef: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
131
+ useState: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
132
+ useSyncExternalStore: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string())),
133
+ useTransition: zod_v4.z.optional(zod_v4.z.array(zod_v4.z.string()))
131
134
  });
132
- var ESLintReactSettingsSchema = v4.z.object({
133
- /**
134
- * The source where React is imported from.
135
- * @description This allows to specify a custom import location for React when not using the official distribution.
136
- * @default `"react"`
137
- * @example `"@pika/react"`
138
- */
139
- importSource: v4.z.optional(v4.z.string()),
140
- /**
141
- * The identifier that's used for JSX Element creation.
142
- * @default `"createElement"`
143
- * @deprecated
144
- */
145
- jsxPragma: v4.z.optional(v4.z.string()),
146
- /**
147
- * The identifier that's used for JSX fragment elements.
148
- * @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
149
- * @default `"Fragment"`
150
- * @deprecated
151
- */
152
- jsxPragmaFrag: v4.z.optional(v4.z.string()),
153
- /**
154
- * The name of the prop that is used for polymorphic components.
155
- * @description This is used to determine the type of the component.
156
- * @example `"as"`
157
- */
158
- polymorphicPropName: v4.z.optional(v4.z.string()),
159
- /**
160
- * @default `true`
161
- * @internal
162
- */
163
- strict: v4.z.optional(v4.z.boolean()),
164
- /**
165
- * Check both the shape and the import to determine if an API is from React.
166
- * @default `true`
167
- * @internal
168
- */
169
- skipImportCheck: v4.z.optional(v4.z.boolean()),
170
- /**
171
- * React version to use, "detect" means auto detect React version from the project's dependencies.
172
- * If `importSource` is specified, an equivalent version of React should be provided here.
173
- * @example `"18.3.1"`
174
- * @default `"detect"`
175
- */
176
- version: v4.z.optional(v4.z.string()),
177
- /**
178
- * A object to define additional hooks that are equivalent to the built-in React Hooks.
179
- * @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
180
- * @example `{ useEffect: ["useIsomorphicLayoutEffect"] }`
181
- */
182
- additionalHooks: v4.z.optional(CustomHooksSchema),
183
- /**
184
- * An array of user-defined components
185
- * @description This is used to inform the ESLint React plugins how to treat these components during checks.
186
- * @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
187
- */
188
- additionalComponents: v4.z.optional(v4.z.array(CustomComponentSchema))
135
+ /**
136
+ * @internal
137
+ */
138
+ const ESLintReactSettingsSchema = zod_v4.z.object({
139
+ importSource: zod_v4.z.optional(zod_v4.z.string()),
140
+ jsxPragma: zod_v4.z.optional(zod_v4.z.string()),
141
+ jsxPragmaFrag: zod_v4.z.optional(zod_v4.z.string()),
142
+ polymorphicPropName: zod_v4.z.optional(zod_v4.z.string()),
143
+ strict: zod_v4.z.optional(zod_v4.z.boolean()),
144
+ skipImportCheck: zod_v4.z.optional(zod_v4.z.boolean()),
145
+ version: zod_v4.z.optional(zod_v4.z.string()),
146
+ additionalHooks: zod_v4.z.optional(CustomHooksSchema),
147
+ additionalComponents: zod_v4.z.optional(zod_v4.z.array(CustomComponentSchema))
189
148
  });
190
- var ESLintSettingsSchema = v4.z.optional(
191
- v4.z.object({
192
- "react-x": v4.z.optional(v4.z.unknown())
193
- })
194
- );
149
+ /**
150
+ * @internal
151
+ */
152
+ const ESLintSettingsSchema = zod_v4.z.optional(zod_v4.z.object({ "react-x": zod_v4.z.optional(zod_v4.z.unknown()) }));
195
153
  function isESLintSettings(settings) {
196
- return ESLintSettingsSchema.safeParse(settings).success;
154
+ return ESLintSettingsSchema.safeParse(settings).success;
197
155
  }
198
156
  function isESLintReactSettings(settings) {
199
- return ESLintReactSettingsSchema.safeParse(settings).success;
157
+ return ESLintReactSettingsSchema.safeParse(settings).success;
200
158
  }
201
- var DEFAULT_ESLINT_REACT_SETTINGS = {
202
- version: "detect",
203
- importSource: "react",
204
- strict: true,
205
- skipImportCheck: true,
206
- polymorphicPropName: "as",
207
- additionalComponents: [],
208
- additionalHooks: {
209
- useEffect: ["useIsomorphicLayoutEffect"],
210
- useLayoutEffect: ["useIsomorphicLayoutEffect"]
211
- }
212
- };
213
- var DEFAULT_ESLINT_SETTINGS = {
214
- "react-x": DEFAULT_ESLINT_REACT_SETTINGS
159
+ /**
160
+ * The default ESLint settings for "react-x".
161
+ */
162
+ const DEFAULT_ESLINT_REACT_SETTINGS = {
163
+ version: "detect",
164
+ importSource: "react",
165
+ strict: true,
166
+ skipImportCheck: true,
167
+ polymorphicPropName: "as",
168
+ additionalComponents: [],
169
+ additionalHooks: {
170
+ useEffect: ["useIsomorphicLayoutEffect"],
171
+ useLayoutEffect: ["useIsomorphicLayoutEffect"]
172
+ }
215
173
  };
216
- var coerceESLintSettings = (settings) => {
217
- return settings;
174
+ const DEFAULT_ESLINT_SETTINGS = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
175
+ const coerceESLintSettings = (settings) => {
176
+ return settings;
218
177
  };
219
- var decodeESLintSettings = (settings) => {
220
- if (isESLintSettings(settings)) {
221
- return settings;
222
- }
223
- return DEFAULT_ESLINT_SETTINGS;
178
+ const decodeESLintSettings = (settings) => {
179
+ if (isESLintSettings(settings)) return settings;
180
+ return DEFAULT_ESLINT_SETTINGS;
224
181
  };
225
- var coerceSettings = (settings) => {
226
- return settings;
182
+ const coerceSettings = (settings) => {
183
+ return settings;
227
184
  };
228
- var decodeSettings = (settings) => {
229
- if (isESLintReactSettings(settings)) {
230
- return settings;
231
- }
232
- return DEFAULT_ESLINT_REACT_SETTINGS;
185
+ const decodeSettings = (settings) => {
186
+ if (isESLintReactSettings(settings)) return settings;
187
+ return DEFAULT_ESLINT_REACT_SETTINGS;
233
188
  };
234
- var normalizeSettings = ({
235
- additionalComponents = [],
236
- additionalHooks = {},
237
- importSource = "react",
238
- polymorphicPropName = "as",
239
- skipImportCheck = true,
240
- strict = true,
241
- version,
242
- ...rest
243
- }) => {
244
- return {
245
- ...rest,
246
- components: additionalComponents.map((component) => {
247
- const { name, as = name, attributes = [], ...rest2 } = component;
248
- const re = kit.RegExp.toRegExp(name);
249
- return {
250
- ...rest2,
251
- name,
252
- re,
253
- as,
254
- attributes: attributes.map(({ name: name2, as: as2 = name2, ...rest3 }) => ({
255
- ...rest3,
256
- name: name2,
257
- as: as2
258
- }))
259
- };
260
- }),
261
- additionalHooks,
262
- importSource,
263
- polymorphicPropName,
264
- skipImportCheck,
265
- strict,
266
- version: tsPattern.match(version).with(tsPattern.P.union(tsPattern.P.nullish, "", "detect"), () => getReactVersion("19.1.0")).otherwise(eff.identity)
267
- };
189
+ const normalizeSettings = ({ additionalComponents = [], additionalHooks = {}, importSource = "react", polymorphicPropName = "as", skipImportCheck = true, strict = true, version,...rest }) => {
190
+ return {
191
+ ...rest,
192
+ components: additionalComponents.map((component) => {
193
+ const { name, as = name, attributes = [],...rest$1 } = component;
194
+ const re = __eslint_react_kit.RegExp.toRegExp(name);
195
+ return {
196
+ ...rest$1,
197
+ name,
198
+ re,
199
+ as,
200
+ attributes: attributes.map(({ name: name$1, as: as$1 = name$1,...rest$2 }) => ({
201
+ ...rest$2,
202
+ name: name$1,
203
+ as: as$1
204
+ }))
205
+ };
206
+ }),
207
+ additionalHooks,
208
+ importSource,
209
+ polymorphicPropName,
210
+ skipImportCheck,
211
+ strict,
212
+ version: (0, ts_pattern.match)(version).with(ts_pattern.P.union(ts_pattern.P.nullish, "", "detect"), () => getReactVersion("19.1.0")).otherwise(__eslint_react_eff.identity)
213
+ };
268
214
  };
269
- var cache = /* @__PURE__ */ new Map();
215
+ const cache = /* @__PURE__ */ new Map();
270
216
  function getSettingsFromContext(context) {
271
- const settings = context.settings;
272
- return eff.getOrElseUpdate(
273
- cache,
274
- settings["react-x"],
275
- () => normalizeSettings(decodeSettings(settings["react-x"]))
276
- );
217
+ const settings = context.settings;
218
+ return (0, __eslint_react_eff.getOrElseUpdate)(cache, settings["react-x"], () => normalizeSettings(decodeSettings(settings["react-x"])));
277
219
  }
278
- var defineSettings = eff.identity;
220
+ /**
221
+ * A helper function to define settings for "react-x" with type checking in JavaScript files.
222
+ * @param settings The settings.
223
+ * @returns The settings.
224
+ */
225
+ const defineSettings = __eslint_react_eff.identity;
279
226
 
227
+ //#endregion
280
228
  exports.CustomComponentPropSchema = CustomComponentPropSchema;
281
229
  exports.CustomComponentSchema = CustomComponentSchema;
282
230
  exports.CustomHooksSchema = CustomHooksSchema;
@@ -299,4 +247,4 @@ exports.getReactVersion = getReactVersion;
299
247
  exports.getSettingsFromContext = getSettingsFromContext;
300
248
  exports.isESLintReactSettings = isESLintReactSettings;
301
249
  exports.isESLintSettings = isESLintSettings;
302
- exports.normalizeSettings = normalizeSettings;
250
+ exports.normalizeSettings = normalizeSettings;