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