eslint-plugin-react-dom 5.30.0-beta.5 → 5.30.0-beta.7
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 +224 -244
- package/package.json +6 -6
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 {
|
|
4
|
-
import {
|
|
3
|
+
import { findAttribute, getAttributeStaticValue, getAttributeStaticValueByName, getAttributeValue, getAttributeValueByName, getElementFullType, hasAnyAttribute, hasAttribute, isEmptyExpressionContainer, isHostElement, isPaddingWhitespace, isPlainAttribute } from "@eslint-react/jsx";
|
|
4
|
+
import { complete, getText } from "@eslint-react/eslint";
|
|
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.7";
|
|
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));
|
|
1422
|
+
}
|
|
1423
|
+
function getAttributeTagsMap(context) {
|
|
1424
|
+
const { version } = getSettingsFromContext(context);
|
|
1425
|
+
return getAttributeTagsMapForVersion(version);
|
|
1450
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,67 +1455,79 @@ 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";
|
|
1488
|
-
const
|
|
1484
|
+
const defaultOptions$1 = [{
|
|
1489
1485
|
ignore: [],
|
|
1490
1486
|
requireDataLowercase: false
|
|
1487
|
+
}];
|
|
1488
|
+
const schema$1 = [{
|
|
1489
|
+
type: "object",
|
|
1490
|
+
additionalProperties: false,
|
|
1491
|
+
properties: {
|
|
1492
|
+
ignore: {
|
|
1493
|
+
type: "array",
|
|
1494
|
+
description: "Property names to ignore.",
|
|
1495
|
+
items: { type: "string" }
|
|
1496
|
+
},
|
|
1497
|
+
requireDataLowercase: {
|
|
1498
|
+
type: "boolean",
|
|
1499
|
+
description: "Require lowercase names for data-* attributes."
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
}];
|
|
1503
|
+
const messages = {
|
|
1504
|
+
"data-lowercase-required": "React does not recognize data-* props with uppercase characters on a DOM element. Found '{{name}}', use '{{lowerCaseName}}' instead",
|
|
1505
|
+
"invalid-prop-on-tag": "Invalid property '{{name}}' found on tag '{{tagName}}', but it is only allowed on: {{allowedTags}}",
|
|
1506
|
+
"unknown-prop": "Unknown property '{{name}}' found",
|
|
1507
|
+
"unknown-prop-with-standard-name": "Unknown property '{{name}}' found, use '{{standardName}}' instead"
|
|
1491
1508
|
};
|
|
1492
1509
|
var no_unknown_property_default = createRule({
|
|
1493
1510
|
meta: {
|
|
1494
1511
|
type: "problem",
|
|
1495
|
-
defaultOptions: [
|
|
1512
|
+
defaultOptions: [...defaultOptions$1],
|
|
1496
1513
|
docs: { description: "Disallows unknown 'DOM' properties." },
|
|
1497
1514
|
fixable: "code",
|
|
1498
|
-
messages
|
|
1499
|
-
|
|
1500
|
-
"invalid-prop-on-tag": "Invalid property '{{name}}' found on tag '{{tagName}}', but it is only allowed on: {{allowedTags}}",
|
|
1501
|
-
"unknown-prop": "Unknown property '{{name}}' found",
|
|
1502
|
-
"unknown-prop-with-standard-name": "Unknown property '{{name}}' found, use '{{standardName}}' instead"
|
|
1503
|
-
},
|
|
1504
|
-
schema: [{
|
|
1505
|
-
type: "object",
|
|
1506
|
-
additionalProperties: false,
|
|
1507
|
-
properties: {
|
|
1508
|
-
ignore: {
|
|
1509
|
-
type: "array",
|
|
1510
|
-
description: "Property names to ignore.",
|
|
1511
|
-
items: { type: "string" }
|
|
1512
|
-
},
|
|
1513
|
-
requireDataLowercase: {
|
|
1514
|
-
type: "boolean",
|
|
1515
|
-
description: "Require lowercase names for data-* attributes."
|
|
1516
|
-
}
|
|
1517
|
-
}
|
|
1518
|
-
}]
|
|
1515
|
+
messages,
|
|
1516
|
+
schema: schema$1
|
|
1519
1517
|
},
|
|
1520
1518
|
name: RULE_NAME$4,
|
|
1521
1519
|
create: create$4
|
|
1522
1520
|
});
|
|
1523
1521
|
function create$4(context) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
}
|
|
1527
|
-
function getRequireDataLowercase() {
|
|
1528
|
-
return context.options[0]?.requireDataLowercase ?? DEFAULTS.requireDataLowercase;
|
|
1529
|
-
}
|
|
1522
|
+
const { ignore, requireDataLowercase } = complete(context.options[0], defaultOptions$1[0]);
|
|
1523
|
+
let attributeTagsMap = null;
|
|
1530
1524
|
return { JSXAttribute(node) {
|
|
1531
|
-
const ignoreNames = getIgnoreConfig();
|
|
1532
1525
|
const actualName = getText(context, node.name);
|
|
1533
|
-
if (
|
|
1526
|
+
if (ignore.includes(actualName)) return;
|
|
1534
1527
|
const name = normalizeAttributeCase(actualName);
|
|
1535
1528
|
if (tagNameHasDot(node)) return;
|
|
1536
1529
|
if (isValidDataAttribute(name)) {
|
|
1537
|
-
if (
|
|
1530
|
+
if (requireDataLowercase && hasUpperCaseCharacter(name)) context.report({
|
|
1538
1531
|
data: {
|
|
1539
1532
|
name: actualName,
|
|
1540
1533
|
lowerCaseName: actualName.toLowerCase()
|
|
@@ -1548,8 +1541,8 @@ function create$4(context) {
|
|
|
1548
1541
|
const tagName = getTagName(node);
|
|
1549
1542
|
if (tagName === "fbt" || tagName === "fbs") return;
|
|
1550
1543
|
if (!isValidHTMLTagInJSX(node)) return;
|
|
1551
|
-
const
|
|
1552
|
-
const allowedTags = has(
|
|
1544
|
+
const tagsMap = attributeTagsMap ??= getAttributeTagsMap(context);
|
|
1545
|
+
const allowedTags = has(tagsMap, name) ? tagsMap[name] : null;
|
|
1553
1546
|
if (tagName != null && allowedTags != null) {
|
|
1554
1547
|
if (!allowedTags.includes(tagName)) context.report({
|
|
1555
1548
|
data: {
|
|
@@ -1563,25 +1556,24 @@ function create$4(context) {
|
|
|
1563
1556
|
return;
|
|
1564
1557
|
}
|
|
1565
1558
|
const standardName = getStandardName(name, context);
|
|
1566
|
-
|
|
1567
|
-
if (standardName != null && standardName === name) return;
|
|
1568
|
-
if (hasStandardNameButIsNotUsed) {
|
|
1559
|
+
if (standardName == null) {
|
|
1569
1560
|
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",
|
|
1561
|
+
data: { name: actualName },
|
|
1562
|
+
messageId: "unknown-prop",
|
|
1578
1563
|
node
|
|
1579
1564
|
});
|
|
1580
1565
|
return;
|
|
1581
1566
|
}
|
|
1567
|
+
if (standardName === name) return;
|
|
1582
1568
|
context.report({
|
|
1583
|
-
data: {
|
|
1584
|
-
|
|
1569
|
+
data: {
|
|
1570
|
+
name: actualName,
|
|
1571
|
+
standardName
|
|
1572
|
+
},
|
|
1573
|
+
fix(fixer) {
|
|
1574
|
+
return fixer.replaceText(node.name, standardName);
|
|
1575
|
+
},
|
|
1576
|
+
messageId: "unknown-prop-with-standard-name",
|
|
1585
1577
|
node
|
|
1586
1578
|
});
|
|
1587
1579
|
} };
|
|
@@ -1604,14 +1596,13 @@ function create$3(context) {
|
|
|
1604
1596
|
return { JSXElement(node) {
|
|
1605
1597
|
const { domElementType } = resolver.resolve(node);
|
|
1606
1598
|
if (domElementType !== "iframe") return;
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1609
|
-
const
|
|
1610
|
-
const value = sandboxValue.toStatic();
|
|
1599
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
1600
|
+
if (sandboxValue == null) return;
|
|
1601
|
+
const value = getAttributeStaticValue(context, sandboxValue);
|
|
1611
1602
|
if (!isString(value) || !UNSAFE_SANDBOX_VALUES.every((a) => value.includes(a))) return;
|
|
1612
1603
|
context.report({
|
|
1613
1604
|
messageId: "default",
|
|
1614
|
-
node: sandboxValue
|
|
1605
|
+
node: getAttributeReportNode(sandboxValue)
|
|
1615
1606
|
});
|
|
1616
1607
|
} };
|
|
1617
1608
|
}
|
|
@@ -1633,8 +1624,7 @@ const schema = [{
|
|
|
1633
1624
|
additionalProperties: false,
|
|
1634
1625
|
properties: { allowReferrer: {
|
|
1635
1626
|
type: "boolean",
|
|
1636
|
-
description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
|
|
1637
|
-
default: false
|
|
1627
|
+
description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
|
|
1638
1628
|
} }
|
|
1639
1629
|
}];
|
|
1640
1630
|
var no_unsafe_target_blank_default = createRule({
|
|
@@ -1654,40 +1644,42 @@ var no_unsafe_target_blank_default = createRule({
|
|
|
1654
1644
|
create: create$2
|
|
1655
1645
|
});
|
|
1656
1646
|
function create$2(context) {
|
|
1657
|
-
const { allowReferrer
|
|
1647
|
+
const { allowReferrer } = complete(context.options[0], defaultOptions[0]);
|
|
1658
1648
|
const resolver = createJSXElementResolver(context);
|
|
1659
1649
|
const requiredRelAttribute = `rel="${allowReferrer ? "noopener" : "noreferrer"}"`;
|
|
1660
|
-
function buildSuggest(fix) {
|
|
1661
|
-
return [{
|
|
1662
|
-
data: { rel: requiredRelAttribute },
|
|
1663
|
-
fix,
|
|
1664
|
-
messageId: "suggest"
|
|
1665
|
-
}];
|
|
1666
|
-
}
|
|
1667
1650
|
return { JSXElement(node) {
|
|
1668
1651
|
const { domElementType } = resolver.resolve(node);
|
|
1669
1652
|
if (domElementType !== "a") return;
|
|
1670
|
-
if (
|
|
1671
|
-
if (!isExternalLinkLike(
|
|
1672
|
-
const
|
|
1673
|
-
if (
|
|
1653
|
+
if (getAttributeStaticValueByName(context, node, "target") !== "_blank") return;
|
|
1654
|
+
if (!isExternalLinkLike(getAttributeStaticValueByName(context, node, "href"))) return;
|
|
1655
|
+
const relValue = getAttributeValueByName(node, "rel");
|
|
1656
|
+
if (relValue == null) {
|
|
1657
|
+
const lastAttribute = node.openingElement.attributes.at(-1);
|
|
1674
1658
|
context.report({
|
|
1675
1659
|
messageId: "default",
|
|
1676
1660
|
data: { rel: requiredRelAttribute },
|
|
1677
1661
|
node: node.openingElement,
|
|
1678
|
-
suggest: buildSuggest((fixer) => fixer.insertTextAfter(node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1662
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.insertTextAfter(lastAttribute ?? node.openingElement.name, ` ${requiredRelAttribute}`))
|
|
1679
1663
|
});
|
|
1680
1664
|
return;
|
|
1681
1665
|
}
|
|
1682
|
-
|
|
1666
|
+
const relAttribute = relValue.attribute;
|
|
1667
|
+
if (isSafeRel(getAttributeStaticValue(context, relValue), allowReferrer)) return;
|
|
1683
1668
|
context.report({
|
|
1684
1669
|
messageId: "default",
|
|
1685
1670
|
data: { rel: requiredRelAttribute },
|
|
1686
1671
|
node: relAttribute,
|
|
1687
|
-
suggest: buildSuggest((fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1672
|
+
suggest: buildSuggest(requiredRelAttribute, (fixer) => fixer.replaceText(relAttribute, requiredRelAttribute))
|
|
1688
1673
|
});
|
|
1689
1674
|
} };
|
|
1690
1675
|
}
|
|
1676
|
+
function buildSuggest(relAttribute, fix) {
|
|
1677
|
+
return [{
|
|
1678
|
+
data: { rel: relAttribute },
|
|
1679
|
+
fix,
|
|
1680
|
+
messageId: "suggest"
|
|
1681
|
+
}];
|
|
1682
|
+
}
|
|
1691
1683
|
var no_use_form_state_default = createRule({
|
|
1692
1684
|
meta: {
|
|
1693
1685
|
type: "problem",
|
|
@@ -1701,31 +1693,19 @@ var no_use_form_state_default = createRule({
|
|
|
1701
1693
|
});
|
|
1702
1694
|
function create$1(context) {
|
|
1703
1695
|
if (!context.sourceCode.text.includes("useFormState")) return {};
|
|
1704
|
-
const
|
|
1705
|
-
if (compare(
|
|
1696
|
+
const { importSource, version } = getSettingsFromContext(context);
|
|
1697
|
+
if (compare(version, "19.0.0", "<")) return {};
|
|
1706
1698
|
const imports = createImportLookup(context.sourceCode.ast, { source: "react-dom" });
|
|
1707
1699
|
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
|
-
}
|
|
1700
|
+
if (!isReactDOMCall(node, imports, "useFormState")) return;
|
|
1701
|
+
context.report({
|
|
1702
|
+
fix: buildFix(context, node, importSource),
|
|
1703
|
+
messageId: "default",
|
|
1704
|
+
node
|
|
1705
|
+
});
|
|
1725
1706
|
} };
|
|
1726
1707
|
}
|
|
1727
|
-
function buildFix(context, node) {
|
|
1728
|
-
const { importSource } = getSettingsFromContext(context);
|
|
1708
|
+
function buildFix(context, node, importSource) {
|
|
1729
1709
|
return (fixer) => {
|
|
1730
1710
|
return [fixer.insertTextBefore(context.sourceCode.ast, `import { useActionState } from "${importSource}";\n`), fixer.replaceText(node.callee, "useActionState")];
|
|
1731
1711
|
};
|
|
@@ -1764,7 +1744,7 @@ function create(context) {
|
|
|
1764
1744
|
return { JSXElement(node) {
|
|
1765
1745
|
const { domElementType } = resolver.resolve(node);
|
|
1766
1746
|
if (!KNOWN_VOID_ELEMENTS.has(domElementType)) return;
|
|
1767
|
-
if (node.children.
|
|
1747
|
+
if (node.children.some(isChildContent) || hasAnyAttribute(node, ["children", "dangerouslySetInnerHTML"])) context.report({
|
|
1768
1748
|
data: { elementType: domElementType },
|
|
1769
1749
|
messageId: "default",
|
|
1770
1750
|
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.7",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for DOM related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,11 +37,11 @@
|
|
|
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.
|
|
40
|
+
"@eslint-react/ast": "5.30.0-beta.7",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.7",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.7",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.7",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.7",
|
|
45
45
|
"@typescript-eslint/types": "^8.72.1",
|
|
46
46
|
"@typescript-eslint/utils": "^8.72.1",
|
|
47
47
|
"compare-versions": "^6.1.1",
|