eslint-plugin-react-dom 5.30.0-beta.2 → 5.30.0-beta.21
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 +223 -243
- package/package.json +10 -10
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.21";
|
|
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,33 +136,27 @@ 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) {
|
|
173
152
|
return (fixer) => {
|
|
174
153
|
const [arg0, arg1] = node.arguments;
|
|
175
|
-
if (arg0 == null
|
|
154
|
+
if (arg0 == null) return null;
|
|
155
|
+
if (arg1 == null) return null;
|
|
156
|
+
if (node.arguments.length !== 2) return null;
|
|
157
|
+
if (arg0.type === AST_NODE_TYPES.SpreadElement) return null;
|
|
158
|
+
if (arg1.type === AST_NODE_TYPES.SpreadElement) return null;
|
|
159
|
+
if (node.parent.type !== AST_NODE_TYPES.ExpressionStatement) return null;
|
|
176
160
|
return [fixer.insertTextBefore(context.sourceCode.ast, "import { hydrateRoot } from \"react-dom/client\";\n"), fixer.replaceText(node, `hydrateRoot(${getText(context, arg1)}, ${getText(context, arg0)})`)];
|
|
177
161
|
};
|
|
178
162
|
}
|
|
@@ -256,6 +240,12 @@ function isObjectKeyword(input) {
|
|
|
256
240
|
return typeof input === "object" && input !== null || isFunction(input);
|
|
257
241
|
}
|
|
258
242
|
dual(2, (data, property) => isObjectKeyword(data) && property in data);
|
|
243
|
+
function getOrInsertComputed(map, key, callback) {
|
|
244
|
+
if (map.has(key)) return map.get(key);
|
|
245
|
+
const value = callback(key);
|
|
246
|
+
map.set(key, value);
|
|
247
|
+
return value;
|
|
248
|
+
}
|
|
259
249
|
dual(2, (self, predicate) => {
|
|
260
250
|
const input = Array.isArray(self) ? self : Array.from(self);
|
|
261
251
|
const len = input.length;
|
|
@@ -281,7 +271,7 @@ function createJSXElementResolver(context) {
|
|
|
281
271
|
};
|
|
282
272
|
const nameNode = node.openingElement.name;
|
|
283
273
|
if (nameNode.type === AST_NODE_TYPES.JSXIdentifier && nameNode.name.charAt(0) === nameNode.name.charAt(0).toLowerCase()) return result;
|
|
284
|
-
const polyPropValue =
|
|
274
|
+
const polyPropValue = getAttributeStaticValueByName(context, node, polymorphicPropName);
|
|
285
275
|
if (isString(polyPropValue)) return {
|
|
286
276
|
...result,
|
|
287
277
|
domElementType: polyPropValue.toLowerCase()
|
|
@@ -314,21 +304,25 @@ function create$10(context) {
|
|
|
314
304
|
const resolver = createJSXElementResolver(context);
|
|
315
305
|
return { JSXElement(node) {
|
|
316
306
|
const { domElementType } = resolver.resolve(node);
|
|
317
|
-
if (domElementType !== "button") return;
|
|
318
|
-
|
|
307
|
+
if (domElementType !== "button" || hasAttribute(node, "type")) return;
|
|
308
|
+
const suggest = BUTTON_TYPES.map((type) => ({
|
|
309
|
+
data: { type },
|
|
310
|
+
fix(fixer) {
|
|
311
|
+
return fixer.insertTextAfter(node.openingElement.name, ` type="${type}"`);
|
|
312
|
+
},
|
|
313
|
+
messageId: "suggest"
|
|
314
|
+
}));
|
|
319
315
|
context.report({
|
|
320
316
|
messageId: "default",
|
|
321
317
|
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
|
-
}))
|
|
318
|
+
suggest
|
|
329
319
|
});
|
|
330
320
|
} };
|
|
331
321
|
}
|
|
322
|
+
// src/utils/get-attribute-report-node.ts
|
|
323
|
+
function getAttributeReportNode(value) {
|
|
324
|
+
return value.node ?? value.attribute;
|
|
325
|
+
}
|
|
332
326
|
var no_missing_iframe_sandbox_default = createRule({
|
|
333
327
|
meta: {
|
|
334
328
|
type: "problem",
|
|
@@ -349,8 +343,8 @@ function create$9(context) {
|
|
|
349
343
|
return { JSXElement(node) {
|
|
350
344
|
const { domElementType } = resolver.resolve(node);
|
|
351
345
|
if (domElementType !== "iframe") return;
|
|
352
|
-
const
|
|
353
|
-
if (
|
|
346
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
347
|
+
if (sandboxValue == null) {
|
|
354
348
|
context.report({
|
|
355
349
|
messageId: "default",
|
|
356
350
|
node: node.openingElement,
|
|
@@ -364,31 +358,20 @@ function create$9(context) {
|
|
|
364
358
|
});
|
|
365
359
|
return;
|
|
366
360
|
}
|
|
367
|
-
|
|
368
|
-
if (isString(sandboxValue.toStatic())) return;
|
|
361
|
+
if (isString(getAttributeStaticValue(context, sandboxValue))) return;
|
|
369
362
|
context.report({
|
|
370
363
|
messageId: "default",
|
|
371
|
-
node: sandboxValue
|
|
364
|
+
node: getAttributeReportNode(sandboxValue),
|
|
372
365
|
suggest: [{
|
|
373
366
|
data: { value: "" },
|
|
374
367
|
fix(fixer) {
|
|
375
|
-
|
|
376
|
-
return fixer.replaceText(sandboxProp, `sandbox=""`);
|
|
368
|
+
return fixer.replaceText(sandboxValue.attribute, `sandbox=""`);
|
|
377
369
|
},
|
|
378
370
|
messageId: "suggest"
|
|
379
371
|
}]
|
|
380
372
|
});
|
|
381
373
|
} };
|
|
382
374
|
}
|
|
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
375
|
var no_render_return_value_default = createRule({
|
|
393
376
|
meta: {
|
|
394
377
|
type: "problem",
|
|
@@ -396,7 +379,7 @@ var no_render_return_value_default = createRule({
|
|
|
396
379
|
messages: { default: "Do not depend on the return value from 'ReactDOM.render'." },
|
|
397
380
|
schema: []
|
|
398
381
|
},
|
|
399
|
-
name:
|
|
382
|
+
name: "no-render-return-value",
|
|
400
383
|
create: create$8
|
|
401
384
|
});
|
|
402
385
|
function create$8(context) {
|
|
@@ -406,23 +389,20 @@ function create$8(context) {
|
|
|
406
389
|
source: "react-dom"
|
|
407
390
|
});
|
|
408
391
|
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
|
-
}
|
|
392
|
+
if (!isReactDOMCall(node, imports, "render") || !isReturnValueUsed(node)) return;
|
|
393
|
+
context.report({
|
|
394
|
+
messageId: "default",
|
|
395
|
+
node
|
|
396
|
+
});
|
|
424
397
|
} };
|
|
425
398
|
}
|
|
399
|
+
const BANNED_PARENT_TYPES = [
|
|
400
|
+
AST_NODE_TYPES.VariableDeclarator,
|
|
401
|
+
AST_NODE_TYPES.Property,
|
|
402
|
+
AST_NODE_TYPES.ReturnStatement,
|
|
403
|
+
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
404
|
+
AST_NODE_TYPES.AssignmentExpression
|
|
405
|
+
];
|
|
426
406
|
function isReturnValueUsed(node) {
|
|
427
407
|
let parent = node.parent;
|
|
428
408
|
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
@@ -441,36 +421,30 @@ var no_render_default = createRule({
|
|
|
441
421
|
});
|
|
442
422
|
function create$7(context) {
|
|
443
423
|
if (!context.sourceCode.text.includes("render")) return {};
|
|
444
|
-
const
|
|
445
|
-
if (compare(
|
|
424
|
+
const { version } = getSettingsFromContext(context);
|
|
425
|
+
if (compare(version, "18.0.0", "<")) return {};
|
|
446
426
|
const imports = createImportLookup(context.sourceCode.ast, {
|
|
447
427
|
builtinNamespaces: ["ReactDOM"],
|
|
448
428
|
source: "react-dom"
|
|
449
429
|
});
|
|
450
430
|
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
|
-
}
|
|
431
|
+
if (!isReactDOMCall(node, imports, "render")) return;
|
|
432
|
+
context.report({
|
|
433
|
+
fix: buildFix$1(context, node),
|
|
434
|
+
messageId: "default",
|
|
435
|
+
node
|
|
436
|
+
});
|
|
468
437
|
} };
|
|
469
438
|
}
|
|
470
439
|
function buildFix$1(context, node) {
|
|
471
440
|
return (fixer) => {
|
|
472
441
|
const [arg0, arg1] = node.arguments;
|
|
473
|
-
if (arg0 == null
|
|
442
|
+
if (arg0 == null) return null;
|
|
443
|
+
if (arg1 == null) return null;
|
|
444
|
+
if (node.arguments.length !== 2) return null;
|
|
445
|
+
if (arg0.type === AST_NODE_TYPES.SpreadElement) return null;
|
|
446
|
+
if (arg1.type === AST_NODE_TYPES.SpreadElement) return null;
|
|
447
|
+
if (node.parent.type !== AST_NODE_TYPES.ExpressionStatement) return null;
|
|
474
448
|
return [fixer.insertTextBefore(context.sourceCode.ast, "import { createRoot } from \"react-dom/client\";\n"), fixer.replaceText(node, `createRoot(${getText(context, arg1)}).render(${getText(context, arg0)})`)];
|
|
475
449
|
};
|
|
476
450
|
}
|
|
@@ -486,8 +460,8 @@ var no_script_url_default = createRule({
|
|
|
486
460
|
});
|
|
487
461
|
function create$6(context) {
|
|
488
462
|
return { JSXAttribute(node) {
|
|
489
|
-
if (node.
|
|
490
|
-
const value =
|
|
463
|
+
if (node.value == null) return;
|
|
464
|
+
const value = getAttributeStaticValue(context, getAttributeValue(node));
|
|
491
465
|
if (isString(value) && RE_JAVASCRIPT_PROTOCOL.test(value)) context.report({
|
|
492
466
|
messageId: "default",
|
|
493
467
|
node: node.value
|
|
@@ -507,13 +481,12 @@ var no_string_style_prop_default = createRule({
|
|
|
507
481
|
function create$5(context) {
|
|
508
482
|
return { JSXElement(node) {
|
|
509
483
|
if (!isHostElement(node)) return;
|
|
510
|
-
const
|
|
511
|
-
if (
|
|
512
|
-
|
|
513
|
-
if (!isString(styleValue.toStatic())) return;
|
|
484
|
+
const styleValue = getAttributeValueByName(node, "style");
|
|
485
|
+
if (styleValue == null) return;
|
|
486
|
+
if (!isString(getAttributeStaticValue(context, styleValue))) return;
|
|
514
487
|
context.report({
|
|
515
488
|
messageId: "default",
|
|
516
|
-
node: styleValue
|
|
489
|
+
node: getAttributeReportNode(styleValue)
|
|
517
490
|
});
|
|
518
491
|
} };
|
|
519
492
|
}
|
|
@@ -1420,37 +1393,55 @@ const REACT_19_3_PROPS = [
|
|
|
1420
1393
|
];
|
|
1421
1394
|
const REACT_19_3_ATTRIBUTE_TAGS_MAP = { credentialless: ["iframe"] };
|
|
1422
1395
|
const REACT_19_3_SVGDOM_ATTRIBUTE_NAMES = { "mask-type": "maskType" };
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
return
|
|
1396
|
+
const VERSION_CACHE_KEY_CACHE = /* @__PURE__ */ new Map();
|
|
1397
|
+
function getVersionCacheKey(version) {
|
|
1398
|
+
return getOrInsertComputed(VERSION_CACHE_KEY_CACHE, version, (v) => [
|
|
1399
|
+
compare(v, "16.1.0", "<="),
|
|
1400
|
+
compare(v, "16.4.0", ">="),
|
|
1401
|
+
compare(v, "19.0.0-rc.0", ">="),
|
|
1402
|
+
compare(v, "19.3.0", ">=")
|
|
1403
|
+
].map(Number).join(""));
|
|
1426
1404
|
}
|
|
1427
|
-
function
|
|
1428
|
-
const
|
|
1429
|
-
if (
|
|
1430
|
-
|
|
1431
|
-
return
|
|
1405
|
+
function buildDOMPropertyNames(version) {
|
|
1406
|
+
const names = DOM_PROPERTY_NAMES_TWO_WORDS.concat(DOM_PROPERTY_NAMES_ONE_WORD);
|
|
1407
|
+
if (compare(version, "16.1.0", "<=")) {
|
|
1408
|
+
names.push("allowTransparency");
|
|
1409
|
+
return names;
|
|
1432
1410
|
}
|
|
1433
|
-
if (
|
|
1434
|
-
if (
|
|
1435
|
-
else
|
|
1436
|
-
if (
|
|
1437
|
-
return
|
|
1411
|
+
if (compare(version, "16.4.0", ">=")) names.push(...REACT_ON_PROPS);
|
|
1412
|
+
if (compare(version, "19.0.0-rc.0", ">=")) names.push(...REACT_19_PROPS);
|
|
1413
|
+
else names.push(...REACT_19_PROPS.map((prop) => prop.toLowerCase()));
|
|
1414
|
+
if (compare(version, "19.3.0", ">=")) names.push(...REACT_19_3_PROPS);
|
|
1415
|
+
return names;
|
|
1438
1416
|
}
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1417
|
+
const ATTRIBUTE_TAGS_MAP_CACHE = /* @__PURE__ */ new Map();
|
|
1418
|
+
function buildAttributeTagsMap(version) {
|
|
1419
|
+
let map = ATTRIBUTE_TAGS_MAP;
|
|
1420
|
+
if (compare(version, "19.0.0-rc.0", ">=")) map = {
|
|
1421
|
+
...map,
|
|
1443
1422
|
...REACT_19_ATTRIBUTE_TAGS_MAP
|
|
1444
1423
|
};
|
|
1445
|
-
if (
|
|
1446
|
-
...
|
|
1424
|
+
if (compare(version, "19.3.0", ">=")) map = {
|
|
1425
|
+
...map,
|
|
1447
1426
|
...REACT_19_3_ATTRIBUTE_TAGS_MAP
|
|
1448
1427
|
};
|
|
1449
|
-
return
|
|
1428
|
+
return map;
|
|
1429
|
+
}
|
|
1430
|
+
function getAttributeTagsMapForVersion(version) {
|
|
1431
|
+
return getOrInsertComputed(ATTRIBUTE_TAGS_MAP_CACHE, getVersionCacheKey(version), () => buildAttributeTagsMap(version));
|
|
1450
1432
|
}
|
|
1433
|
+
function getAttributeTagsMap(context) {
|
|
1434
|
+
const { version } = getSettingsFromContext(context);
|
|
1435
|
+
return getAttributeTagsMapForVersion(version);
|
|
1436
|
+
}
|
|
1437
|
+
const HTML_TAG_VALIDITY_CACHE = /* @__PURE__ */ new WeakMap();
|
|
1451
1438
|
function isValidHTMLTagInJSX(childNode) {
|
|
1452
|
-
|
|
1453
|
-
|
|
1439
|
+
const openingElement = childNode.parent;
|
|
1440
|
+
const cached = HTML_TAG_VALIDITY_CACHE.get(openingElement);
|
|
1441
|
+
if (cached != null) return cached;
|
|
1442
|
+
const isValid = openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z][^-]*$/.test(openingElement.name.name) && !openingElement.attributes.some(isPlainAttribute("is"));
|
|
1443
|
+
HTML_TAG_VALIDITY_CACHE.set(openingElement, isValid);
|
|
1444
|
+
return isValid;
|
|
1454
1445
|
}
|
|
1455
1446
|
function normalizeAttributeCase(name) {
|
|
1456
1447
|
return DOM_PROPERTIES_IGNORE_CASE.find((element) => element.toLowerCase() === name.toLowerCase()) ?? name;
|
|
@@ -1474,25 +1465,34 @@ function tagNameHasDot(node) {
|
|
|
1474
1465
|
function has(obj, key) {
|
|
1475
1466
|
return Object.hasOwn(obj, key);
|
|
1476
1467
|
}
|
|
1468
|
+
const STANDARD_NAME_LOOKUP_CACHE = /* @__PURE__ */ new Map();
|
|
1469
|
+
function getStandardNameLookup(version) {
|
|
1470
|
+
return getOrInsertComputed(STANDARD_NAME_LOOKUP_CACHE, getVersionCacheKey(version), () => {
|
|
1471
|
+
const svgAttributeNames = compare(version, "19.3.0", ">=") ? {
|
|
1472
|
+
...SVGDOM_ATTRIBUTE_NAMES,
|
|
1473
|
+
...REACT_19_3_SVGDOM_ATTRIBUTE_NAMES
|
|
1474
|
+
} : SVGDOM_ATTRIBUTE_NAMES;
|
|
1475
|
+
const exact = new Map([...Object.entries(svgAttributeNames), ...Object.entries(DOM_ATTRIBUTE_NAMES)]);
|
|
1476
|
+
const lower = /* @__PURE__ */ new Map();
|
|
1477
|
+
for (const propertyName of buildDOMPropertyNames(version)) {
|
|
1478
|
+
const key = propertyName.toLowerCase();
|
|
1479
|
+
if (!lower.has(key)) lower.set(key, propertyName);
|
|
1480
|
+
}
|
|
1481
|
+
return {
|
|
1482
|
+
exact,
|
|
1483
|
+
lower
|
|
1484
|
+
};
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1477
1487
|
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;
|
|
1488
|
+
const { version } = getSettingsFromContext(context);
|
|
1489
|
+
const lookup = getStandardNameLookup(version);
|
|
1490
|
+
return lookup.exact.get(name) ?? lookup.lower.get(name.toLowerCase()) ?? null;
|
|
1485
1491
|
}
|
|
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
1492
|
var no_unknown_property_default = createRule({
|
|
1493
1493
|
meta: {
|
|
1494
1494
|
type: "problem",
|
|
1495
|
-
defaultOptions: [
|
|
1495
|
+
defaultOptions: [{}],
|
|
1496
1496
|
docs: { description: "Disallows unknown 'DOM' properties." },
|
|
1497
1497
|
fixable: "code",
|
|
1498
1498
|
messages: {
|
|
@@ -1517,24 +1517,21 @@ var no_unknown_property_default = createRule({
|
|
|
1517
1517
|
}
|
|
1518
1518
|
}]
|
|
1519
1519
|
},
|
|
1520
|
-
name:
|
|
1520
|
+
name: "no-unknown-property",
|
|
1521
1521
|
create: create$4
|
|
1522
1522
|
});
|
|
1523
1523
|
function create$4(context) {
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
return context.options[0]?.requireDataLowercase ?? DEFAULTS.requireDataLowercase;
|
|
1529
|
-
}
|
|
1524
|
+
const options = context.options[0] ?? {};
|
|
1525
|
+
const ignore = options.ignore ?? [];
|
|
1526
|
+
const requireDataLowercase = options.requireDataLowercase ?? false;
|
|
1527
|
+
let attributeTagsMap = null;
|
|
1530
1528
|
return { JSXAttribute(node) {
|
|
1531
|
-
const ignoreNames = getIgnoreConfig();
|
|
1532
1529
|
const actualName = getText(context, node.name);
|
|
1533
|
-
if (
|
|
1530
|
+
if (ignore.includes(actualName)) return;
|
|
1534
1531
|
const name = normalizeAttributeCase(actualName);
|
|
1535
1532
|
if (tagNameHasDot(node)) return;
|
|
1536
1533
|
if (isValidDataAttribute(name)) {
|
|
1537
|
-
if (
|
|
1534
|
+
if (requireDataLowercase && hasUpperCaseCharacter(name)) context.report({
|
|
1538
1535
|
data: {
|
|
1539
1536
|
name: actualName,
|
|
1540
1537
|
lowerCaseName: actualName.toLowerCase()
|
|
@@ -1548,8 +1545,8 @@ function create$4(context) {
|
|
|
1548
1545
|
const tagName = getTagName(node);
|
|
1549
1546
|
if (tagName === "fbt" || tagName === "fbs") return;
|
|
1550
1547
|
if (!isValidHTMLTagInJSX(node)) return;
|
|
1551
|
-
const
|
|
1552
|
-
const allowedTags = has(
|
|
1548
|
+
const tagsMap = attributeTagsMap ??= getAttributeTagsMap(context);
|
|
1549
|
+
const allowedTags = has(tagsMap, name) ? tagsMap[name] : null;
|
|
1553
1550
|
if (tagName != null && allowedTags != null) {
|
|
1554
1551
|
if (!allowedTags.includes(tagName)) context.report({
|
|
1555
1552
|
data: {
|
|
@@ -1563,25 +1560,24 @@ function create$4(context) {
|
|
|
1563
1560
|
return;
|
|
1564
1561
|
}
|
|
1565
1562
|
const standardName = getStandardName(name, context);
|
|
1566
|
-
|
|
1567
|
-
if (standardName != null && standardName === name) return;
|
|
1568
|
-
if (hasStandardNameButIsNotUsed) {
|
|
1563
|
+
if (standardName == null) {
|
|
1569
1564
|
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",
|
|
1565
|
+
data: { name: actualName },
|
|
1566
|
+
messageId: "unknown-prop",
|
|
1578
1567
|
node
|
|
1579
1568
|
});
|
|
1580
1569
|
return;
|
|
1581
1570
|
}
|
|
1571
|
+
if (standardName === name) return;
|
|
1582
1572
|
context.report({
|
|
1583
|
-
data: {
|
|
1584
|
-
|
|
1573
|
+
data: {
|
|
1574
|
+
name: actualName,
|
|
1575
|
+
standardName
|
|
1576
|
+
},
|
|
1577
|
+
fix(fixer) {
|
|
1578
|
+
return fixer.replaceText(node.name, standardName);
|
|
1579
|
+
},
|
|
1580
|
+
messageId: "unknown-prop-with-standard-name",
|
|
1585
1581
|
node
|
|
1586
1582
|
});
|
|
1587
1583
|
} };
|
|
@@ -1604,14 +1600,13 @@ function create$3(context) {
|
|
|
1604
1600
|
return { JSXElement(node) {
|
|
1605
1601
|
const { domElementType } = resolver.resolve(node);
|
|
1606
1602
|
if (domElementType !== "iframe") return;
|
|
1607
|
-
const
|
|
1608
|
-
if (
|
|
1609
|
-
const
|
|
1610
|
-
const value = sandboxValue.toStatic();
|
|
1603
|
+
const sandboxValue = getAttributeValueByName(node, "sandbox");
|
|
1604
|
+
if (sandboxValue == null) return;
|
|
1605
|
+
const value = getAttributeStaticValue(context, sandboxValue);
|
|
1611
1606
|
if (!isString(value) || !UNSAFE_SANDBOX_VALUES.every((a) => value.includes(a))) return;
|
|
1612
1607
|
context.report({
|
|
1613
1608
|
messageId: "default",
|
|
1614
|
-
node: sandboxValue
|
|
1609
|
+
node: getAttributeReportNode(sandboxValue)
|
|
1615
1610
|
});
|
|
1616
1611
|
} };
|
|
1617
1612
|
}
|
|
@@ -1625,22 +1620,10 @@ function isSafeRel(value, allowReferrer) {
|
|
|
1625
1620
|
if (/\bnoreferrer\b/u.test(value)) return true;
|
|
1626
1621
|
return allowReferrer && /\bnoopener\b/u.test(value);
|
|
1627
1622
|
}
|
|
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
1623
|
var no_unsafe_target_blank_default = createRule({
|
|
1641
1624
|
meta: {
|
|
1642
1625
|
type: "problem",
|
|
1643
|
-
defaultOptions: [
|
|
1626
|
+
defaultOptions: [{}],
|
|
1644
1627
|
docs: { description: "Disallows 'target=\"_blank\"' without 'rel=\"noreferrer\"'." },
|
|
1645
1628
|
fixable: "code",
|
|
1646
1629
|
hasSuggestions: true,
|
|
@@ -1648,46 +1631,55 @@ var no_unsafe_target_blank_default = createRule({
|
|
|
1648
1631
|
default: `Using 'target="_blank"' on an external link without '{{rel}}' is a security risk.`,
|
|
1649
1632
|
suggest: `Add '{{rel}}' to the link to prevent security risks.`
|
|
1650
1633
|
},
|
|
1651
|
-
schema
|
|
1634
|
+
schema: [{
|
|
1635
|
+
type: "object",
|
|
1636
|
+
additionalProperties: false,
|
|
1637
|
+
properties: { allowReferrer: {
|
|
1638
|
+
type: "boolean",
|
|
1639
|
+
description: "Allow 'rel=\"noopener\"' without 'noreferrer' so referrer information is preserved."
|
|
1640
|
+
} }
|
|
1641
|
+
}]
|
|
1652
1642
|
},
|
|
1653
|
-
name:
|
|
1643
|
+
name: "no-unsafe-target-blank",
|
|
1654
1644
|
create: create$2
|
|
1655
1645
|
});
|
|
1656
1646
|
function create$2(context) {
|
|
1657
|
-
const
|
|
1647
|
+
const allowReferrer = (context.options[0] ?? {}).allowReferrer ?? false;
|
|
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.21",
|
|
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.21",
|
|
41
|
+
"@eslint-react/eslint": "5.30.0-beta.21",
|
|
42
|
+
"@eslint-react/jsx": "5.30.0-beta.21",
|
|
43
|
+
"@eslint-react/shared": "5.30.0-beta.21",
|
|
44
|
+
"@eslint-react/var": "5.30.0-beta.21",
|
|
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
|
},
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"@types/react": "^19.3.0",
|
|
57
57
|
"@types/react-dom": "^19.3.0",
|
|
58
58
|
"dedent": "^1.7.2",
|
|
59
|
-
"eslint": "^10.
|
|
60
|
-
"tsdown": "^0.23.
|
|
59
|
+
"eslint": "^10.14.0",
|
|
60
|
+
"tsdown": "^0.23.4",
|
|
61
61
|
"typescript": "6.0.3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|