@eslint-react/jsx 0.8.9-beta.1 → 0.8.9-beta.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.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/node_modules/@eslint-react/ast/dist/index.d.mts +1 -1
- package/node_modules/@eslint-react/ast/dist/index.d.ts +1 -1
- package/node_modules/@eslint-react/ast/package.json +2 -1
- package/node_modules/@eslint-react/shared/dist/index.cjs +424 -0
- package/node_modules/@eslint-react/shared/dist/index.d.mts +128 -0
- package/node_modules/@eslint-react/shared/dist/index.d.ts +128 -0
- package/node_modules/@eslint-react/shared/dist/index.js +424 -0
- package/node_modules/@eslint-react/shared/dist/index.mjs +390 -0
- package/node_modules/@eslint-react/shared/package.json +49 -0
- package/node_modules/@eslint-react/tools/package.json +1 -1
- package/node_modules/@eslint-react/types/dist/index.d.mts +1 -56
- package/node_modules/@eslint-react/types/dist/index.d.ts +1 -56
- package/node_modules/@eslint-react/types/package.json +1 -1
- package/package.json +6 -4
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { RuleContext } from '@eslint-react/shared';
|
|
1
2
|
import { Data, O, Narrow } from '@eslint-react/tools';
|
|
2
|
-
import { RuleContext } from '@eslint-react/types';
|
|
3
3
|
import TSESLintScopeManager, { Scope, Variable, Definition } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { TSESLint, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { RuleContext } from '@eslint-react/shared';
|
|
1
2
|
import { Data, O, Narrow } from '@eslint-react/tools';
|
|
2
|
-
import { RuleContext } from '@eslint-react/types';
|
|
3
3
|
import TSESLintScopeManager, { Scope, Variable, Definition } from '@typescript-eslint/scope-manager';
|
|
4
4
|
import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
5
5
|
import { TSESLint, TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/ast",
|
|
3
|
-
"version": "0.8.9-beta.
|
|
3
|
+
"version": "0.8.9-beta.2",
|
|
4
4
|
"description": "ESLint x React's TSESTree AST primitive utility module.",
|
|
5
5
|
"homepage": "https://github.com/rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -43,6 +43,7 @@
|
|
|
43
43
|
"@eslint-community/eslint-utils": "4.4.0",
|
|
44
44
|
"@eslint-react/tools": "workspace:*",
|
|
45
45
|
"@eslint-react/types": "workspace:*",
|
|
46
|
+
"@eslint-react/shared": "workspace:*",
|
|
46
47
|
"@typescript-eslint/scope-manager": "6.10.0",
|
|
47
48
|
"@typescript-eslint/types": "6.10.0",
|
|
48
49
|
"@typescript-eslint/utils": "6.10.0",
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var dedent = require('dedent');
|
|
4
|
+
var utils = require('@typescript-eslint/utils');
|
|
5
|
+
var deepmergeTs = require('deepmerge-ts');
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/split-name.ts
|
|
9
|
+
* Split the file/variable name written in camelCase, kebab-case, PascalCase, and snake_case.
|
|
10
|
+
*/ const splitName = (name)=>{
|
|
11
|
+
return name.replaceAll("_", "-").replaceAll(/([\da-z])([A-Z])|([A-Z])([A-Z])(?=[a-z])/gu, "$1$3-$2$4").toLowerCase().split("-");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/* eslint-disable security/detect-object-injection */ /* eslint-disable security/detect-non-literal-regexp */ // Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/preset-rules.ts
|
|
15
|
+
const presetRules = {
|
|
16
|
+
PascalCase: {
|
|
17
|
+
expression: /^[A-Z][\dA-Za-z]*$/u,
|
|
18
|
+
recommendationBuilder: (name)=>{
|
|
19
|
+
return splitName(name).map((word)=>{
|
|
20
|
+
const [first, ...rest] = word;
|
|
21
|
+
return `${first?.toUpperCase() ?? ""}${rest.join("")}`;
|
|
22
|
+
}).join("");
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
camelCase: {
|
|
26
|
+
expression: /^[a-z][\dA-Za-z]*$/u,
|
|
27
|
+
recommendationBuilder: (name)=>{
|
|
28
|
+
return splitName(name).map((word, i)=>{
|
|
29
|
+
if (i === 0) {
|
|
30
|
+
return word;
|
|
31
|
+
}
|
|
32
|
+
const [first, ...rest] = word;
|
|
33
|
+
return `${first?.toUpperCase() ?? ""}${rest.join("")}`;
|
|
34
|
+
}).join("");
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"kebab-case": {
|
|
38
|
+
expression: /^[a-z][\d\-a-z]*$/u,
|
|
39
|
+
recommendationBuilder: (name)=>{
|
|
40
|
+
return splitName(name).join("-");
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
snake_case: {
|
|
44
|
+
expression: /^[a-z][\d_a-z]*$/u,
|
|
45
|
+
recommendationBuilder: (name)=>{
|
|
46
|
+
return splitName(name).join("_");
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
// eslint-disable-next-line perfectionist/sort-objects
|
|
50
|
+
CONSTANT_CASE: {
|
|
51
|
+
expression: /^[A-Z][\d_A-Z]*$/u,
|
|
52
|
+
recommendationBuilder: (name)=>{
|
|
53
|
+
return splitName(name).join("_").toUpperCase();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const getRule = (expression, preset = presetRules)=>{
|
|
58
|
+
const rule = preset[expression];
|
|
59
|
+
return rule ?? {
|
|
60
|
+
expression: new RegExp(`^${expression}$`, "u")
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/* eslint-disable functional/no-this-expressions */ /* eslint-disable functional/no-expression-statements */ /* eslint-disable functional/no-classes */ /* eslint-disable functional/no-throw-statements */ /* eslint-disable functional/prefer-immutable-types */ /* eslint-disable security/detect-non-literal-regexp */ // Copied from https://github.com/epaew/eslint-plugin-filenames-simple/blob/master/src/utils/case-validator.ts
|
|
65
|
+
class CaseValidator {
|
|
66
|
+
#expression;
|
|
67
|
+
#ignorePatterns;
|
|
68
|
+
#recommendationBuilder;
|
|
69
|
+
constructor(expression, ignorePatterns, recommendationBuilder = ()=>{
|
|
70
|
+
// eslint-disable-next-line functional-core/purity
|
|
71
|
+
throw new Error("Not implemented");
|
|
72
|
+
}){
|
|
73
|
+
this.#expression = expression;
|
|
74
|
+
this.#ignorePatterns = ignorePatterns;
|
|
75
|
+
this.#recommendationBuilder = recommendationBuilder;
|
|
76
|
+
}
|
|
77
|
+
getRecommendedName(name) {
|
|
78
|
+
const recommendedName = this.#recommendationBuilder(name);
|
|
79
|
+
if (this.#expression.test(recommendedName)) {
|
|
80
|
+
return recommendedName;
|
|
81
|
+
}
|
|
82
|
+
// eslint-disable-next-line functional-core/purity
|
|
83
|
+
throw new Error("Failed to build recommendation.");
|
|
84
|
+
}
|
|
85
|
+
validate(name) {
|
|
86
|
+
if (this.#ignorePatterns.some((re)=>re.test(name))) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
return this.#expression.test(name);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const getCaseValidator = (ruleName, ignorePattern = [])=>{
|
|
93
|
+
const { expression, recommendationBuilder } = getRule(ruleName);
|
|
94
|
+
return new CaseValidator(expression, ignorePattern.map((pattern)=>new RegExp(`^${pattern}$`, "u")), recommendationBuilder);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// eslint-disable-next-line functional-core/purity
|
|
98
|
+
const createElementComponent = "const CreateElementComponent = () => React.createElement('div', null, null)";
|
|
99
|
+
const arrowFunctionComponent = "const FunctionComponent = () => <div></div>";
|
|
100
|
+
const functionComponent = dedent`
|
|
101
|
+
function FunctionComponent() {
|
|
102
|
+
return <div></div>
|
|
103
|
+
}
|
|
104
|
+
`;
|
|
105
|
+
const memoComponent = dedent`
|
|
106
|
+
import { memo } from 'react'
|
|
107
|
+
|
|
108
|
+
const MemoComponent = memo(() => <div></div>)
|
|
109
|
+
`;
|
|
110
|
+
const forwardRefComponent = dedent`
|
|
111
|
+
import { forwardRef } from 'react'
|
|
112
|
+
|
|
113
|
+
const ForwardRefComponent = forwardRef(() => <div></div>)
|
|
114
|
+
`;
|
|
115
|
+
const memoForwardRefComponent = dedent`
|
|
116
|
+
import { memo, forwardRef } from 'react'
|
|
117
|
+
|
|
118
|
+
const MemoForwardRefComponent = memo(forwardRef(() => <div></div>))
|
|
119
|
+
`;
|
|
120
|
+
const allComponents = [
|
|
121
|
+
arrowFunctionComponent,
|
|
122
|
+
functionComponent,
|
|
123
|
+
createElementComponent,
|
|
124
|
+
memoComponent,
|
|
125
|
+
forwardRefComponent,
|
|
126
|
+
memoForwardRefComponent
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
// eslint-disable-next-line functional-core/purity
|
|
130
|
+
const fn = "const fn = () => null";
|
|
131
|
+
const fnWithReturn = dedent`
|
|
132
|
+
function fnWithReturn() {
|
|
133
|
+
return null
|
|
134
|
+
}
|
|
135
|
+
`;
|
|
136
|
+
const renderFunction = "const renderFunction = (id: string, name: string) => <div key={id} id={id}>{name}</div>";
|
|
137
|
+
const renderFunctionWithReturn = dedent`
|
|
138
|
+
function renderFunctionWithReturn(id: string, name: string) {
|
|
139
|
+
return <div key={id} id={id}>{name}</div>
|
|
140
|
+
}
|
|
141
|
+
`;
|
|
142
|
+
const allFunctions = [
|
|
143
|
+
fn,
|
|
144
|
+
fnWithReturn,
|
|
145
|
+
renderFunction,
|
|
146
|
+
renderFunctionWithReturn
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
const allValid = [
|
|
150
|
+
...allComponents,
|
|
151
|
+
...allFunctions
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const NPM_SCOPE = "@eslint-react";
|
|
155
|
+
const GITHUB_URL = "https://github.com/rel1cx/eslint-react/blob/main";
|
|
156
|
+
const WEBSITE_URL = "https://eslint-react.xyz";
|
|
157
|
+
const JSX_EXTENSIONS = [
|
|
158
|
+
".jsx",
|
|
159
|
+
".tsx"
|
|
160
|
+
];
|
|
161
|
+
// @see https://github.com/facebook/react/blob/6db7f4209e6f32ebde298a0b7451710dd6aa3e19/packages/react-dom-bindings/src/shared/sanitizeURL.js#L22
|
|
162
|
+
// dprint-ignore
|
|
163
|
+
// eslint-disable-next-line no-control-regex
|
|
164
|
+
const RE_JAVASCRIPT_PROTOCOL = /^[\u0000-\u001F ]*j[\t\n\r]*a[\t\n\r]*v[\t\n\r]*a[\t\n\r]*s[\t\n\r]*c[\t\n\r]*r[\t\n\r]*i[\t\n\r]*p[\t\n\r]*t[\t\n\r]*:/iu;
|
|
165
|
+
|
|
166
|
+
// eslint-disable-next-line functional-core/purity
|
|
167
|
+
const getDocsUrl = (pluginName)=>(ruleName)=>{
|
|
168
|
+
return `${WEBSITE_URL}/rules/${pluginName}-${ruleName}`;
|
|
169
|
+
};
|
|
170
|
+
const createRuleForPlugin = (pluginName)=>utils.ESLintUtils.RuleCreator(getDocsUrl(pluginName));
|
|
171
|
+
|
|
172
|
+
const ReactHostHTMLComponent = 0;
|
|
173
|
+
const ReactHostSVGComponent = 1;
|
|
174
|
+
const ReactHostWebComponent = 2;
|
|
175
|
+
/* eslint-disable functional-core/purity */ // source: https://react.dev/reference/react-dom/components#all-html-components
|
|
176
|
+
const HostHTMLComponentTypes = [
|
|
177
|
+
"aside",
|
|
178
|
+
"audio",
|
|
179
|
+
"b",
|
|
180
|
+
"base",
|
|
181
|
+
"bdi",
|
|
182
|
+
"bdo",
|
|
183
|
+
"blockquote",
|
|
184
|
+
"body",
|
|
185
|
+
"br",
|
|
186
|
+
"button",
|
|
187
|
+
"canvas",
|
|
188
|
+
"caption",
|
|
189
|
+
"cite",
|
|
190
|
+
"code",
|
|
191
|
+
"col",
|
|
192
|
+
"colgroup",
|
|
193
|
+
"data",
|
|
194
|
+
"datalist",
|
|
195
|
+
"dd",
|
|
196
|
+
"del",
|
|
197
|
+
"details",
|
|
198
|
+
"dfn",
|
|
199
|
+
"dialog",
|
|
200
|
+
"div",
|
|
201
|
+
"dl",
|
|
202
|
+
"dt",
|
|
203
|
+
"em",
|
|
204
|
+
"embed",
|
|
205
|
+
"fieldset",
|
|
206
|
+
"figcaption",
|
|
207
|
+
"figure",
|
|
208
|
+
"footer",
|
|
209
|
+
"form",
|
|
210
|
+
"h1",
|
|
211
|
+
"head",
|
|
212
|
+
"header",
|
|
213
|
+
"hgroup",
|
|
214
|
+
"hr",
|
|
215
|
+
"html",
|
|
216
|
+
"i",
|
|
217
|
+
"iframe",
|
|
218
|
+
"img",
|
|
219
|
+
"input",
|
|
220
|
+
"ins",
|
|
221
|
+
"kbd",
|
|
222
|
+
"label",
|
|
223
|
+
"legend",
|
|
224
|
+
"li",
|
|
225
|
+
"link",
|
|
226
|
+
"main",
|
|
227
|
+
"map",
|
|
228
|
+
"mark",
|
|
229
|
+
"menu",
|
|
230
|
+
"meta",
|
|
231
|
+
"meter",
|
|
232
|
+
"nav",
|
|
233
|
+
"noscript",
|
|
234
|
+
"object",
|
|
235
|
+
"ol",
|
|
236
|
+
"optgroup",
|
|
237
|
+
"option",
|
|
238
|
+
"output",
|
|
239
|
+
"p",
|
|
240
|
+
"picture",
|
|
241
|
+
"pre",
|
|
242
|
+
"progress",
|
|
243
|
+
"q",
|
|
244
|
+
"rp",
|
|
245
|
+
"rt",
|
|
246
|
+
"ruby",
|
|
247
|
+
"s",
|
|
248
|
+
"samp",
|
|
249
|
+
"script",
|
|
250
|
+
"section",
|
|
251
|
+
"select",
|
|
252
|
+
"slot",
|
|
253
|
+
"small",
|
|
254
|
+
"source",
|
|
255
|
+
"span",
|
|
256
|
+
"strong",
|
|
257
|
+
"style",
|
|
258
|
+
"sub",
|
|
259
|
+
"summary",
|
|
260
|
+
"sup",
|
|
261
|
+
"table",
|
|
262
|
+
"tbody",
|
|
263
|
+
"td",
|
|
264
|
+
"template",
|
|
265
|
+
"textarea",
|
|
266
|
+
"tfoot",
|
|
267
|
+
"th",
|
|
268
|
+
"thead",
|
|
269
|
+
"time",
|
|
270
|
+
"title",
|
|
271
|
+
"tr",
|
|
272
|
+
"track",
|
|
273
|
+
"u",
|
|
274
|
+
"ul",
|
|
275
|
+
"var",
|
|
276
|
+
"video",
|
|
277
|
+
"wbr"
|
|
278
|
+
];
|
|
279
|
+
// source: https://react.dev/reference/react-dom/components#all-svg-components
|
|
280
|
+
const HostSVGComponentTypes = [
|
|
281
|
+
"a",
|
|
282
|
+
"animate",
|
|
283
|
+
"animateMotion",
|
|
284
|
+
"animateTransform",
|
|
285
|
+
"circle",
|
|
286
|
+
"clipPath",
|
|
287
|
+
"defs",
|
|
288
|
+
"desc",
|
|
289
|
+
"discard",
|
|
290
|
+
"ellipse",
|
|
291
|
+
"feBlend",
|
|
292
|
+
"feColorMatrix",
|
|
293
|
+
"feComponentTransfer",
|
|
294
|
+
"feComposite",
|
|
295
|
+
"feConvolveMatrix",
|
|
296
|
+
"feDiffuseLighting",
|
|
297
|
+
"feDisplacementMap",
|
|
298
|
+
"feDistantLight",
|
|
299
|
+
"feDropShadow",
|
|
300
|
+
"feFlood",
|
|
301
|
+
"feFuncA",
|
|
302
|
+
"feFuncB",
|
|
303
|
+
"feFuncG",
|
|
304
|
+
"feFuncR",
|
|
305
|
+
"feGaussianBlur",
|
|
306
|
+
"feImage",
|
|
307
|
+
"feMerge",
|
|
308
|
+
"feMergeNode",
|
|
309
|
+
"feMorphology",
|
|
310
|
+
"feOffset",
|
|
311
|
+
"fePointLight",
|
|
312
|
+
"feSpecularLighting",
|
|
313
|
+
"feSpotLight",
|
|
314
|
+
"feTile",
|
|
315
|
+
"feTurbulence",
|
|
316
|
+
"filter",
|
|
317
|
+
"foreignObject",
|
|
318
|
+
"g",
|
|
319
|
+
"hatch",
|
|
320
|
+
"hatchpath",
|
|
321
|
+
"image",
|
|
322
|
+
"line",
|
|
323
|
+
"linearGradient",
|
|
324
|
+
"marker",
|
|
325
|
+
"mask",
|
|
326
|
+
"metadata",
|
|
327
|
+
"mpath",
|
|
328
|
+
"path",
|
|
329
|
+
"pattern",
|
|
330
|
+
"polygon",
|
|
331
|
+
"polyline",
|
|
332
|
+
"radialGradient",
|
|
333
|
+
"rect",
|
|
334
|
+
"script",
|
|
335
|
+
"set",
|
|
336
|
+
"stop",
|
|
337
|
+
"style",
|
|
338
|
+
"svg",
|
|
339
|
+
"switch",
|
|
340
|
+
"symbol",
|
|
341
|
+
"text",
|
|
342
|
+
"textPath",
|
|
343
|
+
"title",
|
|
344
|
+
"tspan",
|
|
345
|
+
"use",
|
|
346
|
+
"view"
|
|
347
|
+
];
|
|
348
|
+
function isHostHTMLComponentName(name) {
|
|
349
|
+
return HostHTMLComponentTypes.includes(name);
|
|
350
|
+
}
|
|
351
|
+
function isHostSVGComponentName(name) {
|
|
352
|
+
return HostSVGComponentTypes.includes(name);
|
|
353
|
+
}
|
|
354
|
+
function isHostWebComponentName() {
|
|
355
|
+
// TODO: implement this following the spec in https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/* eslint-disable functional-core/purity */ // Copied from https://github.com/eslint-functional/eslint-plugin-functional/blob/e4bd4ad79502ff77ae26e703e1761ab80a46868b/src/utils/merge-configs.ts
|
|
359
|
+
const mergeConfigs = deepmergeTs.deepmergeCustom({
|
|
360
|
+
mergeArrays (values, utils, meta) {
|
|
361
|
+
if (meta !== undefined && meta.keyPath.length >= 2 && meta.keyPath[0] === "rules") {
|
|
362
|
+
return utils.defaultMergeFunctions.mergeOthers(values);
|
|
363
|
+
}
|
|
364
|
+
return utils.actions.defaultMerge;
|
|
365
|
+
},
|
|
366
|
+
metaDataUpdater: (previousMeta, metaMeta)=>{
|
|
367
|
+
if (previousMeta === undefined) {
|
|
368
|
+
if (metaMeta.key === undefined) {
|
|
369
|
+
return {
|
|
370
|
+
keyPath: []
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
return {
|
|
374
|
+
keyPath: [
|
|
375
|
+
metaMeta.key
|
|
376
|
+
]
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
if (metaMeta.key === undefined) {
|
|
380
|
+
return previousMeta;
|
|
381
|
+
}
|
|
382
|
+
return {
|
|
383
|
+
...metaMeta,
|
|
384
|
+
keyPath: [
|
|
385
|
+
...previousMeta.keyPath,
|
|
386
|
+
metaMeta.key
|
|
387
|
+
]
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
exports.CaseValidator = CaseValidator;
|
|
393
|
+
exports.GITHUB_URL = GITHUB_URL;
|
|
394
|
+
exports.HostHTMLComponentTypes = HostHTMLComponentTypes;
|
|
395
|
+
exports.HostSVGComponentTypes = HostSVGComponentTypes;
|
|
396
|
+
exports.JSX_EXTENSIONS = JSX_EXTENSIONS;
|
|
397
|
+
exports.NPM_SCOPE = NPM_SCOPE;
|
|
398
|
+
exports.RE_JAVASCRIPT_PROTOCOL = RE_JAVASCRIPT_PROTOCOL;
|
|
399
|
+
exports.ReactHostHTMLComponent = ReactHostHTMLComponent;
|
|
400
|
+
exports.ReactHostSVGComponent = ReactHostSVGComponent;
|
|
401
|
+
exports.ReactHostWebComponent = ReactHostWebComponent;
|
|
402
|
+
exports.WEBSITE_URL = WEBSITE_URL;
|
|
403
|
+
exports.allComponents = allComponents;
|
|
404
|
+
exports.allFunctions = allFunctions;
|
|
405
|
+
exports.allValid = allValid;
|
|
406
|
+
exports.arrowFunctionComponent = arrowFunctionComponent;
|
|
407
|
+
exports.createElementComponent = createElementComponent;
|
|
408
|
+
exports.createRuleForPlugin = createRuleForPlugin;
|
|
409
|
+
exports.fn = fn;
|
|
410
|
+
exports.fnWithReturn = fnWithReturn;
|
|
411
|
+
exports.forwardRefComponent = forwardRefComponent;
|
|
412
|
+
exports.functionComponent = functionComponent;
|
|
413
|
+
exports.getCaseValidator = getCaseValidator;
|
|
414
|
+
exports.getRule = getRule;
|
|
415
|
+
exports.isHostHTMLComponentName = isHostHTMLComponentName;
|
|
416
|
+
exports.isHostSVGComponentName = isHostSVGComponentName;
|
|
417
|
+
exports.isHostWebComponentName = isHostWebComponentName;
|
|
418
|
+
exports.memoComponent = memoComponent;
|
|
419
|
+
exports.memoForwardRefComponent = memoForwardRefComponent;
|
|
420
|
+
exports.mergeConfigs = mergeConfigs;
|
|
421
|
+
exports.presetRules = presetRules;
|
|
422
|
+
exports.renderFunction = renderFunction;
|
|
423
|
+
exports.renderFunctionWithReturn = renderFunctionWithReturn;
|
|
424
|
+
exports.splitName = splitName;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
import * as deepmerge_ts from 'deepmerge-ts';
|
|
3
|
+
|
|
4
|
+
type RecommendationBuilder = (name: string) => string;
|
|
5
|
+
declare class CaseValidator {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(expression: RegExp, ignorePatterns: RegExp[], recommendationBuilder?: RecommendationBuilder);
|
|
8
|
+
getRecommendedName(name: string): string;
|
|
9
|
+
validate(name: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const getCaseValidator: (ruleName: string, ignorePattern?: string[]) => CaseValidator;
|
|
12
|
+
|
|
13
|
+
type Rule = {
|
|
14
|
+
expression: RegExp;
|
|
15
|
+
recommendationBuilder?: (name: string) => string;
|
|
16
|
+
};
|
|
17
|
+
type PresetRules = {
|
|
18
|
+
[key: string]: Required<Rule> | undefined;
|
|
19
|
+
PascalCase: Required<Rule>;
|
|
20
|
+
camelCase: Required<Rule>;
|
|
21
|
+
"kebab-case": Required<Rule>;
|
|
22
|
+
snake_case: Required<Rule>;
|
|
23
|
+
CONSTANT_CASE: Required<Rule>;
|
|
24
|
+
};
|
|
25
|
+
declare const presetRules: PresetRules;
|
|
26
|
+
declare const getRule: (expression: string, preset?: PresetRules) => Rule;
|
|
27
|
+
|
|
28
|
+
declare const splitName: (name: string) => string[];
|
|
29
|
+
|
|
30
|
+
declare const createElementComponent = "const CreateElementComponent = () => React.createElement('div', null, null)";
|
|
31
|
+
declare const arrowFunctionComponent = "const FunctionComponent = () => <div></div>";
|
|
32
|
+
declare const functionComponent: string;
|
|
33
|
+
declare const memoComponent: string;
|
|
34
|
+
declare const forwardRefComponent: string;
|
|
35
|
+
declare const memoForwardRefComponent: string;
|
|
36
|
+
declare const allComponents: readonly ["const FunctionComponent = () => <div></div>", string, "const CreateElementComponent = () => React.createElement('div', null, null)", string, string, string];
|
|
37
|
+
|
|
38
|
+
declare const fn = "const fn = () => null";
|
|
39
|
+
declare const fnWithReturn: string;
|
|
40
|
+
declare const renderFunction = "const renderFunction = (id: string, name: string) => <div key={id} id={id}>{name}</div>";
|
|
41
|
+
declare const renderFunctionWithReturn: string;
|
|
42
|
+
declare const allFunctions: readonly ["const fn = () => null", string, "const renderFunction = (id: string, name: string) => <div key={id} id={id}>{name}</div>", string];
|
|
43
|
+
|
|
44
|
+
declare const allValid: string[];
|
|
45
|
+
|
|
46
|
+
declare const NPM_SCOPE = "@eslint-react";
|
|
47
|
+
declare const GITHUB_URL = "https://github.com/rel1cx/eslint-react/blob/main";
|
|
48
|
+
declare const WEBSITE_URL = "https://eslint-react.xyz";
|
|
49
|
+
declare const JSX_EXTENSIONS: string[];
|
|
50
|
+
declare const RE_JAVASCRIPT_PROTOCOL: RegExp;
|
|
51
|
+
|
|
52
|
+
declare const createRuleForPlugin: (pluginName: string) => <TOptions extends readonly unknown[], TMessageIds extends string>({ name, meta, ...rule }: Readonly<ESLintUtils.RuleWithMetaAndName<TOptions, TMessageIds>>) => ESLintUtils.RuleModule<TMessageIds, TOptions, ESLintUtils.RuleListener>;
|
|
53
|
+
|
|
54
|
+
type ReactHostComponentType = 0 | 1 | 2;
|
|
55
|
+
declare const ReactHostHTMLComponent = 0;
|
|
56
|
+
declare const ReactHostSVGComponent = 1;
|
|
57
|
+
declare const ReactHostWebComponent = 2;
|
|
58
|
+
declare const HostHTMLComponentTypes: readonly ["aside", "audio", "b", "base", "bdi", "bdo", "blockquote", "body", "br", "button", "canvas", "caption", "cite", "code", "col", "colgroup", "data", "datalist", "dd", "del", "details", "dfn", "dialog", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "footer", "form", "h1", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "kbd", "label", "legend", "li", "link", "main", "map", "mark", "menu", "meta", "meter", "nav", "noscript", "object", "ol", "optgroup", "option", "output", "p", "picture", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "slot", "small", "source", "span", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "template", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "u", "ul", "var", "video", "wbr"];
|
|
59
|
+
declare const HostSVGComponentTypes: readonly ["a", "animate", "animateMotion", "animateTransform", "circle", "clipPath", "defs", "desc", "discard", "ellipse", "feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting", "feDisplacementMap", "feDistantLight", "feDropShadow", "feFlood", "feFuncA", "feFuncB", "feFuncG", "feFuncR", "feGaussianBlur", "feImage", "feMerge", "feMergeNode", "feMorphology", "feOffset", "fePointLight", "feSpecularLighting", "feSpotLight", "feTile", "feTurbulence", "filter", "foreignObject", "g", "hatch", "hatchpath", "image", "line", "linearGradient", "marker", "mask", "metadata", "mpath", "path", "pattern", "polygon", "polyline", "radialGradient", "rect", "script", "set", "stop", "style", "svg", "switch", "symbol", "text", "textPath", "title", "tspan", "use", "view"];
|
|
60
|
+
declare function isHostHTMLComponentName(name: string): boolean;
|
|
61
|
+
declare function isHostSVGComponentName(name: string): boolean;
|
|
62
|
+
declare function isHostWebComponentName(): void;
|
|
63
|
+
|
|
64
|
+
declare const mergeConfigs: <Ts extends readonly unknown[]>(...objects: Ts) => deepmerge_ts.DeepMergeHKT<Ts, Readonly<{
|
|
65
|
+
DeepMergeRecordsURI: "DeepMergeRecordsDefaultURI";
|
|
66
|
+
DeepMergeArraysURI: "DeepMergeArraysDefaultURI";
|
|
67
|
+
DeepMergeSetsURI: "DeepMergeSetsDefaultURI";
|
|
68
|
+
DeepMergeMapsURI: "DeepMergeMapsDefaultURI";
|
|
69
|
+
DeepMergeOthersURI: "DeepMergeLeafURI";
|
|
70
|
+
}>, {
|
|
71
|
+
keyPath: PropertyKey[];
|
|
72
|
+
}>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Rule application condition.
|
|
76
|
+
* @since 0.0.1
|
|
77
|
+
*/
|
|
78
|
+
type Cond = "always" | "never";
|
|
79
|
+
/**
|
|
80
|
+
* Rule severity.
|
|
81
|
+
* @since 0.0.1
|
|
82
|
+
*/
|
|
83
|
+
type Severity = "error" | "off" | "warn";
|
|
84
|
+
/**
|
|
85
|
+
* Rule declaration.
|
|
86
|
+
* @since 0.0.1
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
89
|
+
type RuleDeclaration = [Severity, Record<string, unknown>?] | Severity;
|
|
90
|
+
/**
|
|
91
|
+
* Rule config preset.
|
|
92
|
+
* @since 0.0.1
|
|
93
|
+
*/
|
|
94
|
+
type RulePreset = Record<string, RuleDeclaration>;
|
|
95
|
+
/**
|
|
96
|
+
* Rule creator function.
|
|
97
|
+
* @since 0.0.1
|
|
98
|
+
*/
|
|
99
|
+
type CreateRule = Parameters<ReturnType<typeof ESLintUtils.RuleCreator>>[0]["create"];
|
|
100
|
+
/**
|
|
101
|
+
* Rule context.
|
|
102
|
+
* @since 0.0.1
|
|
103
|
+
*/
|
|
104
|
+
type RuleContext = Parameters<CreateRule>[0];
|
|
105
|
+
/**
|
|
106
|
+
* Rule options.
|
|
107
|
+
* @since 0.0.1
|
|
108
|
+
*/
|
|
109
|
+
type RuleOptions = Parameters<CreateRule>[1];
|
|
110
|
+
|
|
111
|
+
type RuleCategory = "complexity" | "correctness" | "debug" | "deprecated" | "nursery" | "pedantic" | "perf" | "restriction" | "security" | "style" | "suspicious" | "verbose";
|
|
112
|
+
|
|
113
|
+
type Namespace = "debug" | "experimental" | "jsx" | "naming-convention" | "react" | "react-hooks";
|
|
114
|
+
type Ban = "ban";
|
|
115
|
+
type PositiveModifier = "ensure" | "prefer" | "strict";
|
|
116
|
+
type NegativeModifier = "no";
|
|
117
|
+
type NeutralModifier = "max" | "min";
|
|
118
|
+
type Modifier = NegativeModifier | NeutralModifier | PositiveModifier;
|
|
119
|
+
type NegativeDescriptive = "complicated" | "confusing" | "constructed" | "duplicate" | "empty" | "extra" | "falsely" | "implicit" | "invalid" | "leaked" | "legacy" | "missing" | "misused" | "mixing" | "nested" | "redundant" | "suppressing" | "suspicious" | "unknown" | "unreachable" | "unsafe" | "unsorted" | "unstable" | "unused" | "useless";
|
|
120
|
+
type PositiveDescriptive = "explicit" | "optimal" | "optimized" | "standard" | "strict";
|
|
121
|
+
type NeutralDescriptive = "access" | "calling" | "inside" | "outside";
|
|
122
|
+
type Descriptive = NegativeDescriptive | NeutralDescriptive | PositiveDescriptive;
|
|
123
|
+
type Term = "argument" | "array" | "array-index" | "arrow-function" | "attribute" | "callback" | "children" | "class" | "class-component" | "class-method" | "class-property" | "clone-element" | "comment" | "component" | "components" | "computed" | "computed-property" | "conditional-rendering" | "const" | "constant" | "constructor" | "context" | "context-consumer" | "context-provider" | "context-value" | "create-ref" | "custom-hooks" | "default-props" | "deps" | "destructuring" | "destructuring-assignment" | "direct-mutation" | "display-name" | "document" | "effect" | "element" | "error" | "event" | "event-handler" | "exhaustive-deps" | "expression" | "false" | "filename" | "forward-ref" | "fragment" | "function" | "function-component" | "function-name" | "global" | "handler" | "hook" | "html" | "id" | "index" | "input" | "key" | "list-rendering" | "literal" | "map" | "memo" | "memoized-function" | "method" | "name" | "namespace" | "node" | "parameter" | "prop" | "ref" | "render" | "return" | "spread" | "state" | "string" | "string-refs" | "style" | "textnodes" | "use-callback" | "use-context" | "use-effect" | "use-imperative-handle" | "use-layout-effect" | "use-memo" | "use-reducer" | "use-ref" | "use-state" | "value" | "variable";
|
|
124
|
+
type Additional = string;
|
|
125
|
+
type RuleName = `${Ban}-${Term}` | `${NeutralModifier}-${Term}` | `${NegativeModifier}-${NegativeDescriptive}-${Term}` | `${NegativeModifier}-${NeutralDescriptive}-${Term}` | `${PositiveModifier}-${NeutralDescriptive}-${Term}` | `${PositiveModifier}-${PositiveDescriptive}-${Term}`;
|
|
126
|
+
type RuleNameWithAdditional = `${RuleName}-${Additional}`;
|
|
127
|
+
|
|
128
|
+
export { type Additional, type Ban, CaseValidator, type Cond, type CreateRule, type Descriptive, GITHUB_URL, HostHTMLComponentTypes, HostSVGComponentTypes, JSX_EXTENSIONS, type Modifier, NPM_SCOPE, type Namespace, type NegativeDescriptive, type NegativeModifier, type NeutralDescriptive, type NeutralModifier, type PositiveDescriptive, type PositiveModifier, RE_JAVASCRIPT_PROTOCOL, type ReactHostComponentType, ReactHostHTMLComponent, ReactHostSVGComponent, ReactHostWebComponent, type RuleCategory, type RuleContext, type RuleDeclaration, type RuleName, type RuleNameWithAdditional, type RuleOptions, type RulePreset, type Severity, type Term, WEBSITE_URL, allComponents, allFunctions, allValid, arrowFunctionComponent, createElementComponent, createRuleForPlugin, fn, fnWithReturn, forwardRefComponent, functionComponent, getCaseValidator, getRule, isHostHTMLComponentName, isHostSVGComponentName, isHostWebComponentName, memoComponent, memoForwardRefComponent, mergeConfigs, presetRules, renderFunction, renderFunctionWithReturn, splitName };
|