eslint-plugin-react-dom 5.30.0-beta.4 → 5.30.0-beta.6
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.js +196 -217
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS, RE_JAVASCRIPT_PROTOCOL, getSettingsFromContext } from "@eslint-react/shared";
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
|
+
import { findAttribute, getAttributeStaticValue, getAttributeStaticValueByName, getAttributeValue, getAttributeValueByName, getElementFullType, hasAnyAttribute, hasAttribute, isEmptyExpressionContainer, isHostElement, isPaddingWhitespace, isPlainAttribute } from "@eslint-react/jsx";
|
|
3
4
|
import { getText } from "@eslint-react/eslint";
|
|
4
|
-
import { findAttribute, getAttributeStaticValue, getElementFullType, hasAnyAttribute, hasAttribute, isAttribute, isHostElement, isPaddingWhitespace, resolveAttributeValue } from "@eslint-react/jsx";
|
|
5
5
|
import { Check, Extract } from "@eslint-react/ast";
|
|
6
|
-
import { createImportLookup } from "@eslint-react/var";
|
|
7
6
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
7
|
+
import { createImportLookup } from "@eslint-react/var";
|
|
8
8
|
import { compare } from "compare-versions";
|
|
9
9
|
// \0rolldown/runtime.js
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
@@ -19,12 +19,16 @@ var __exportAll = (all, no_symbols) => {
|
|
|
19
19
|
};
|
|
20
20
|
// package.json
|
|
21
21
|
var name$2 = "eslint-plugin-react-dom";
|
|
22
|
-
var version = "5.30.0-beta.
|
|
22
|
+
var version = "5.30.0-beta.6";
|
|
23
23
|
// src/utils/create-rule.ts
|
|
24
24
|
function getDocsUrl(ruleName) {
|
|
25
25
|
return `https://eslint-react.xyz/docs/rules/dom-${ruleName}`;
|
|
26
26
|
}
|
|
27
27
|
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
28
|
+
// src/utils/is-child-content.ts
|
|
29
|
+
function isChildContent(child) {
|
|
30
|
+
return !isPaddingWhitespace(child) && !isEmptyExpressionContainer(child);
|
|
31
|
+
}
|
|
28
32
|
var no_dangerously_set_innerhtml_with_children_default = createRule({
|
|
29
33
|
meta: {
|
|
30
34
|
type: "problem",
|
|
@@ -38,8 +42,8 @@ var no_dangerously_set_innerhtml_with_children_default = createRule({
|
|
|
38
42
|
function create$15(context) {
|
|
39
43
|
if (!context.sourceCode.text.includes("dangerouslySetInnerHTML")) return {};
|
|
40
44
|
return { JSXElement(node) {
|
|
41
|
-
if (!hasAttribute(
|
|
42
|
-
const fact = findAttribute(
|
|
45
|
+
if (!hasAttribute(node, "dangerouslySetInnerHTML")) return;
|
|
46
|
+
const fact = findAttribute(node, "children") ?? node.children.find(isChildContent);
|
|
43
47
|
if (fact == null) return;
|
|
44
48
|
context.report({
|
|
45
49
|
messageId: "default",
|
|
@@ -60,7 +64,7 @@ var no_dangerously_set_innerhtml_default = createRule({
|
|
|
60
64
|
function create$14(context) {
|
|
61
65
|
if (!context.sourceCode.text.includes("dangerouslySetInnerHTML")) return {};
|
|
62
66
|
return { JSXElement(node) {
|
|
63
|
-
const prop = findAttribute(
|
|
67
|
+
const prop = findAttribute(node, "dangerouslySetInnerHTML");
|
|
64
68
|
if (prop == null) return;
|
|
65
69
|
context.report({
|
|
66
70
|
messageId: "default",
|
|
@@ -68,6 +72,12 @@ function create$14(context) {
|
|
|
68
72
|
});
|
|
69
73
|
} };
|
|
70
74
|
}
|
|
75
|
+
// src/utils/is-react-dom-call.ts
|
|
76
|
+
function isReactDOMCall(node, imports, api, allowGlobalDirect = false) {
|
|
77
|
+
const callee = Extract.unwrap(node.callee);
|
|
78
|
+
if (Check.isIdentifier(callee)) return allowGlobalDirect && callee.name === api || imports.has(callee.name, api);
|
|
79
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === api && imports.isModuleBinding(callee.object.name);
|
|
80
|
+
}
|
|
71
81
|
var no_find_dom_node_default = createRule({
|
|
72
82
|
meta: {
|
|
73
83
|
type: "problem",
|
|
@@ -85,21 +95,11 @@ function create$13(context) {
|
|
|
85
95
|
source: "react-dom"
|
|
86
96
|
});
|
|
87
97
|
return { CallExpression(node) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
node
|
|
94
|
-
});
|
|
95
|
-
return;
|
|
96
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "findDOMNode" && imports.hasNamespace(callee.object.name):
|
|
97
|
-
context.report({
|
|
98
|
-
messageId: "default",
|
|
99
|
-
node
|
|
100
|
-
});
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
98
|
+
if (!isReactDOMCall(node, imports, "findDOMNode", true)) return;
|
|
99
|
+
context.report({
|
|
100
|
+
messageId: "default",
|
|
101
|
+
node
|
|
102
|
+
});
|
|
103
103
|
} };
|
|
104
104
|
}
|
|
105
105
|
var no_flush_sync_default = createRule({
|
|
@@ -116,21 +116,11 @@ function create$12(context) {
|
|
|
116
116
|
if (!context.sourceCode.text.includes("flushSync")) return {};
|
|
117
117
|
const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
|
|
118
118
|
return { CallExpression(node) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
node
|
|
125
|
-
});
|
|
126
|
-
return;
|
|
127
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "flushSync" && imports.hasNamespace(callee.object.name):
|
|
128
|
-
context.report({
|
|
129
|
-
messageId: "default",
|
|
130
|
-
node
|
|
131
|
-
});
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
119
|
+
if (!isReactDOMCall(node, imports, "flushSync")) return;
|
|
120
|
+
context.report({
|
|
121
|
+
messageId: "default",
|
|
122
|
+
node
|
|
123
|
+
});
|
|
134
124
|
} };
|
|
135
125
|
}
|
|
136
126
|
var no_hydrate_default = createRule({
|
|
@@ -146,27 +136,16 @@ var no_hydrate_default = createRule({
|
|
|
146
136
|
});
|
|
147
137
|
function create$11(context) {
|
|
148
138
|
if (!context.sourceCode.text.includes("hydrate")) return {};
|
|
149
|
-
const
|
|
150
|
-
if (compare(
|
|
139
|
+
const { version } = getSettingsFromContext(context);
|
|
140
|
+
if (compare(version, "18.0.0", "<")) return {};
|
|
151
141
|
const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
|
|
152
142
|
return { CallExpression(node) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
node
|
|
160
|
-
});
|
|
161
|
-
return;
|
|
162
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "hydrate" && imports.hasNamespace(callee.object.name):
|
|
163
|
-
context.report({
|
|
164
|
-
fix: buildFix$2(context, node),
|
|
165
|
-
messageId: "default",
|
|
166
|
-
node
|
|
167
|
-
});
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
143
|
+
if (!isReactDOMCall(node, imports, "hydrate")) return;
|
|
144
|
+
context.report({
|
|
145
|
+
fix: buildFix$2(context, node),
|
|
146
|
+
messageId: "default",
|
|
147
|
+
node
|
|
148
|
+
});
|
|
170
149
|
} };
|
|
171
150
|
}
|
|
172
151
|
function buildFix$2(context, node) {
|
|
@@ -256,6 +235,12 @@ function isObjectKeyword(input) {
|
|
|
256
235
|
return typeof input === "object" && input !== null || isFunction(input);
|
|
257
236
|
}
|
|
258
237
|
dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
238
|
+
function getOrInsertComputed(map, key, callback) {
|
|
239
|
+
if (map.has(key)) return map.get(key);
|
|
240
|
+
const value = callback(key);
|
|
241
|
+
map.set(key, value);
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
259
244
|
dual(2, (self, predicate) => {
|
|
260
245
|
const input = Array.isArray(self) ? self : Array.from(self);
|
|
261
246
|
const len = input.length;
|
|
@@ -281,7 +266,7 @@ function createJSXElementResolver(context) {
|
|
|
281
266
|
};
|
|
282
267
|
const nameNode = node.openingElement.name;
|
|
283
268
|
if (nameNode.type === AST_NODE_TYPES.JSXIdentifier && nameNode.name.charAt(0) === nameNode.name.charAt(0).toLowerCase()) return result;
|
|
284
|
-
const polyPropValue =
|
|
269
|
+
const polyPropValue = getAttributeStaticValueByName(context, node, polymorphicPropName);
|
|
285
270
|
if (isString(polyPropValue)) return {
|
|
286
271
|
...result,
|
|
287
272
|
domElementType: polyPropValue.toLowerCase()
|
|
@@ -314,21 +299,25 @@ function create$10(context) {
|
|
|
314
299
|
const resolver = createJSXElementResolver(context);
|
|
315
300
|
return { JSXElement(node) {
|
|
316
301
|
const { domElementType } = resolver.resolve(node);
|
|
317
|
-
if (domElementType !== "button") return;
|
|
318
|
-
|
|
302
|
+
if (domElementType !== "button" || hasAttribute(node, "type")) return;
|
|
303
|
+
const suggest = BUTTON_TYPES.map((type) => ({
|
|
304
|
+
data: { type },
|
|
305
|
+
fix(fixer) {
|
|
306
|
+
return fixer.insertTextAfter(node.openingElement.name, ` type="${type}"`);
|
|
307
|
+
},
|
|
308
|
+
messageId: "suggest"
|
|
309
|
+
}));
|
|
319
310
|
context.report({
|
|
320
311
|
messageId: "default",
|
|
321
312
|
node: node.openingElement,
|
|
322
|
-
suggest
|
|
323
|
-
data: { type },
|
|
324
|
-
fix(fixer) {
|
|
325
|
-
return fixer.insertTextAfter(node.openingElement.name, ` type="${type}"`);
|
|
326
|
-
},
|
|
327
|
-
messageId: "suggest"
|
|
328
|
-
}))
|
|
313
|
+
suggest
|
|
329
314
|
});
|
|
330
315
|
} };
|
|
331
316
|
}
|
|
317
|
+
// src/utils/get-attribute-report-node.ts
|
|
318
|
+
function getAttributeReportNode(value) {
|
|
319
|
+
return value.node ?? value.attribute;
|
|
320
|
+
}
|
|
332
321
|
var no_missing_iframe_sandbox_default = createRule({
|
|
333
322
|
meta: {
|
|
334
323
|
type: "problem",
|
|
@@ -349,8 +338,8 @@ function create$9(context) {
|
|
|
349
338
|
return { JSXElement(node) {
|
|
350
339
|
const { domElementType } = resolver.resolve(node);
|
|
351
340
|
if (domElementType !== "iframe") return;
|
|
352
|
-
const
|
|
353
|
-
if (
|
|
341
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
342
|
+
if (sandboxValue == null) {
|
|
354
343
|
context.report({
|
|
355
344
|
messageId: "default",
|
|
356
345
|
node: node.openingElement,
|
|
@@ -364,31 +353,20 @@ function create$9(context) {
|
|
|
364
353
|
});
|
|
365
354
|
return;
|
|
366
355
|
}
|
|
367
|
-
|
|
368
|
-
if (isString(sandboxValue.toStatic())) return;
|
|
356
|
+
if (isString(getAttributeStaticValue(context, sandboxValue))) return;
|
|
369
357
|
context.report({
|
|
370
358
|
messageId: "default",
|
|
371
|
-
node: sandboxValue
|
|
359
|
+
node: getAttributeReportNode(sandboxValue),
|
|
372
360
|
suggest: [{
|
|
373
361
|
data: { value: "" },
|
|
374
362
|
fix(fixer) {
|
|
375
|
-
|
|
376
|
-
return fixer.replaceText(sandboxProp, `sandbox=""`);
|
|
363
|
+
return fixer.replaceText(sandboxValue.attribute, `sandbox=""`);
|
|
377
364
|
},
|
|
378
365
|
messageId: "suggest"
|
|
379
366
|
}]
|
|
380
367
|
});
|
|
381
368
|
} };
|
|
382
369
|
}
|
|
383
|
-
// src/rules/no-render-return-value/no-render-return-value.ts
|
|
384
|
-
const RULE_NAME$8 = "no-render-return-value";
|
|
385
|
-
const BANNED_PARENT_TYPES = [
|
|
386
|
-
AST_NODE_TYPES.VariableDeclarator,
|
|
387
|
-
AST_NODE_TYPES.Property,
|
|
388
|
-
AST_NODE_TYPES.ReturnStatement,
|
|
389
|
-
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
390
|
-
AST_NODE_TYPES.AssignmentExpression
|
|
391
|
-
];
|
|
392
370
|
var no_render_return_value_default = createRule({
|
|
393
371
|
meta: {
|
|
394
372
|
type: "problem",
|
|
@@ -396,7 +374,7 @@ var no_render_return_value_default = createRule({
|
|
|
396
374
|
messages: { default: "Do not depend on the return value from 'ReactDOM.render'." },
|
|
397
375
|
schema: []
|
|
398
376
|
},
|
|
399
|
-
name:
|
|
377
|
+
name: "no-render-return-value",
|
|
400
378
|
create: create$8
|
|
401
379
|
});
|
|
402
380
|
function create$8(context) {
|
|
@@ -406,23 +384,20 @@ function create$8(context) {
|
|
|
406
384
|
source: "react-dom"
|
|
407
385
|
});
|
|
408
386
|
return { CallExpression(node) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
node
|
|
415
|
-
});
|
|
416
|
-
return;
|
|
417
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "render" && imports.hasNamespace(callee.object.name) && isReturnValueUsed(node):
|
|
418
|
-
context.report({
|
|
419
|
-
messageId: "default",
|
|
420
|
-
node
|
|
421
|
-
});
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
387
|
+
if (!isReactDOMCall(node, imports, "render") || !isReturnValueUsed(node)) return;
|
|
388
|
+
context.report({
|
|
389
|
+
messageId: "default",
|
|
390
|
+
node
|
|
391
|
+
});
|
|
424
392
|
} };
|
|
425
393
|
}
|
|
394
|
+
const BANNED_PARENT_TYPES = [
|
|
395
|
+
AST_NODE_TYPES.VariableDeclarator,
|
|
396
|
+
AST_NODE_TYPES.Property,
|
|
397
|
+
AST_NODE_TYPES.ReturnStatement,
|
|
398
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
399
|
+
AST_NODE_TYPES.AssignmentExpression
|
|
400
|
+
];
|
|
426
401
|
function isReturnValueUsed(node) {
|
|
427
402
|
let parent = node.parent;
|
|
428
403
|
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
@@ -441,30 +416,19 @@ var no_render_default = createRule({
|
|
|
441
416
|
});
|
|
442
417
|
function create$7(context) {
|
|
443
418
|
if (!context.sourceCode.text.includes("render")) return {};
|
|
444
|
-
const
|
|
445
|
-
if (compare(
|
|
419
|
+
const { version } = getSettingsFromContext(context);
|
|
420
|
+
if (compare(version, "18.0.0", "<")) return {};
|
|
446
421
|
const imports = createImportLookup(context.sourceCode.ast, {
|
|
447
422
|
builtinNamespaces: ["ReactDOM"],
|
|
448
423
|
source: "react-dom"
|
|
449
424
|
});
|
|
450
425
|
return { CallExpression(node) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
node
|
|
458
|
-
});
|
|
459
|
-
return;
|
|
460
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "render" && imports.hasNamespace(callee.object.name):
|
|
461
|
-
context.report({
|
|
462
|
-
fix: buildFix$1(context, node),
|
|
463
|
-
messageId: "default",
|
|
464
|
-
node
|
|
465
|
-
});
|
|
466
|
-
return;
|
|
467
|
-
}
|
|
426
|
+
if (!isReactDOMCall(node, imports, "render")) return;
|
|
427
|
+
context.report({
|
|
428
|
+
fix: buildFix$1(context, node),
|
|
429
|
+
messageId: "default",
|
|
430
|
+
node
|
|
431
|
+
});
|
|
468
432
|
} };
|
|
469
433
|
}
|
|
470
434
|
function buildFix$1(context, node) {
|
|
@@ -486,8 +450,8 @@ var no_script_url_default = createRule({
|
|
|
486
450
|
});
|
|
487
451
|
function create$6(context) {
|
|
488
452
|
return { JSXAttribute(node) {
|
|
489
|
-
if (node.
|
|
490
|
-
const value =
|
|
453
|
+
if (node.value == null) return;
|
|
454
|
+
const value = getAttributeStaticValue(context, getAttributeValue(node));
|
|
491
455
|
if (isString(value) && RE_JAVASCRIPT_PROTOCOL.test(value)) context.report({
|
|
492
456
|
messageId: "default",
|
|
493
457
|
node: node.value
|
|
@@ -507,13 +471,12 @@ var no_string_style_prop_default = createRule({
|
|
|
507
471
|
function create$5(context) {
|
|
508
472
|
return { JSXElement(node) {
|
|
509
473
|
if (!isHostElement(node)) return;
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
if (!isString(styleValue.toStatic())) return;
|
|
474
|
+
const styleValue = getAttributeValueByName(node, "style");
|
|
475
|
+
if (styleValue == null) return;
|
|
476
|
+
if (!isString(getAttributeStaticValue(context, styleValue))) return;
|
|
514
477
|
context.report({
|
|
515
478
|
messageId: "default",
|
|
516
|
-
node: styleValue
|
|
479
|
+
node: getAttributeReportNode(styleValue)
|
|
517
480
|
});
|
|
518
481
|
} };
|
|
519
482
|
}
|
|
@@ -1420,37 +1383,55 @@ const REACT_19_3_PROPS = [
|
|
|
1420
1383
|
];
|
|
1421
1384
|
const REACT_19_3_ATTRIBUTE_TAGS_MAP = { credentialless: ["iframe"] };
|
|
1422
1385
|
const REACT_19_3_SVGDOM_ATTRIBUTE_NAMES = { "mask-type": "maskType" };
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
return
|
|
1386
|
+
const VERSION_CACHE_KEY_CACHE = /* @__PURE__ */ new Map();
|
|
1387
|
+
function getVersionCacheKey(version) {
|
|
1388
|
+
return getOrInsertComputed(VERSION_CACHE_KEY_CACHE, version, (v) => [
|
|
1389
|
+
compare(v, "16.1.0", "<="),
|
|
1390
|
+
compare(v, "16.4.0", ">="),
|
|
1391
|
+
compare(v, "19.0.0-rc.0", ">="),
|
|
1392
|
+
compare(v, "19.3.0", ">=")
|
|
1393
|
+
].map(Number).join(""));
|
|
1426
1394
|
}
|
|
1427
|
-
function
|
|
1428
|
-
const
|
|
1429
|
-
if (
|
|
1430
|
-
|
|
1431
|
-
return
|
|
1395
|
+
function buildDOMPropertyNames(version) {
|
|
1396
|
+
const names = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
|
|
1397
|
+
if (compare(version, "16.1.0", "<=")) {
|
|
1398
|
+
names.push("allowTransparency");
|
|
1399
|
+
return names;
|
|
1432
1400
|
}
|
|
1433
|
-
if (
|
|
1434
|
-
if (
|
|
1435
|
-
else
|
|
1436
|
-
if (
|
|
1437
|
-
return
|
|
1401
|
+
if (compare(version, "16.4.0", ">=")) names.push(...REACT_ON_PROPS);
|
|
1402
|
+
if (compare(version, "19.0.0-rc.0", ">=")) names.push(...REACT_19_PROPS);
|
|
1403
|
+
else names.push(...REACT_19_PROPS.map((prop) => prop.toLowerCase()));
|
|
1404
|
+
if (compare(version, "19.3.0", ">=")) names.push(...REACT_19_3_PROPS);
|
|
1405
|
+
return names;
|
|
1438
1406
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1407
|
+
const ATTRIBUTE_TAGS_MAP_CACHE = /* @__PURE__ */ new Map();
|
|
1408
|
+
function buildAttributeTagsMap(version) {
|
|
1409
|
+
let map = ATTRIBUTE_TAGS_MAP;
|
|
1410
|
+
if (compare(version, "19.0.0-rc.0", ">=")) map = {
|
|
1411
|
+
...map,
|
|
1443
1412
|
...REACT_19_ATTRIBUTE_TAGS_MAP
|
|
1444
1413
|
};
|
|
1445
|
-
if (
|
|
1446
|
-
...
|
|
1414
|
+
if (compare(version, "19.3.0", ">=")) map = {
|
|
1415
|
+
...map,
|
|
1447
1416
|
...REACT_19_3_ATTRIBUTE_TAGS_MAP
|
|
1448
1417
|
};
|
|
1449
|
-
return
|
|
1418
|
+
return map;
|
|
1419
|
+
}
|
|
1420
|
+
function getAttributeTagsMapForVersion(version) {
|
|
1421
|
+
return getOrInsertComputed(ATTRIBUTE_TAGS_MAP_CACHE, getVersionCacheKey(version), () => buildAttributeTagsMap(version));
|
|
1450
1422
|
}
|
|
1423
|
+
function getAttributeTagsMap(context) {
|
|
1424
|
+
const { version } = getSettingsFromContext(context);
|
|
1425
|
+
return getAttributeTagsMapForVersion(version);
|
|
1426
|
+
}
|
|
1427
|
+
const HTML_TAG_VALIDITY_CACHE = /* @__PURE__ */ new WeakMap();
|
|
1451
1428
|
function isValidHTMLTagInJSX(childNode) {
|
|
1452
|
-
|
|
1453
|
-
|
|
1429
|
+
const openingElement = childNode.parent;
|
|
1430
|
+
const cached = HTML_TAG_VALIDITY_CACHE.get(openingElement);
|
|
1431
|
+
if (cached != null) return cached;
|
|
1432
|
+
const isValid = openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z][^-]*$/.test(openingElement.name.name) && !openingElement.attributes.some(isPlainAttribute("is"));
|
|
1433
|
+
HTML_TAG_VALIDITY_CACHE.set(openingElement, isValid);
|
|
1434
|
+
return isValid;
|
|
1454
1435
|
}
|
|
1455
1436
|
function normalizeAttributeCase(name) {
|
|
1456
1437
|
return DOM_PROPERTIES_IGNORE_CASE.find((element) => element.toLowerCase() === name.toLowerCase()) ?? name;
|
|
@@ -1474,14 +1455,29 @@ function tagNameHasDot(node) {
|
|
|
1474
1455
|
function has(obj, key) {
|
|
1475
1456
|
return Object.hasOwn(obj, key);
|
|
1476
1457
|
}
|
|
1458
|
+
const STANDARD_NAME_LOOKUP_CACHE = /* @__PURE__ */ new Map();
|
|
1459
|
+
function getStandardNameLookup(version) {
|
|
1460
|
+
return getOrInsertComputed(STANDARD_NAME_LOOKUP_CACHE, getVersionCacheKey(version), () => {
|
|
1461
|
+
const svgAttributeNames = compare(version, "19.3.0", ">=") ? {
|
|
1462
|
+
...SVGDOM_ATTRIBUTE_NAMES,
|
|
1463
|
+
...REACT_19_3_SVGDOM_ATTRIBUTE_NAMES
|
|
1464
|
+
} : SVGDOM_ATTRIBUTE_NAMES;
|
|
1465
|
+
const exact = new Map([...Object.entries(svgAttributeNames), ...Object.entries(DOM_ATTRIBUTE_NAMES)]);
|
|
1466
|
+
const lower = /* @__PURE__ */ new Map();
|
|
1467
|
+
for (const propertyName of buildDOMPropertyNames(version)) {
|
|
1468
|
+
const key = propertyName.toLowerCase();
|
|
1469
|
+
if (!lower.has(key)) lower.set(key, propertyName);
|
|
1470
|
+
}
|
|
1471
|
+
return {
|
|
1472
|
+
exact,
|
|
1473
|
+
lower
|
|
1474
|
+
};
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
1477
|
function getStandardName(name, context) {
|
|
1478
|
-
|
|
1479
|
-
const
|
|
1480
|
-
|
|
1481
|
-
...REACT_19_3_SVGDOM_ATTRIBUTE_NAMES
|
|
1482
|
-
} : SVGDOM_ATTRIBUTE_NAMES;
|
|
1483
|
-
if (has(svgAttributeNames, name)) return svgAttributeNames[name] ?? null;
|
|
1484
|
-
return getDOMPropertyNames(context).find((element) => element.toLowerCase() === name.toLowerCase()) ?? null;
|
|
1478
|
+
const { version } = getSettingsFromContext(context);
|
|
1479
|
+
const lookup = getStandardNameLookup(version);
|
|
1480
|
+
return lookup.exact.get(name) ?? lookup.lower.get(name.toLowerCase()) ?? null;
|
|
1485
1481
|
}
|
|
1486
1482
|
// src/rules/no-unknown-property/no-unknown-property.ts
|
|
1487
1483
|
const RULE_NAME$4 = "no-unknown-property";
|
|
@@ -1521,20 +1517,15 @@ var no_unknown_property_default = createRule({
|
|
|
1521
1517
|
create: create$4
|
|
1522
1518
|
});
|
|
1523
1519
|
function create$4(context) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
1527
|
-
function getRequireDataLowercase() {
|
|
1528
|
-
return context.options[0]?.requireDataLowercase ?? DEFAULTS.requireDataLowercase;
|
|
1529
|
-
}
|
|
1520
|
+
const { ignore = DEFAULTS.ignore, requireDataLowercase = DEFAULTS.requireDataLowercase } = context.options[0] ?? DEFAULTS;
|
|
1521
|
+
let attributeTagsMap = null;
|
|
1530
1522
|
return { JSXAttribute(node) {
|
|
1531
|
-
const ignoreNames = getIgnoreConfig();
|
|
1532
1523
|
const actualName = getText(context, node.name);
|
|
1533
|
-
if (
|
|
1524
|
+
if (ignore.includes(actualName)) return;
|
|
1534
1525
|
const name = normalizeAttributeCase(actualName);
|
|
1535
1526
|
if (tagNameHasDot(node)) return;
|
|
1536
1527
|
if (isValidDataAttribute(name)) {
|
|
1537
|
-
if (
|
|
1528
|
+
if (requireDataLowercase && hasUpperCaseCharacter(name)) context.report({
|
|
1538
1529
|
data: {
|
|
1539
1530
|
name: actualName,
|
|
1540
1531
|
lowerCaseName: actualName.toLowerCase()
|
|
@@ -1548,8 +1539,8 @@ function create$4(context) {
|
|
|
1548
1539
|
const tagName = getTagName(node);
|
|
1549
1540
|
if (tagName === "fbt" || tagName === "fbs") return;
|
|
1550
1541
|
if (!isValidHTMLTagInJSX(node)) return;
|
|
1551
|
-
const
|
|
1552
|
-
const allowedTags = has(
|
|
1542
|
+
const tagsMap = attributeTagsMap ??= getAttributeTagsMap(context);
|
|
1543
|
+
const allowedTags = has(tagsMap, name) ? tagsMap[name] : null;
|
|
1553
1544
|
if (tagName != null && allowedTags != null) {
|
|
1554
1545
|
if (!allowedTags.includes(tagName)) context.report({
|
|
1555
1546
|
data: {
|
|
@@ -1563,25 +1554,24 @@ function create$4(context) {
|
|
|
1563
1554
|
return;
|
|
1564
1555
|
}
|
|
1565
1556
|
const standardName = getStandardName(name, context);
|
|
1566
|
-
|
|
1567
|
-
if (standardName != null && standardName === name) return;
|
|
1568
|
-
if (hasStandardNameButIsNotUsed) {
|
|
1557
|
+
if (standardName == null) {
|
|
1569
1558
|
context.report({
|
|
1570
|
-
data: {
|
|
1571
|
-
|
|
1572
|
-
standardName
|
|
1573
|
-
},
|
|
1574
|
-
fix(fixer) {
|
|
1575
|
-
return fixer.replaceText(node.name, standardName);
|
|
1576
|
-
},
|
|
1577
|
-
messageId: "unknown-prop-with-standard-name",
|
|
1559
|
+
data: { name: actualName },
|
|
1560
|
+
messageId: "unknown-prop",
|
|
1578
1561
|
node
|
|
1579
1562
|
});
|
|
1580
1563
|
return;
|
|
1581
1564
|
}
|
|
1565
|
+
if (standardName === name) return;
|
|
1582
1566
|
context.report({
|
|
1583
|
-
data: {
|
|
1584
|
-
|
|
1567
|
+
data: {
|
|
1568
|
+
name: actualName,
|
|
1569
|
+
standardName
|
|
1570
|
+
},
|
|
1571
|
+
fix(fixer) {
|
|
1572
|
+
return fixer.replaceText(node.name, standardName);
|
|
1573
|
+
},
|
|
1574
|
+
messageId: "unknown-prop-with-standard-name",
|
|
1585
1575
|
node
|
|
1586
1576
|
});
|
|
1587
1577
|
} };
|
|
@@ -1604,14 +1594,13 @@ function create$3(context) {
|
|
|
1604
1594
|
return { JSXElement(node) {
|
|
1605
1595
|
const { domElementType } = resolver.resolve(node);
|
|
1606
1596
|
if (domElementType !== "iframe") return;
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1609
|
-
const
|
|
1610
|
-
const value = sandboxValue.toStatic();
|
|
1597
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
1598
|
+
if (sandboxValue == null) return;
|
|
1599
|
+
const value = getAttributeStaticValue(context, sandboxValue);
|
|
1611
1600
|
if (!isString(value) || !UNSAFE_SANDBOX_VALUES.every((a) => value.includes(a))) return;
|
|
1612
1601
|
context.report({
|
|
1613
1602
|
messageId: "default",
|
|
1614
|
-
node: sandboxValue
|
|
1603
|
+
node: getAttributeReportNode(sandboxValue)
|
|
1615
1604
|
});
|
|
1616
1605
|
} };
|
|
1617
1606
|
}
|
|
@@ -1657,37 +1646,39 @@ function create$2(context) {
|
|
|
1657
1646
|
const { allowReferrer = false } = context.options[0] ?? defaultOptions[0];
|
|
1658
1647
|
const resolver = createJSXElementResolver(context);
|
|
1659
1648
|
const requiredRelAttribute = `rel="${allowReferrer ? "noopener" : "noreferrer"}"`;
|
|
1660
|
-
function buildSuggest(fix) {
|
|
1661
|
-
return [{
|
|
1662
|
-
data: { rel: requiredRelAttribute },
|
|
1663
|
-
fix,
|
|
1664
|
-
messageId: "suggest"
|
|
1665
|
-
}];
|
|
1666
|
-
}
|
|
1667
1649
|
return { JSXElement(node) {
|
|
1668
1650
|
const { domElementType } = resolver.resolve(node);
|
|
1669
1651
|
if (domElementType !== "a") return;
|
|
1670
|
-
if (
|
|
1671
|
-
if (!isExternalLinkLike(
|
|
1672
|
-
const
|
|
1673
|
-
if (
|
|
1652
|
+
if (getAttributeStaticValueByName(context, node, "target") !== "_blank") return;
|
|
1653
|
+
if (!isExternalLinkLike(getAttributeStaticValueByName(context, node, "href"))) return;
|
|
1654
|
+
const relValue = getAttributeValueByName(node, "rel");
|
|
1655
|
+
if (relValue == null) {
|
|
1656
|
+
const lastAttribute = node.openingElement.attributes.at(-1);
|
|
1674
1657
|
context.report({
|
|
1675
1658
|
messageId: "default",
|
|
1676
1659
|
data: { rel: requiredRelAttribute },
|
|
1677
1660
|
node: node.openingElement,
|
|
1678
|
-
suggest: buildSuggest((fixer) => fixer.insertTextAfter(node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1661
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.insertTextAfter(lastAttribute ?? node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1679
1662
|
});
|
|
1680
1663
|
return;
|
|
1681
1664
|
}
|
|
1682
|
-
|
|
1665
|
+
const relAttribute = relValue.attribute;
|
|
1666
|
+
if (isSafeRel(getAttributeStaticValue(context, relValue), allowReferrer)) return;
|
|
1683
1667
|
context.report({
|
|
1684
1668
|
messageId: "default",
|
|
1685
1669
|
data: { rel: requiredRelAttribute },
|
|
1686
1670
|
node: relAttribute,
|
|
1687
|
-
suggest: buildSuggest((fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1671
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1688
1672
|
});
|
|
1689
1673
|
} };
|
|
1690
1674
|
}
|
|
1675
|
+
function buildSuggest(relAttribute, fix) {
|
|
1676
|
+
return [{
|
|
1677
|
+
data: { rel: relAttribute },
|
|
1678
|
+
fix,
|
|
1679
|
+
messageId: "suggest"
|
|
1680
|
+
}];
|
|
1681
|
+
}
|
|
1691
1682
|
var no_use_form_state_default = createRule({
|
|
1692
1683
|
meta: {
|
|
1693
1684
|
type: "problem",
|
|
@@ -1701,31 +1692,19 @@ var no_use_form_state_default = createRule({
|
|
|
1701
1692
|
});
|
|
1702
1693
|
function create$1(context) {
|
|
1703
1694
|
if (!context.sourceCode.text.includes("useFormState")) return {};
|
|
1704
|
-
const
|
|
1705
|
-
if (compare(
|
|
1695
|
+
const { importSource, version } = getSettingsFromContext(context);
|
|
1696
|
+
if (compare(version, "19.0.0", "<")) return {};
|
|
1706
1697
|
const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
|
|
1707
1698
|
return { CallExpression(node) {
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
node
|
|
1715
|
-
});
|
|
1716
|
-
return;
|
|
1717
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "useFormState" && imports.hasNamespace(callee.object.name):
|
|
1718
|
-
context.report({
|
|
1719
|
-
fix: buildFix(context, node),
|
|
1720
|
-
messageId: "default",
|
|
1721
|
-
node
|
|
1722
|
-
});
|
|
1723
|
-
return;
|
|
1724
|
-
}
|
|
1699
|
+
if (!isReactDOMCall(node, imports, "useFormState")) return;
|
|
1700
|
+
context.report({
|
|
1701
|
+
fix: buildFix(context, node, importSource),
|
|
1702
|
+
messageId: "default",
|
|
1703
|
+
node
|
|
1704
|
+
});
|
|
1725
1705
|
} };
|
|
1726
1706
|
}
|
|
1727
|
-
function buildFix(context, node) {
|
|
1728
|
-
const { importSource } = getSettingsFromContext(context);
|
|
1707
|
+
function buildFix(context, node, importSource) {
|
|
1729
1708
|
return (fixer) => {
|
|
1730
1709
|
return [fixer.insertTextBefore(context.sourceCode.ast, `import { useActionState } from "${importSource}";\n`), fixer.replaceText(node.callee, "useActionState")];
|
|
1731
1710
|
};
|
|
@@ -1764,7 +1743,7 @@ function create(context) {
|
|
|
1764
1743
|
return { JSXElement(node) {
|
|
1765
1744
|
const { domElementType } = resolver.resolve(node);
|
|
1766
1745
|
if (!KNOWN_VOID_ELEMENTS.has(domElementType)) return;
|
|
1767
|
-
if (node.children.
|
|
1746
|
+
if (node.children.some(isChildContent) || hasAnyAttribute(node, ["children", "dangerouslySetInnerHTML"])) context.report({
|
|
1768
1747
|
data: { elementType: domElementType },
|
|
1769
1748
|
messageId: "default",
|
|
1770
1749
|
node
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-dom",
|
|
3
|
-
"version": "5.30.0-beta.
|
|
3
|
+
"version": "5.30.0-beta.6",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for DOM related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@eslint-react/ast": "5.30.0-beta.
|
|
41
|
-
"@eslint-react/eslint": "5.30.0-beta.
|
|
42
|
-
"@eslint-react/jsx": "5.30.0-beta.
|
|
43
|
-
"@eslint-react/shared": "5.30.0-beta.
|
|
44
|
-
"@eslint-react/var": "5.30.0-beta.
|
|
45
|
-
"@typescript-eslint/types": "^8.72.
|
|
46
|
-
"@typescript-eslint/utils": "^8.72.
|
|
40
|
+
"@eslint-react/ast": "5.30.0-beta.6",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.6",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.6",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.6",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.6",
|
|
45
|
+
"@typescript-eslint/types": "^8.72.1",
|
|
46
|
+
"@typescript-eslint/utils": "^8.72.1",
|
|
47
47
|
"compare-versions": "^6.1.1",
|
|
48
48
|
"ts-pattern": "^5.9.2"
|
|
49
49
|
},
|