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