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