@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.d.ts
CHANGED
|
@@ -2,6 +2,16 @@ import { _ } from '@eslint-react/eff';
|
|
|
2
2
|
import { RuleContext } from '@eslint-react/kit';
|
|
3
3
|
import * as z from '@zod/mini';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
declare const getId: () => string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
declare const _require: NodeJS.Require;
|
|
14
|
+
|
|
5
15
|
/**
|
|
6
16
|
* The NPM scope for this project.
|
|
7
17
|
*/
|
|
@@ -23,8 +33,6 @@ declare const WEBSITE_URL = "https://eslint-react.xyz";
|
|
|
23
33
|
*/
|
|
24
34
|
declare const getDocsUrl: (pluginName: string) => (ruleName: string) => string;
|
|
25
35
|
|
|
26
|
-
declare const getId: () => string;
|
|
27
|
-
|
|
28
36
|
declare function getReactVersion(fallback: string): string;
|
|
29
37
|
|
|
30
38
|
/**
|
|
@@ -1075,4 +1083,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
|
|
|
1075
1083
|
}
|
|
1076
1084
|
}
|
|
1077
1085
|
|
|
1078
|
-
export { type CustomComponent, type CustomComponentNormalized, type CustomComponentProp, type CustomComponentPropNormalized, CustomComponentPropSchema, CustomComponentSchema, type CustomHooks, CustomHooksSchema, DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, NPM_SCOPE, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineSettings, getDocsUrl, getId, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, normalizeSettings };
|
|
1086
|
+
export { type CustomComponent, type CustomComponentNormalized, type CustomComponentProp, type CustomComponentPropNormalized, CustomComponentPropSchema, CustomComponentSchema, type CustomHooks, CustomHooksSchema, DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, type ESLintReactSettings, type ESLintReactSettingsNormalized, ESLintReactSettingsSchema, type ESLintSettings, ESLintSettingsSchema, GITHUB_URL, NPM_SCOPE, WEBSITE_URL, _require, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineSettings, getDocsUrl, getId, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, normalizeSettings };
|
package/dist/index.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import module from 'node:module';
|
|
2
|
+
import path from 'node: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 * as z from '@zod/mini';
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var z = require('@zod/mini');
|
|
8
|
-
|
|
9
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
10
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
|
|
12
|
-
function _interopNamespace(e) {
|
|
13
|
-
if (e && e.__esModule) return e;
|
|
14
|
-
var n = Object.create(null);
|
|
15
|
-
if (e) {
|
|
16
|
-
Object.keys(e).forEach(function (k) {
|
|
17
|
-
if (k !== 'default') {
|
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return e[k]; }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
n.default = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var module__default = /*#__PURE__*/_interopDefault(module$1);
|
|
31
|
-
var z__namespace = /*#__PURE__*/_interopNamespace(z);
|
|
8
|
+
// src/_id.ts
|
|
9
|
+
var id = 0n;
|
|
10
|
+
var getId = () => (id++).toString();
|
|
11
|
+
var _require = module.createRequire(process.cwd() + path.sep);
|
|
32
12
|
|
|
33
13
|
// src/constants.ts
|
|
34
14
|
var NPM_SCOPE = "@eslint-react";
|
|
@@ -42,154 +22,149 @@ var getDocsUrl = (pluginName) => (ruleName) => {
|
|
|
42
22
|
}
|
|
43
23
|
return `${WEBSITE_URL}/docs/rules/${pluginName}-${ruleName}`;
|
|
44
24
|
};
|
|
45
|
-
|
|
46
|
-
// src/get-id.ts
|
|
47
|
-
var id = 0n;
|
|
48
|
-
var getId = () => (id++).toString();
|
|
49
|
-
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)));
|
|
50
25
|
function getReactVersion(fallback) {
|
|
51
26
|
try {
|
|
52
|
-
return
|
|
27
|
+
return match(_require("react")).with({ version: P.select(P.string) }, identity).otherwise(() => fallback);
|
|
53
28
|
} catch {
|
|
54
29
|
return fallback;
|
|
55
30
|
}
|
|
56
31
|
}
|
|
57
|
-
var CustomComponentPropSchema =
|
|
32
|
+
var CustomComponentPropSchema = z.object({
|
|
58
33
|
/**
|
|
59
34
|
* The name of the prop in the user-defined component.
|
|
60
35
|
* @example
|
|
61
36
|
* "to"
|
|
62
37
|
*/
|
|
63
|
-
name:
|
|
38
|
+
name: z.string(),
|
|
64
39
|
/**
|
|
65
40
|
* The name of the prop in the host component.
|
|
66
41
|
* @example
|
|
67
42
|
* "href"
|
|
68
43
|
*/
|
|
69
|
-
as:
|
|
44
|
+
as: z.optional(z.string()),
|
|
70
45
|
/**
|
|
71
46
|
* Whether the prop is controlled or not in the user-defined component.
|
|
72
47
|
* @internal
|
|
73
48
|
* @example
|
|
74
49
|
* `true`
|
|
75
50
|
*/
|
|
76
|
-
controlled:
|
|
51
|
+
controlled: z.optional(z.boolean()),
|
|
77
52
|
/**
|
|
78
53
|
* The default value of the prop in the user-defined component.
|
|
79
54
|
* @example
|
|
80
55
|
* `"/"`
|
|
81
56
|
*/
|
|
82
|
-
defaultValue:
|
|
57
|
+
defaultValue: z.optional(z.string())
|
|
83
58
|
});
|
|
84
|
-
var CustomComponentSchema =
|
|
59
|
+
var CustomComponentSchema = z.object({
|
|
85
60
|
/**
|
|
86
61
|
* The name of the user-defined component.
|
|
87
62
|
* @example
|
|
88
63
|
* "Link"
|
|
89
64
|
*/
|
|
90
|
-
name:
|
|
65
|
+
name: z.string(),
|
|
91
66
|
/**
|
|
92
67
|
* The name of the host component that the user-defined component represents.
|
|
93
68
|
* @example
|
|
94
69
|
* "a"
|
|
95
70
|
*/
|
|
96
|
-
as:
|
|
71
|
+
as: z.optional(z.string()),
|
|
97
72
|
/**
|
|
98
73
|
* Attributes mapping between the user-defined component and the host component.
|
|
99
74
|
* @example
|
|
100
75
|
* `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
|
|
101
76
|
*/
|
|
102
|
-
attributes:
|
|
77
|
+
attributes: z.optional(z.array(CustomComponentPropSchema)),
|
|
103
78
|
/**
|
|
104
79
|
* The ESQuery selector to select the component precisely.
|
|
105
80
|
* @internal
|
|
106
81
|
* @example
|
|
107
82
|
* `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
|
|
108
83
|
*/
|
|
109
|
-
selector:
|
|
84
|
+
selector: z.optional(z.string())
|
|
110
85
|
});
|
|
111
|
-
var CustomHooksSchema =
|
|
112
|
-
use:
|
|
113
|
-
useActionState:
|
|
114
|
-
useCallback:
|
|
115
|
-
useContext:
|
|
116
|
-
useDebugValue:
|
|
117
|
-
useDeferredValue:
|
|
118
|
-
useEffect:
|
|
119
|
-
useFormStatus:
|
|
120
|
-
useId:
|
|
121
|
-
useImperativeHandle:
|
|
122
|
-
useInsertionEffect:
|
|
123
|
-
useLayoutEffect:
|
|
124
|
-
useMemo:
|
|
125
|
-
useOptimistic:
|
|
126
|
-
useReducer:
|
|
127
|
-
useRef:
|
|
128
|
-
useState:
|
|
129
|
-
useSyncExternalStore:
|
|
130
|
-
useTransition:
|
|
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()))
|
|
131
106
|
});
|
|
132
|
-
var ESLintReactSettingsSchema =
|
|
107
|
+
var ESLintReactSettingsSchema = z.object({
|
|
133
108
|
/**
|
|
134
109
|
* The source where React is imported from.
|
|
135
110
|
* @description This allows to specify a custom import location for React when not using the official distribution.
|
|
136
111
|
* @default `"react"`
|
|
137
112
|
* @example `"@pika/react"`
|
|
138
113
|
*/
|
|
139
|
-
importSource:
|
|
114
|
+
importSource: z.optional(z.string()),
|
|
140
115
|
/**
|
|
141
116
|
* The identifier that's used for JSX Element creation.
|
|
142
117
|
* @default `"createElement"`
|
|
143
118
|
* @deprecated
|
|
144
119
|
*/
|
|
145
|
-
jsxPragma:
|
|
120
|
+
jsxPragma: z.optional(z.string()),
|
|
146
121
|
/**
|
|
147
122
|
* The identifier that's used for JSX fragment elements.
|
|
148
123
|
* @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
|
|
149
124
|
* @default `"Fragment"`
|
|
150
125
|
* @deprecated
|
|
151
126
|
*/
|
|
152
|
-
jsxPragmaFrag:
|
|
127
|
+
jsxPragmaFrag: z.optional(z.string()),
|
|
153
128
|
/**
|
|
154
129
|
* The name of the prop that is used for polymorphic components.
|
|
155
130
|
* @description This is used to determine the type of the component.
|
|
156
131
|
* @example `"as"`
|
|
157
132
|
*/
|
|
158
|
-
polymorphicPropName:
|
|
133
|
+
polymorphicPropName: z.optional(z.string()),
|
|
159
134
|
/**
|
|
160
135
|
* @default `true`
|
|
161
136
|
* @internal
|
|
162
137
|
*/
|
|
163
|
-
strict:
|
|
138
|
+
strict: z.optional(z.boolean()),
|
|
164
139
|
/**
|
|
165
140
|
* Check both the shape and the import to determine if an API is from React.
|
|
166
141
|
* @default `true`
|
|
167
142
|
* @internal
|
|
168
143
|
*/
|
|
169
|
-
skipImportCheck:
|
|
144
|
+
skipImportCheck: z.optional(z.boolean()),
|
|
170
145
|
/**
|
|
171
146
|
* React version to use, "detect" means auto detect React version from the project's dependencies.
|
|
172
147
|
* If `importSource` is specified, an equivalent version of React should be provided here.
|
|
173
148
|
* @example `"18.3.1"`
|
|
174
149
|
* @default `"detect"`
|
|
175
150
|
*/
|
|
176
|
-
version:
|
|
151
|
+
version: z.optional(z.string()),
|
|
177
152
|
/**
|
|
178
153
|
* A object to define additional hooks that are equivalent to the built-in React Hooks.
|
|
179
154
|
* @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
|
|
180
155
|
* @example `{ useEffect: ["useIsomorphicLayoutEffect"] }`
|
|
181
156
|
*/
|
|
182
|
-
additionalHooks:
|
|
157
|
+
additionalHooks: z.optional(CustomHooksSchema),
|
|
183
158
|
/**
|
|
184
159
|
* An array of user-defined components
|
|
185
160
|
* @description This is used to inform the ESLint React plugins how to treat these components during checks.
|
|
186
161
|
* @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
|
|
187
162
|
*/
|
|
188
|
-
additionalComponents:
|
|
163
|
+
additionalComponents: z.optional(z.array(CustomComponentSchema))
|
|
189
164
|
});
|
|
190
|
-
var ESLintSettingsSchema =
|
|
191
|
-
|
|
192
|
-
"react-x":
|
|
165
|
+
var ESLintSettingsSchema = z.optional(
|
|
166
|
+
z.object({
|
|
167
|
+
"react-x": z.optional(z.unknown())
|
|
193
168
|
}),
|
|
194
169
|
{}
|
|
195
170
|
);
|
|
@@ -242,12 +217,11 @@ var normalizeSettings = ({
|
|
|
242
217
|
version,
|
|
243
218
|
...rest
|
|
244
219
|
}) => {
|
|
245
|
-
const fallbackVersion = DEFAULT_ESLINT_REACT_SETTINGS.version;
|
|
246
220
|
return {
|
|
247
221
|
...rest,
|
|
248
222
|
components: additionalComponents.map((component) => {
|
|
249
223
|
const { name, as = name, attributes = [], ...rest2 } = component;
|
|
250
|
-
const re =
|
|
224
|
+
const re = RegExp.toRegExp(name);
|
|
251
225
|
return {
|
|
252
226
|
...rest2,
|
|
253
227
|
name,
|
|
@@ -265,39 +239,18 @@ var normalizeSettings = ({
|
|
|
265
239
|
polymorphicPropName,
|
|
266
240
|
skipImportCheck,
|
|
267
241
|
strict,
|
|
268
|
-
version:
|
|
242
|
+
version: match(version).with(P.union(P.nullish, "", "detect"), () => getReactVersion("19.1.0")).otherwise(identity)
|
|
269
243
|
};
|
|
270
244
|
};
|
|
271
245
|
var cache = /* @__PURE__ */ new Map();
|
|
272
246
|
function getSettingsFromContext(context) {
|
|
273
247
|
const settings = context.settings;
|
|
274
|
-
return
|
|
248
|
+
return getOrElseUpdate(
|
|
275
249
|
cache,
|
|
276
250
|
settings["react-x"],
|
|
277
251
|
() => normalizeSettings(decodeSettings(settings["react-x"]))
|
|
278
252
|
);
|
|
279
253
|
}
|
|
280
|
-
var defineSettings =
|
|
254
|
+
var defineSettings = identity;
|
|
281
255
|
|
|
282
|
-
|
|
283
|
-
exports.CustomComponentSchema = CustomComponentSchema;
|
|
284
|
-
exports.CustomHooksSchema = CustomHooksSchema;
|
|
285
|
-
exports.DEFAULT_ESLINT_REACT_SETTINGS = DEFAULT_ESLINT_REACT_SETTINGS;
|
|
286
|
-
exports.DEFAULT_ESLINT_SETTINGS = DEFAULT_ESLINT_SETTINGS;
|
|
287
|
-
exports.ESLintReactSettingsSchema = ESLintReactSettingsSchema;
|
|
288
|
-
exports.ESLintSettingsSchema = ESLintSettingsSchema;
|
|
289
|
-
exports.GITHUB_URL = GITHUB_URL;
|
|
290
|
-
exports.NPM_SCOPE = NPM_SCOPE;
|
|
291
|
-
exports.WEBSITE_URL = WEBSITE_URL;
|
|
292
|
-
exports.coerceESLintSettings = coerceESLintSettings;
|
|
293
|
-
exports.coerceSettings = coerceSettings;
|
|
294
|
-
exports.decodeESLintSettings = decodeESLintSettings;
|
|
295
|
-
exports.decodeSettings = decodeSettings;
|
|
296
|
-
exports.defineSettings = defineSettings;
|
|
297
|
-
exports.getDocsUrl = getDocsUrl;
|
|
298
|
-
exports.getId = getId;
|
|
299
|
-
exports.getReactVersion = getReactVersion;
|
|
300
|
-
exports.getSettingsFromContext = getSettingsFromContext;
|
|
301
|
-
exports.isESLintReactSettings = isESLintReactSettings;
|
|
302
|
-
exports.isESLintSettings = isESLintSettings;
|
|
303
|
-
exports.normalizeSettings = normalizeSettings;
|
|
256
|
+
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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/shared",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.2",
|
|
4
4
|
"description": "ESLint React's Shared constants and functions.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -14,22 +14,14 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"author": "Rel1cx<rel1cx@proton.me>",
|
|
16
16
|
"sideEffects": false,
|
|
17
|
+
"type": "module",
|
|
17
18
|
"exports": {
|
|
18
19
|
".": {
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"default": "./dist/index.mjs"
|
|
22
|
-
},
|
|
23
|
-
"require": {
|
|
24
|
-
"types": "./dist/index.d.ts",
|
|
25
|
-
"default": "./dist/index.js"
|
|
26
|
-
}
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
27
22
|
},
|
|
28
23
|
"./package.json": "./package.json"
|
|
29
24
|
},
|
|
30
|
-
"main": "dist/index.js",
|
|
31
|
-
"module": "dist/index.mjs",
|
|
32
|
-
"types": "dist/index.d.ts",
|
|
33
25
|
"files": [
|
|
34
26
|
"dist",
|
|
35
27
|
"./package.json"
|
|
@@ -38,8 +30,8 @@
|
|
|
38
30
|
"@typescript-eslint/utils": "^8.30.1",
|
|
39
31
|
"@zod/mini": "^4.0.0-beta.20250418T073619",
|
|
40
32
|
"ts-pattern": "^5.7.0",
|
|
41
|
-
"@eslint-react/eff": "2.0.0-next.
|
|
42
|
-
"@eslint-react/kit": "2.0.0-next.
|
|
33
|
+
"@eslint-react/eff": "2.0.0-next.2",
|
|
34
|
+
"@eslint-react/kit": "2.0.0-next.2"
|
|
43
35
|
},
|
|
44
36
|
"devDependencies": {
|
|
45
37
|
"@tsconfig/node22": "^22.0.1",
|