@eslint-react/shared 2.0.0-next.58 → 2.0.0-next.61

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