eslint-plugin-react-dom 3.0.0-beta.69 → 3.0.0-beta.70
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 +36 -27
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS, RE_JAVASCRIPT_PROTOCOL, WEBSITE_URL, defineRuleListener, getSettingsFromContext } from "@eslint-react/shared";
|
|
2
|
-
import
|
|
2
|
+
import { JsxInspector } from "@eslint-react/core";
|
|
3
3
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
4
4
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
5
5
|
import { compare } from "compare-versions";
|
|
@@ -24,7 +24,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region package.json
|
|
26
26
|
var name$2 = "eslint-plugin-react-dom";
|
|
27
|
-
var version = "3.0.0-beta.
|
|
27
|
+
var version = "3.0.0-beta.70";
|
|
28
28
|
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/utils/create-jsx-element-resolver.ts
|
|
@@ -41,16 +41,17 @@ var version = "3.0.0-beta.69";
|
|
|
41
41
|
*/
|
|
42
42
|
function createJsxElementResolver(context) {
|
|
43
43
|
const { polymorphicPropName } = getSettingsFromContext(context);
|
|
44
|
+
const jsx = JsxInspector.from(context);
|
|
44
45
|
return { resolve(node) {
|
|
45
|
-
const elementName =
|
|
46
|
+
const elementName = jsx.getElementType(node);
|
|
46
47
|
const result = {
|
|
47
48
|
domElementType: elementName,
|
|
48
49
|
jsxElementType: elementName
|
|
49
50
|
};
|
|
50
51
|
if (elementName === elementName.toLowerCase() || polymorphicPropName == null) return result;
|
|
51
|
-
const polymorphicProp =
|
|
52
|
+
const polymorphicProp = jsx.findAttribute(node, polymorphicPropName);
|
|
52
53
|
if (polymorphicProp != null) {
|
|
53
|
-
const polyPropValue =
|
|
54
|
+
const polyPropValue = jsx.resolveAttributeValue(polymorphicProp);
|
|
54
55
|
const polyPropValueString = polyPropValue.kind === "spreadProps" ? polyPropValue.getProperty(polymorphicPropName) : polyPropValue.toStatic();
|
|
55
56
|
if (typeof polyPropValueString === "string") return {
|
|
56
57
|
...result,
|
|
@@ -89,15 +90,15 @@ const DSIH$1 = "dangerouslySetInnerHTML";
|
|
|
89
90
|
* @returns `true` if the node is significant, `false` otherwise
|
|
90
91
|
*/
|
|
91
92
|
function isSignificantChildren(node) {
|
|
92
|
-
if (!
|
|
93
|
+
if (!JsxInspector.isJsxText(node)) return true;
|
|
93
94
|
return !(node.raw.trim() === "" && node.raw.includes("\n"));
|
|
94
95
|
}
|
|
95
96
|
function create$17(context) {
|
|
96
97
|
if (!context.sourceCode.text.includes(DSIH$1)) return {};
|
|
98
|
+
const jsx = JsxInspector.from(context);
|
|
97
99
|
return defineRuleListener({ JSXElement(node) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const childrenPropOrNode = findJsxAttribute("children") ?? node.children.find(isSignificantChildren);
|
|
100
|
+
if (!jsx.hasAttribute(node, DSIH$1)) return;
|
|
101
|
+
const childrenPropOrNode = jsx.findAttribute(node, "children") ?? node.children.find(isSignificantChildren);
|
|
101
102
|
if (childrenPropOrNode == null) return;
|
|
102
103
|
context.report({
|
|
103
104
|
messageId: "default",
|
|
@@ -123,8 +124,9 @@ var no_dangerously_set_innerhtml_default = createRule({
|
|
|
123
124
|
});
|
|
124
125
|
function create$16(context) {
|
|
125
126
|
if (!context.sourceCode.text.includes(DSIH)) return {};
|
|
127
|
+
const jsx = JsxInspector.from(context);
|
|
126
128
|
return defineRuleListener({ JSXElement(node) {
|
|
127
|
-
const dsihProp =
|
|
129
|
+
const dsihProp = jsx.findAttribute(node, DSIH);
|
|
128
130
|
if (dsihProp == null) return;
|
|
129
131
|
context.report({
|
|
130
132
|
messageId: "default",
|
|
@@ -295,9 +297,10 @@ var no_missing_button_type_default = createRule({
|
|
|
295
297
|
});
|
|
296
298
|
function create$12(context) {
|
|
297
299
|
const resolver = createJsxElementResolver(context);
|
|
300
|
+
const jsx = JsxInspector.from(context);
|
|
298
301
|
return defineRuleListener({ JSXElement(node) {
|
|
299
302
|
if (resolver.resolve(node).domElementType !== "button") return;
|
|
300
|
-
if (
|
|
303
|
+
if (jsx.hasAttribute(node, "type")) return;
|
|
301
304
|
context.report({
|
|
302
305
|
messageId: "missingTypeAttribute",
|
|
303
306
|
node: node.openingElement,
|
|
@@ -331,10 +334,11 @@ var no_missing_iframe_sandbox_default = createRule({
|
|
|
331
334
|
});
|
|
332
335
|
function create$11(context) {
|
|
333
336
|
const resolver = createJsxElementResolver(context);
|
|
337
|
+
const jsx = JsxInspector.from(context);
|
|
334
338
|
return defineRuleListener({ JSXElement(node) {
|
|
335
339
|
const { domElementType } = resolver.resolve(node);
|
|
336
340
|
if (domElementType !== "iframe") return;
|
|
337
|
-
const sandboxProp =
|
|
341
|
+
const sandboxProp = jsx.findAttribute(node, "sandbox");
|
|
338
342
|
if (sandboxProp == null) {
|
|
339
343
|
context.report({
|
|
340
344
|
messageId: "missingSandboxAttribute",
|
|
@@ -349,7 +353,7 @@ function create$11(context) {
|
|
|
349
353
|
});
|
|
350
354
|
return;
|
|
351
355
|
}
|
|
352
|
-
const sandboxValue =
|
|
356
|
+
const sandboxValue = jsx.resolveAttributeValue(sandboxProp);
|
|
353
357
|
if (typeof sandboxValue.toStatic() === "string") return;
|
|
354
358
|
if (sandboxValue.kind === "spreadProps" && typeof sandboxValue.getProperty("sandbox") === "string") return;
|
|
355
359
|
context.report({
|
|
@@ -382,8 +386,9 @@ var no_namespace_default = createRule({
|
|
|
382
386
|
defaultOptions: []
|
|
383
387
|
});
|
|
384
388
|
function create$10(context) {
|
|
389
|
+
const jsx = JsxInspector.from(context);
|
|
385
390
|
return defineRuleListener({ JSXElement(node) {
|
|
386
|
-
const name =
|
|
391
|
+
const name = jsx.getElementType(node);
|
|
387
392
|
if (typeof name !== "string" || !name.includes(":")) return;
|
|
388
393
|
context.report({
|
|
389
394
|
data: { name },
|
|
@@ -536,9 +541,10 @@ var no_script_url_default = createRule({
|
|
|
536
541
|
defaultOptions: []
|
|
537
542
|
});
|
|
538
543
|
function create$7(context) {
|
|
544
|
+
const jsx = JsxInspector.from(context);
|
|
539
545
|
return defineRuleListener({ JSXAttribute(node) {
|
|
540
546
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier || node.value == null) return;
|
|
541
|
-
const value =
|
|
547
|
+
const value = jsx.resolveAttributeValue(node).toStatic();
|
|
542
548
|
if (typeof value === "string" && RE_JAVASCRIPT_PROTOCOL.test(value)) context.report({
|
|
543
549
|
messageId: "default",
|
|
544
550
|
node: node.value
|
|
@@ -561,11 +567,12 @@ var no_string_style_prop_default = createRule({
|
|
|
561
567
|
defaultOptions: []
|
|
562
568
|
});
|
|
563
569
|
function create$6(context) {
|
|
570
|
+
const jsx = JsxInspector.from(context);
|
|
564
571
|
return defineRuleListener({ JSXElement(node) {
|
|
565
|
-
if (!
|
|
566
|
-
const styleProp =
|
|
572
|
+
if (!jsx.isHostElement(node)) return;
|
|
573
|
+
const styleProp = jsx.findAttribute(node, "style");
|
|
567
574
|
if (styleProp == null) return;
|
|
568
|
-
const styleValue =
|
|
575
|
+
const styleValue = jsx.resolveAttributeValue(styleProp);
|
|
569
576
|
if (typeof styleValue.toStatic() === "string") context.report({
|
|
570
577
|
messageId: "default",
|
|
571
578
|
node: styleValue.node ?? styleProp
|
|
@@ -1736,11 +1743,12 @@ var no_unsafe_iframe_sandbox_default = createRule({
|
|
|
1736
1743
|
});
|
|
1737
1744
|
function create$4(context) {
|
|
1738
1745
|
const resolver = createJsxElementResolver(context);
|
|
1746
|
+
const jsx = JsxInspector.from(context);
|
|
1739
1747
|
return defineRuleListener({ JSXElement(node) {
|
|
1740
1748
|
if (resolver.resolve(node).domElementType !== "iframe") return;
|
|
1741
|
-
const sandboxProp =
|
|
1749
|
+
const sandboxProp = jsx.findAttribute(node, "sandbox");
|
|
1742
1750
|
if (sandboxProp == null) return;
|
|
1743
|
-
const sandboxValue =
|
|
1751
|
+
const sandboxValue = jsx.resolveAttributeValue(sandboxProp);
|
|
1744
1752
|
if (isUnsafeSandboxCombination(sandboxValue.kind === "spreadProps" ? sandboxValue.getProperty("sandbox") : sandboxValue.toStatic())) context.report({
|
|
1745
1753
|
messageId: "default",
|
|
1746
1754
|
node: sandboxValue.node ?? sandboxProp
|
|
@@ -1789,17 +1797,18 @@ var no_unsafe_target_blank_default = createRule({
|
|
|
1789
1797
|
});
|
|
1790
1798
|
function create$3(context) {
|
|
1791
1799
|
const resolver = createJsxElementResolver(context);
|
|
1800
|
+
const jsx = JsxInspector.from(context);
|
|
1792
1801
|
return defineRuleListener({ JSXElement(node) {
|
|
1793
1802
|
const { domElementType } = resolver.resolve(node);
|
|
1794
1803
|
if (domElementType !== "a") return;
|
|
1795
|
-
const findAttribute =
|
|
1804
|
+
const findAttribute = (name) => jsx.findAttribute(node, name);
|
|
1796
1805
|
const targetProp = findAttribute("target");
|
|
1797
1806
|
if (targetProp == null) return;
|
|
1798
|
-
const targetValue =
|
|
1807
|
+
const targetValue = jsx.resolveAttributeValue(targetProp);
|
|
1799
1808
|
if ((targetValue.kind === "spreadProps" ? targetValue.getProperty("target") : targetValue.toStatic()) !== "_blank") return;
|
|
1800
1809
|
const hrefProp = findAttribute("href");
|
|
1801
1810
|
if (hrefProp == null) return;
|
|
1802
|
-
const hrefValue =
|
|
1811
|
+
const hrefValue = jsx.resolveAttributeValue(hrefProp);
|
|
1803
1812
|
if (!isExternalLinkLike(hrefValue.kind === "spreadProps" ? hrefValue.getProperty("href") : hrefValue.toStatic())) return;
|
|
1804
1813
|
const relProp = findAttribute("rel");
|
|
1805
1814
|
if (relProp == null) {
|
|
@@ -1815,7 +1824,7 @@ function create$3(context) {
|
|
|
1815
1824
|
});
|
|
1816
1825
|
return;
|
|
1817
1826
|
}
|
|
1818
|
-
const relValue =
|
|
1827
|
+
const relValue = jsx.resolveAttributeValue(relProp);
|
|
1819
1828
|
if (isSafeRel(relValue.kind === "spreadProps" ? relValue.getProperty("rel") : relValue.toStatic())) return;
|
|
1820
1829
|
context.report({
|
|
1821
1830
|
messageId: "default",
|
|
@@ -1926,12 +1935,12 @@ var no_void_elements_with_children_default = createRule({
|
|
|
1926
1935
|
});
|
|
1927
1936
|
function create$1(context) {
|
|
1928
1937
|
const resolver = createJsxElementResolver(context);
|
|
1938
|
+
const jsx = JsxInspector.from(context);
|
|
1929
1939
|
return defineRuleListener({ JSXElement(node) {
|
|
1930
1940
|
const { domElementType } = resolver.resolve(node);
|
|
1931
1941
|
if (!voidElements.has(domElementType)) return;
|
|
1932
|
-
const
|
|
1933
|
-
const
|
|
1934
|
-
const hasDangerouslySetInnerHTML = findJsxAttribute("dangerouslySetInnerHTML") != null;
|
|
1942
|
+
const hasChildrenProp = jsx.hasAttribute(node, "children");
|
|
1943
|
+
const hasDangerouslySetInnerHTML = jsx.hasAttribute(node, "dangerouslySetInnerHTML");
|
|
1935
1944
|
if (node.children.length > 0 || hasChildrenProp || hasDangerouslySetInnerHTML) context.report({
|
|
1936
1945
|
data: { elementType: domElementType },
|
|
1937
1946
|
messageId: "default",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-dom",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.70",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for DOM related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"@typescript-eslint/utils": "canary",
|
|
44
44
|
"compare-versions": "^6.1.1",
|
|
45
45
|
"ts-pattern": "^5.9.0",
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/var": "3.0.0-beta.
|
|
46
|
+
"@eslint-react/core": "3.0.0-beta.70",
|
|
47
|
+
"@eslint-react/eff": "3.0.0-beta.70",
|
|
48
|
+
"@eslint-react/shared": "3.0.0-beta.70",
|
|
49
|
+
"@eslint-react/ast": "3.0.0-beta.70",
|
|
50
|
+
"@eslint-react/var": "3.0.0-beta.70"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/react": "^19.2.14",
|