eslint-plugin-react-dom 5.30.0-beta.1 → 5.30.0-beta.10
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 +211 -241
- 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.10";
|
|
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,25 +1455,34 @@ 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
|
-
// src/rules/no-unknown-property/no-unknown-property.ts
|
|
1487
|
-
const RULE_NAME$4 = "no-unknown-property";
|
|
1488
|
-
const DEFAULTS = {
|
|
1489
|
-
ignore: [],
|
|
1490
|
-
requireDataLowercase: false
|
|
1491
|
-
};
|
|
1492
1482
|
var no_unknown_property_default = createRule({
|
|
1493
1483
|
meta: {
|
|
1494
1484
|
type: "problem",
|
|
1495
|
-
defaultOptions: [
|
|
1485
|
+
defaultOptions: [{}],
|
|
1496
1486
|
docs: { description: "Disallows unknown 'DOM' properties." },
|
|
1497
1487
|
fixable: "code",
|
|
1498
1488
|
messages: {
|
|
@@ -1517,24 +1507,21 @@ var no_unknown_property_default = createRule({
|
|
|
1517
1507
|
}
|
|
1518
1508
|
}]
|
|
1519
1509
|
},
|
|
1520
|
-
name:
|
|
1510
|
+
name: "no-unknown-property",
|
|
1521
1511
|
create: create$4
|
|
1522
1512
|
});
|
|
1523
1513
|
function create$4(context) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
return context.options[0]?.requireDataLowercase ?? DEFAULTS.requireDataLowercase;
|
|
1529
|
-
}
|
|
1514
|
+
const options = context.options[0] ?? {};
|
|
1515
|
+
const ignore = options.ignore ?? [];
|
|
1516
|
+
const requireDataLowercase = options.requireDataLowercase ?? false;
|
|
1517
|
+
let attributeTagsMap = null;
|
|
1530
1518
|
return { JSXAttribute(node) {
|
|
1531
|
-
const ignoreNames = getIgnoreConfig();
|
|
1532
1519
|
const actualName = getText(context, node.name);
|
|
1533
|
-
if (
|
|
1520
|
+
if (ignore.includes(actualName)) return;
|
|
1534
1521
|
const name = normalizeAttributeCase(actualName);
|
|
1535
1522
|
if (tagNameHasDot(node)) return;
|
|
1536
1523
|
if (isValidDataAttribute(name)) {
|
|
1537
|
-
if (
|
|
1524
|
+
if (requireDataLowercase && hasUpperCaseCharacter(name)) context.report({
|
|
1538
1525
|
data: {
|
|
1539
1526
|
name: actualName,
|
|
1540
1527
|
lowerCaseName: actualName.toLowerCase()
|
|
@@ -1548,8 +1535,8 @@ function create$4(context) {
|
|
|
1548
1535
|
const tagName = getTagName(node);
|
|
1549
1536
|
if (tagName === "fbt" || tagName === "fbs") return;
|
|
1550
1537
|
if (!isValidHTMLTagInJSX(node)) return;
|
|
1551
|
-
const
|
|
1552
|
-
const allowedTags = has(
|
|
1538
|
+
const tagsMap = attributeTagsMap ??= getAttributeTagsMap(context);
|
|
1539
|
+
const allowedTags = has(tagsMap, name) ? tagsMap[name] : null;
|
|
1553
1540
|
if (tagName != null && allowedTags != null) {
|
|
1554
1541
|
if (!allowedTags.includes(tagName)) context.report({
|
|
1555
1542
|
data: {
|
|
@@ -1563,25 +1550,24 @@ function create$4(context) {
|
|
|
1563
1550
|
return;
|
|
1564
1551
|
}
|
|
1565
1552
|
const standardName = getStandardName(name, context);
|
|
1566
|
-
|
|
1567
|
-
if (standardName != null && standardName === name) return;
|
|
1568
|
-
if (hasStandardNameButIsNotUsed) {
|
|
1553
|
+
if (standardName == null) {
|
|
1569
1554
|
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",
|
|
1555
|
+
data: { name: actualName },
|
|
1556
|
+
messageId: "unknown-prop",
|
|
1578
1557
|
node
|
|
1579
1558
|
});
|
|
1580
1559
|
return;
|
|
1581
1560
|
}
|
|
1561
|
+
if (standardName === name) return;
|
|
1582
1562
|
context.report({
|
|
1583
|
-
data: {
|
|
1584
|
-
|
|
1563
|
+
data: {
|
|
1564
|
+
name: actualName,
|
|
1565
|
+
standardName
|
|
1566
|
+
},
|
|
1567
|
+
fix(fixer) {
|
|
1568
|
+
return fixer.replaceText(node.name, standardName);
|
|
1569
|
+
},
|
|
1570
|
+
messageId: "unknown-prop-with-standard-name",
|
|
1585
1571
|
node
|
|
1586
1572
|
});
|
|
1587
1573
|
} };
|
|
@@ -1604,14 +1590,13 @@ function create$3(context) {
|
|
|
1604
1590
|
return { JSXElement(node) {
|
|
1605
1591
|
const { domElementType } = resolver.resolve(node);
|
|
1606
1592
|
if (domElementType !== "iframe") return;
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1609
|
-
const
|
|
1610
|
-
const value = sandboxValue.toStatic();
|
|
1593
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
1594
|
+
if (sandboxValue == null) return;
|
|
1595
|
+
const value = getAttributeStaticValue(context, sandboxValue);
|
|
1611
1596
|
if (!isString(value) || !UNSAFE_SANDBOX_VALUES.every((a) => value.includes(a))) return;
|
|
1612
1597
|
context.report({
|
|
1613
1598
|
messageId: "default",
|
|
1614
|
-
node: sandboxValue
|
|
1599
|
+
node: getAttributeReportNode(sandboxValue)
|
|
1615
1600
|
});
|
|
1616
1601
|
} };
|
|
1617
1602
|
}
|
|
@@ -1625,22 +1610,10 @@ function isSafeRel(value, allowReferrer) {
|
|
|
1625
1610
|
if (/\bnoreferrer\b/u.test(value)) return true;
|
|
1626
1611
|
return allowReferrer && /\bnoopener\b/u.test(value);
|
|
1627
1612
|
}
|
|
1628
|
-
// src/rules/no-unsafe-target-blank/no-unsafe-target-blank.ts
|
|
1629
|
-
const RULE_NAME$2 = "no-unsafe-target-blank";
|
|
1630
|
-
const defaultOptions = [{ allowReferrer: false }];
|
|
1631
|
-
const schema = [{
|
|
1632
|
-
type: "object",
|
|
1633
|
-
additionalProperties: false,
|
|
1634
|
-
properties: { allowReferrer: {
|
|
1635
|
-
type: "boolean",
|
|
1636
|
-
description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved.",
|
|
1637
|
-
default: false
|
|
1638
|
-
} }
|
|
1639
|
-
}];
|
|
1640
1613
|
var no_unsafe_target_blank_default = createRule({
|
|
1641
1614
|
meta: {
|
|
1642
1615
|
type: "problem",
|
|
1643
|
-
defaultOptions: [
|
|
1616
|
+
defaultOptions: [{}],
|
|
1644
1617
|
docs: { description: "Disallows 'target=\"_blank\"' without 'rel=\"noreferrer\"'." },
|
|
1645
1618
|
fixable: "code",
|
|
1646
1619
|
hasSuggestions: true,
|
|
@@ -1648,46 +1621,55 @@ var no_unsafe_target_blank_default = createRule({
|
|
|
1648
1621
|
default: `Using 'target="_blank"' on an external link without '{{rel}}' is a security risk.`,
|
|
1649
1622
|
suggest: `Add '{{rel}}' to the link to prevent security risks.`
|
|
1650
1623
|
},
|
|
1651
|
-
schema
|
|
1624
|
+
schema: [{
|
|
1625
|
+
type: "object",
|
|
1626
|
+
additionalProperties: false,
|
|
1627
|
+
properties: { allowReferrer: {
|
|
1628
|
+
type: "boolean",
|
|
1629
|
+
description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
|
|
1630
|
+
} }
|
|
1631
|
+
}]
|
|
1652
1632
|
},
|
|
1653
|
-
name:
|
|
1633
|
+
name: "no-unsafe-target-blank",
|
|
1654
1634
|
create: create$2
|
|
1655
1635
|
});
|
|
1656
1636
|
function create$2(context) {
|
|
1657
|
-
const
|
|
1637
|
+
const allowReferrer = (context.options[0] ?? {}).allowReferrer ?? false;
|
|
1658
1638
|
const resolver = createJSXElementResolver(context);
|
|
1659
1639
|
const requiredRelAttribute = `rel="${allowReferrer ? "noopener" : "noreferrer"}"`;
|
|
1660
|
-
function buildSuggest(fix) {
|
|
1661
|
-
return [{
|
|
1662
|
-
data: { rel: requiredRelAttribute },
|
|
1663
|
-
fix,
|
|
1664
|
-
messageId: "suggest"
|
|
1665
|
-
}];
|
|
1666
|
-
}
|
|
1667
1640
|
return { JSXElement(node) {
|
|
1668
1641
|
const { domElementType } = resolver.resolve(node);
|
|
1669
1642
|
if (domElementType !== "a") return;
|
|
1670
|
-
if (
|
|
1671
|
-
if (!isExternalLinkLike(
|
|
1672
|
-
const
|
|
1673
|
-
if (
|
|
1643
|
+
if (getAttributeStaticValueByName(context, node, "target") !== "_blank") return;
|
|
1644
|
+
if (!isExternalLinkLike(getAttributeStaticValueByName(context, node, "href"))) return;
|
|
1645
|
+
const relValue = getAttributeValueByName(node, "rel");
|
|
1646
|
+
if (relValue == null) {
|
|
1647
|
+
const lastAttribute = node.openingElement.attributes.at(-1);
|
|
1674
1648
|
context.report({
|
|
1675
1649
|
messageId: "default",
|
|
1676
1650
|
data: { rel: requiredRelAttribute },
|
|
1677
1651
|
node: node.openingElement,
|
|
1678
|
-
suggest: buildSuggest((fixer) => fixer.insertTextAfter(node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1652
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.insertTextAfter(lastAttribute ?? node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1679
1653
|
});
|
|
1680
1654
|
return;
|
|
1681
1655
|
}
|
|
1682
|
-
|
|
1656
|
+
const relAttribute = relValue.attribute;
|
|
1657
|
+
if (isSafeRel(getAttributeStaticValue(context, relValue), allowReferrer)) return;
|
|
1683
1658
|
context.report({
|
|
1684
1659
|
messageId: "default",
|
|
1685
1660
|
data: { rel: requiredRelAttribute },
|
|
1686
1661
|
node: relAttribute,
|
|
1687
|
-
suggest: buildSuggest((fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1662
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1688
1663
|
});
|
|
1689
1664
|
} };
|
|
1690
1665
|
}
|
|
1666
|
+
function buildSuggest(relAttribute, fix) {
|
|
1667
|
+
return [{
|
|
1668
|
+
data: { rel: relAttribute },
|
|
1669
|
+
fix,
|
|
1670
|
+
messageId: "suggest"
|
|
1671
|
+
}];
|
|
1672
|
+
}
|
|
1691
1673
|
var no_use_form_state_default = createRule({
|
|
1692
1674
|
meta: {
|
|
1693
1675
|
type: "problem",
|
|
@@ -1701,31 +1683,19 @@ var no_use_form_state_default = createRule({
|
|
|
1701
1683
|
});
|
|
1702
1684
|
function create$1(context) {
|
|
1703
1685
|
if (!context.sourceCode.text.includes("useFormState")) return {};
|
|
1704
|
-
const
|
|
1705
|
-
if (compare(
|
|
1686
|
+
const { importSource, version } = getSettingsFromContext(context);
|
|
1687
|
+
if (compare(version, "19.0.0", "<")) return {};
|
|
1706
1688
|
const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
|
|
1707
1689
|
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
|
-
}
|
|
1690
|
+
if (!isReactDOMCall(node, imports, "useFormState")) return;
|
|
1691
|
+
context.report({
|
|
1692
|
+
fix: buildFix(context, node, importSource),
|
|
1693
|
+
messageId: "default",
|
|
1694
|
+
node
|
|
1695
|
+
});
|
|
1725
1696
|
} };
|
|
1726
1697
|
}
|
|
1727
|
-
function buildFix(context, node) {
|
|
1728
|
-
const { importSource } = getSettingsFromContext(context);
|
|
1698
|
+
function buildFix(context, node, importSource) {
|
|
1729
1699
|
return (fixer) => {
|
|
1730
1700
|
return [fixer.insertTextBefore(context.sourceCode.ast, `import { useActionState } from "${importSource}";\n`), fixer.replaceText(node.callee, "useActionState")];
|
|
1731
1701
|
};
|
|
@@ -1764,7 +1734,7 @@ function create(context) {
|
|
|
1764
1734
|
return { JSXElement(node) {
|
|
1765
1735
|
const { domElementType } = resolver.resolve(node);
|
|
1766
1736
|
if (!KNOWN_VOID_ELEMENTS.has(domElementType)) return;
|
|
1767
|
-
if (node.children.
|
|
1737
|
+
if (node.children.some(isChildContent) || hasAnyAttribute(node, ["children", "dangerouslySetInnerHTML"])) context.report({
|
|
1768
1738
|
data: { elementType: domElementType },
|
|
1769
1739
|
messageId: "default",
|
|
1770
1740
|
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.10",
|
|
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.10",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.10",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.10",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.10",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.10",
|
|
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
|
},
|