@eslint-react/shared 2.0.0-next.0 → 2.0.0-next.2
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.d.ts +11 -3
- package/dist/index.js +59 -106
- package/package.json +6 -14
- package/dist/index.d.mts +0 -1078
- package/dist/index.mjs +0 -256
package/dist/index.mjs
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import module from 'node: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 * as z from '@zod/mini';
|
|
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";
|
|
11
|
-
|
|
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}`;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// src/get-id.ts
|
|
21
|
-
var id = 0n;
|
|
22
|
-
var getId = () => (id++).toString();
|
|
23
|
-
var _require = module.createRequire(import.meta.url);
|
|
24
|
-
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
|
-
}
|
|
30
|
-
}
|
|
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())
|
|
57
|
-
});
|
|
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())
|
|
84
|
-
});
|
|
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()))
|
|
105
|
-
});
|
|
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))
|
|
163
|
-
});
|
|
164
|
-
var ESLintSettingsSchema = z.optional(
|
|
165
|
-
z.object({
|
|
166
|
-
"react-x": z.optional(z.unknown())
|
|
167
|
-
}),
|
|
168
|
-
{}
|
|
169
|
-
);
|
|
170
|
-
function isESLintSettings(settings) {
|
|
171
|
-
return ESLintSettingsSchema.safeParse(settings).success;
|
|
172
|
-
}
|
|
173
|
-
function isESLintReactSettings(settings) {
|
|
174
|
-
return ESLintReactSettingsSchema.safeParse(settings).success;
|
|
175
|
-
}
|
|
176
|
-
var DEFAULT_ESLINT_REACT_SETTINGS = {
|
|
177
|
-
version: "detect",
|
|
178
|
-
importSource: "react",
|
|
179
|
-
strict: true,
|
|
180
|
-
skipImportCheck: true,
|
|
181
|
-
polymorphicPropName: "as",
|
|
182
|
-
additionalComponents: [],
|
|
183
|
-
additionalHooks: {
|
|
184
|
-
useEffect: ["useIsomorphicLayoutEffect"],
|
|
185
|
-
useLayoutEffect: ["useIsomorphicLayoutEffect"]
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
var DEFAULT_ESLINT_SETTINGS = {
|
|
189
|
-
"react-x": DEFAULT_ESLINT_REACT_SETTINGS
|
|
190
|
-
};
|
|
191
|
-
var coerceESLintSettings = (settings) => {
|
|
192
|
-
return settings;
|
|
193
|
-
};
|
|
194
|
-
var decodeESLintSettings = (settings) => {
|
|
195
|
-
if (isESLintSettings(settings)) {
|
|
196
|
-
return settings;
|
|
197
|
-
}
|
|
198
|
-
return DEFAULT_ESLINT_SETTINGS;
|
|
199
|
-
};
|
|
200
|
-
var coerceSettings = (settings) => {
|
|
201
|
-
return settings;
|
|
202
|
-
};
|
|
203
|
-
var decodeSettings = (settings) => {
|
|
204
|
-
if (isESLintReactSettings(settings)) {
|
|
205
|
-
return settings;
|
|
206
|
-
}
|
|
207
|
-
return DEFAULT_ESLINT_REACT_SETTINGS;
|
|
208
|
-
};
|
|
209
|
-
var normalizeSettings = ({
|
|
210
|
-
additionalComponents = [],
|
|
211
|
-
additionalHooks = {},
|
|
212
|
-
importSource = "react",
|
|
213
|
-
polymorphicPropName = "as",
|
|
214
|
-
skipImportCheck = true,
|
|
215
|
-
strict = true,
|
|
216
|
-
version,
|
|
217
|
-
...rest
|
|
218
|
-
}) => {
|
|
219
|
-
const fallbackVersion = DEFAULT_ESLINT_REACT_SETTINGS.version;
|
|
220
|
-
return {
|
|
221
|
-
...rest,
|
|
222
|
-
components: additionalComponents.map((component) => {
|
|
223
|
-
const { name, as = name, attributes = [], ...rest2 } = component;
|
|
224
|
-
const re = RegExp.toRegExp(name);
|
|
225
|
-
return {
|
|
226
|
-
...rest2,
|
|
227
|
-
name,
|
|
228
|
-
re,
|
|
229
|
-
as,
|
|
230
|
-
attributes: attributes.map(({ name: name2, as: as2 = name2, ...rest3 }) => ({
|
|
231
|
-
...rest3,
|
|
232
|
-
name: name2,
|
|
233
|
-
as: as2
|
|
234
|
-
}))
|
|
235
|
-
};
|
|
236
|
-
}),
|
|
237
|
-
additionalHooks,
|
|
238
|
-
importSource,
|
|
239
|
-
polymorphicPropName,
|
|
240
|
-
skipImportCheck,
|
|
241
|
-
strict,
|
|
242
|
-
version: match(version).with(P.union(P.nullish, "", "detect"), () => getReactVersion(fallbackVersion)).otherwise(identity)
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
var cache = /* @__PURE__ */ new Map();
|
|
246
|
-
function getSettingsFromContext(context) {
|
|
247
|
-
const settings = context.settings;
|
|
248
|
-
return getOrElseUpdate(
|
|
249
|
-
cache,
|
|
250
|
-
settings["react-x"],
|
|
251
|
-
() => normalizeSettings(decodeSettings(settings["react-x"]))
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
var defineSettings = identity;
|
|
255
|
-
|
|
256
|
-
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 };
|