eslint-plugin-react-dom 5.20.2 → 5.20.3
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 +54 -53
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import { DEFAULT_ESLINT_REACT_SETTINGS, RE_JAVASCRIPT_PROTOCOL, getSettingsFromC
|
|
|
2
2
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
3
3
|
import "@eslint-react/eslint";
|
|
4
4
|
import { findAttribute, getAttributeStaticValue, getElementFullType, hasAnyAttribute, hasAttribute, isHostElement, isPaddingWhitespace, resolveAttributeValue } from "@eslint-react/jsx";
|
|
5
|
-
import * as core from "@eslint-react/core";
|
|
6
5
|
import { Check, Extract } from "@eslint-react/ast";
|
|
7
6
|
import { createImportLookup } from "@eslint-react/var";
|
|
8
7
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
@@ -27,7 +26,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
27
26
|
//#endregion
|
|
28
27
|
//#region package.json
|
|
29
28
|
var name$2 = "eslint-plugin-react-dom";
|
|
30
|
-
var version = "5.20.
|
|
29
|
+
var version = "5.20.3";
|
|
31
30
|
|
|
32
31
|
//#endregion
|
|
33
32
|
//#region src/utils/create-rule.ts
|
|
@@ -54,11 +53,11 @@ function create$15(context) {
|
|
|
54
53
|
if (!context.sourceCode.text.includes("dangerouslySetInnerHTML")) return {};
|
|
55
54
|
return { JSXElement(node) {
|
|
56
55
|
if (!hasAttribute(context, node, "dangerouslySetInnerHTML")) return;
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
56
|
+
const fact = findAttribute(context, node, "children") ?? node.children.find((child) => !isPaddingWhitespace(child));
|
|
57
|
+
if (fact == null) return;
|
|
59
58
|
context.report({
|
|
60
59
|
messageId: "default",
|
|
61
|
-
node:
|
|
60
|
+
node: fact
|
|
62
61
|
});
|
|
63
62
|
} };
|
|
64
63
|
}
|
|
@@ -80,18 +79,17 @@ var no_dangerously_set_innerhtml_default = createRule({
|
|
|
80
79
|
function create$14(context) {
|
|
81
80
|
if (!context.sourceCode.text.includes("dangerouslySetInnerHTML")) return {};
|
|
82
81
|
return { JSXElement(node) {
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
82
|
+
const prop = findAttribute(context, node, "dangerouslySetInnerHTML");
|
|
83
|
+
if (prop == null) return;
|
|
85
84
|
context.report({
|
|
86
85
|
messageId: "default",
|
|
87
|
-
node:
|
|
86
|
+
node: prop
|
|
88
87
|
});
|
|
89
88
|
} };
|
|
90
89
|
}
|
|
91
90
|
|
|
92
91
|
//#endregion
|
|
93
92
|
//#region src/rules/no-find-dom-node/no-find-dom-node.ts
|
|
94
|
-
const isFindDOMNodeCall = core.isAPICall("findDOMNode");
|
|
95
93
|
const RULE_NAME$13 = "no-find-dom-node";
|
|
96
94
|
var no_find_dom_node_default = createRule({
|
|
97
95
|
meta: {
|
|
@@ -106,11 +104,26 @@ var no_find_dom_node_default = createRule({
|
|
|
106
104
|
});
|
|
107
105
|
function create$13(context) {
|
|
108
106
|
if (!context.sourceCode.text.includes("findDOMNode")) return {};
|
|
107
|
+
const imports = createImportLookup(context.sourceCode.ast, {
|
|
108
|
+
builtinNamespaces: ["React", "ReactDOM"],
|
|
109
|
+
source: "react-dom"
|
|
110
|
+
});
|
|
109
111
|
return { CallExpression(node) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
const callee = Extract.unwrap(node.callee);
|
|
113
|
+
switch (true) {
|
|
114
|
+
case Check.isIdentifier(callee) && (callee.name === "findDOMNode" || imports.has(callee.name, "findDOMNode")):
|
|
115
|
+
context.report({
|
|
116
|
+
messageId: "default",
|
|
117
|
+
node
|
|
118
|
+
});
|
|
119
|
+
return;
|
|
120
|
+
case callee.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(callee.object) && Extract.getCalleeName(node) === "findDOMNode" && imports.hasNamespace(callee.object.name):
|
|
121
|
+
context.report({
|
|
122
|
+
messageId: "default",
|
|
123
|
+
node
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
114
127
|
} };
|
|
115
128
|
}
|
|
116
129
|
|
|
@@ -266,14 +279,17 @@ var no_missing_button_type_default = createRule({
|
|
|
266
279
|
function create$10(context) {
|
|
267
280
|
const resolver = createJsxElementResolver(context);
|
|
268
281
|
return { JSXElement(node) {
|
|
269
|
-
|
|
282
|
+
const { domElementType } = resolver.resolve(node);
|
|
283
|
+
if (domElementType !== "button") return;
|
|
270
284
|
if (hasAttribute(context, node, "type")) return;
|
|
271
285
|
context.report({
|
|
272
286
|
messageId: "missingTypeAttribute",
|
|
273
287
|
node: node.openingElement,
|
|
274
288
|
suggest: BUTTON_TYPES.map((type) => ({
|
|
275
289
|
data: { type },
|
|
276
|
-
fix
|
|
290
|
+
fix(fixer) {
|
|
291
|
+
return fixer.insertTextAfter(node.openingElement.name, ` type="${type}"`);
|
|
292
|
+
},
|
|
277
293
|
messageId: "addTypeAttribute"
|
|
278
294
|
}))
|
|
279
295
|
});
|
|
@@ -339,18 +355,13 @@ function create$9(context) {
|
|
|
339
355
|
//#endregion
|
|
340
356
|
//#region src/rules/no-render-return-value/no-render-return-value.ts
|
|
341
357
|
const RULE_NAME$8 = "no-render-return-value";
|
|
342
|
-
const
|
|
358
|
+
const BANNED_PARENT_TYPES = [
|
|
343
359
|
AST_NODE_TYPES.VariableDeclarator,
|
|
344
360
|
AST_NODE_TYPES.Property,
|
|
345
361
|
AST_NODE_TYPES.ReturnStatement,
|
|
346
362
|
AST_NODE_TYPES.ArrowFunctionExpression,
|
|
347
363
|
AST_NODE_TYPES.AssignmentExpression
|
|
348
364
|
];
|
|
349
|
-
function isReturnValueUsed(node) {
|
|
350
|
-
let parent = node.parent;
|
|
351
|
-
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
352
|
-
return banParentTypes.includes(parent.type);
|
|
353
|
-
}
|
|
354
365
|
var no_render_return_value_default = createRule({
|
|
355
366
|
meta: {
|
|
356
367
|
type: "problem",
|
|
@@ -363,9 +374,10 @@ var no_render_return_value_default = createRule({
|
|
|
363
374
|
defaultOptions: []
|
|
364
375
|
});
|
|
365
376
|
function create$8(context) {
|
|
377
|
+
if (!context.sourceCode.text.includes("render")) return {};
|
|
366
378
|
const imports = createImportLookup(context.sourceCode.ast, {
|
|
367
|
-
|
|
368
|
-
|
|
379
|
+
builtinNamespaces: ["ReactDOM"],
|
|
380
|
+
source: "react-dom"
|
|
369
381
|
});
|
|
370
382
|
return { CallExpression(node) {
|
|
371
383
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -385,6 +397,11 @@ function create$8(context) {
|
|
|
385
397
|
}
|
|
386
398
|
} };
|
|
387
399
|
}
|
|
400
|
+
function isReturnValueUsed(node) {
|
|
401
|
+
let parent = node.parent;
|
|
402
|
+
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
403
|
+
return BANNED_PARENT_TYPES.includes(parent.type);
|
|
404
|
+
}
|
|
388
405
|
|
|
389
406
|
//#endregion
|
|
390
407
|
//#region src/rules/no-render/no-render.ts
|
|
@@ -406,8 +423,8 @@ function create$7(context) {
|
|
|
406
423
|
const settings = getSettingsFromContext(context);
|
|
407
424
|
if (compare(settings.version, "18.0.0", "<")) return {};
|
|
408
425
|
const imports = createImportLookup(context.sourceCode.ast, {
|
|
409
|
-
|
|
410
|
-
|
|
426
|
+
builtinNamespaces: ["ReactDOM"],
|
|
427
|
+
source: "react-dom"
|
|
411
428
|
});
|
|
412
429
|
return { CallExpression(node) {
|
|
413
430
|
const callee = Extract.unwrap(node.callee);
|
|
@@ -429,12 +446,6 @@ function create$7(context) {
|
|
|
429
446
|
}
|
|
430
447
|
} };
|
|
431
448
|
}
|
|
432
|
-
/**
|
|
433
|
-
* Provides a fixer function to replace `render(app, container)` with `createRoot(container).render(app)`
|
|
434
|
-
* @param context The rule context
|
|
435
|
-
* @param node The `CallExpression` node to fix
|
|
436
|
-
* @returns A fixer function or null if the fix cannot be applied
|
|
437
|
-
*/
|
|
438
449
|
function buildFix$1(context, node) {
|
|
439
450
|
const getText = (n) => context.sourceCode.getText(n);
|
|
440
451
|
return (fixer) => {
|
|
@@ -489,7 +500,8 @@ function create$5(context) {
|
|
|
489
500
|
const styleProp = findAttribute(context, node, "style");
|
|
490
501
|
if (styleProp == null) return;
|
|
491
502
|
const styleValue = resolveAttributeValue(context, styleProp);
|
|
492
|
-
if (typeof styleValue.toStatic()
|
|
503
|
+
if (typeof styleValue.toStatic() !== "string") return;
|
|
504
|
+
context.report({
|
|
493
505
|
messageId: "default",
|
|
494
506
|
node: styleValue.node ?? styleProp
|
|
495
507
|
});
|
|
@@ -1579,23 +1591,10 @@ var no_unknown_property_default = createRule({
|
|
|
1579
1591
|
create: create$4,
|
|
1580
1592
|
defaultOptions: []
|
|
1581
1593
|
});
|
|
1582
|
-
/**
|
|
1583
|
-
* Create function for the ESLint rule
|
|
1584
|
-
* @param context ESLint rule context
|
|
1585
|
-
* @returns Rule listener
|
|
1586
|
-
*/
|
|
1587
1594
|
function create$4(context) {
|
|
1588
|
-
/**
|
|
1589
|
-
* Gets the ignore configuration from rule options
|
|
1590
|
-
* @returns Array of attribute names to ignore
|
|
1591
|
-
*/
|
|
1592
1595
|
function getIgnoreConfig() {
|
|
1593
1596
|
return context.options[0]?.ignore ?? DEFAULTS.ignore;
|
|
1594
1597
|
}
|
|
1595
|
-
/**
|
|
1596
|
-
* Gets the requireDataLowercase option from rule options
|
|
1597
|
-
* @returns Whether data attributes must be lowercase
|
|
1598
|
-
*/
|
|
1599
1598
|
function getRequireDataLowercase() {
|
|
1600
1599
|
return context.options[0]?.requireDataLowercase ?? DEFAULTS.requireDataLowercase;
|
|
1601
1600
|
}
|
|
@@ -1691,11 +1690,13 @@ var no_unsafe_iframe_sandbox_default = createRule({
|
|
|
1691
1690
|
function create$3(context) {
|
|
1692
1691
|
const resolver = createJsxElementResolver(context);
|
|
1693
1692
|
return { JSXElement(node) {
|
|
1694
|
-
|
|
1693
|
+
const { domElementType } = resolver.resolve(node);
|
|
1694
|
+
if (domElementType !== "iframe") return;
|
|
1695
1695
|
const sandboxProp = findAttribute(context, node, "sandbox");
|
|
1696
1696
|
if (sandboxProp == null) return;
|
|
1697
1697
|
const sandboxValue = resolveAttributeValue(context, sandboxProp, "sandbox");
|
|
1698
|
-
if (isUnsafeSandboxCombination(sandboxValue.toStatic()))
|
|
1698
|
+
if (!isUnsafeSandboxCombination(sandboxValue.toStatic())) return;
|
|
1699
|
+
context.report({
|
|
1699
1700
|
messageId: "default",
|
|
1700
1701
|
node: sandboxValue.node ?? sandboxProp
|
|
1701
1702
|
});
|
|
@@ -1750,8 +1751,8 @@ function create$2(context) {
|
|
|
1750
1751
|
const { domElementType } = resolver.resolve(node);
|
|
1751
1752
|
if (domElementType !== "a") return;
|
|
1752
1753
|
if (getAttributeStaticValue(context, node, "target") !== "_blank") return;
|
|
1753
|
-
const
|
|
1754
|
-
if (!isExternalLinkLike(
|
|
1754
|
+
const hrefValue = getAttributeStaticValue(context, node, "href");
|
|
1755
|
+
if (!isExternalLinkLike(hrefValue)) return;
|
|
1755
1756
|
const relProp = findAttribute(context, node, "rel");
|
|
1756
1757
|
if (relProp == null) {
|
|
1757
1758
|
context.report({
|
|
@@ -1766,8 +1767,8 @@ function create$2(context) {
|
|
|
1766
1767
|
});
|
|
1767
1768
|
return;
|
|
1768
1769
|
}
|
|
1769
|
-
const
|
|
1770
|
-
if (isSafeRel(
|
|
1770
|
+
const relValue = getAttributeStaticValue(context, node, "rel");
|
|
1771
|
+
if (isSafeRel(relValue)) return;
|
|
1771
1772
|
context.report({
|
|
1772
1773
|
messageId: "default",
|
|
1773
1774
|
node: relProp,
|
|
@@ -1830,7 +1831,7 @@ function buildFix(context, node) {
|
|
|
1830
1831
|
|
|
1831
1832
|
//#endregion
|
|
1832
1833
|
//#region src/rules/no-void-elements-with-children/lib.ts
|
|
1833
|
-
const
|
|
1834
|
+
const KNOWN_VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
1834
1835
|
"area",
|
|
1835
1836
|
"base",
|
|
1836
1837
|
"br",
|
|
@@ -1867,7 +1868,7 @@ function create(context) {
|
|
|
1867
1868
|
const resolver = createJsxElementResolver(context);
|
|
1868
1869
|
return { JSXElement(node) {
|
|
1869
1870
|
const { domElementType } = resolver.resolve(node);
|
|
1870
|
-
if (!
|
|
1871
|
+
if (!KNOWN_VOID_ELEMENTS.has(domElementType)) return;
|
|
1871
1872
|
if (node.children.length > 0 || hasAnyAttribute(context, node, ["children", "dangerouslySetInnerHTML"])) context.report({
|
|
1872
1873
|
data: { elementType: domElementType },
|
|
1873
1874
|
messageId: "default",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-dom",
|
|
3
|
-
"version": "5.20.
|
|
3
|
+
"version": "5.20.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for DOM related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@eslint-react/ast": "5.20.
|
|
41
|
-
"@eslint-react/core": "5.20.
|
|
42
|
-
"@eslint-react/eslint": "5.20.
|
|
43
|
-
"@eslint-react/jsx": "5.20.
|
|
44
|
-
"@eslint-react/shared": "5.20.
|
|
45
|
-
"@eslint-react/var": "5.20.
|
|
40
|
+
"@eslint-react/ast": "5.20.3",
|
|
41
|
+
"@eslint-react/core": "5.20.3",
|
|
42
|
+
"@eslint-react/eslint": "5.20.3",
|
|
43
|
+
"@eslint-react/jsx": "5.20.3",
|
|
44
|
+
"@eslint-react/shared": "5.20.3",
|
|
45
|
+
"@eslint-react/var": "5.20.3",
|
|
46
46
|
"@typescript-eslint/types": "^8.70.0",
|
|
47
47
|
"@typescript-eslint/utils": "^8.70.0",
|
|
48
48
|
"compare-versions": "^6.1.1"
|