eslint-plugin-react-dom 1.46.0 → 1.47.0-next.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var shared = require('@eslint-react/shared');
4
- var JSX = require('@eslint-react/jsx');
4
+ var ER = require('@eslint-react/core');
5
5
  var utils = require('@typescript-eslint/utils');
6
6
  var AST = require('@eslint-react/ast');
7
7
  var types = require('@typescript-eslint/types');
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
27
27
  return Object.freeze(n);
28
28
  }
29
29
 
30
- var JSX__namespace = /*#__PURE__*/_interopNamespace(JSX);
30
+ var ER__namespace = /*#__PURE__*/_interopNamespace(ER);
31
31
  var AST__namespace = /*#__PURE__*/_interopNamespace(AST);
32
32
 
33
33
  var __defProp = Object.defineProperty;
@@ -67,35 +67,54 @@ var settings = {
67
67
 
68
68
  // package.json
69
69
  var name2 = "eslint-plugin-react-dom";
70
- var version = "1.46.0";
70
+ var version = "1.47.0-next.0";
71
+ function createJsxElementResolver(context) {
72
+ const {
73
+ additionalComponents,
74
+ polymorphicPropName
75
+ } = shared.getSettingsFromContext(context);
76
+ return {
77
+ resolve(node) {
78
+ const name3 = ER__namespace.getElementType(context, node);
79
+ const component = additionalComponents.findLast((c) => c.name === name3 || c.re.test(name3));
80
+ const result = {
81
+ attributes: component?.attributes ?? [],
82
+ domElementType: component?.as ?? name3,
83
+ jsxElementType: name3
84
+ };
85
+ if (name3 === name3.toLowerCase() || component != null || polymorphicPropName == null) {
86
+ return result;
87
+ }
88
+ const initialScope = context.sourceCode.getScope(node);
89
+ const polymorphicPropAttr = ER__namespace.getAttribute(
90
+ context,
91
+ polymorphicPropName,
92
+ node.openingElement.attributes,
93
+ initialScope
94
+ );
95
+ if (polymorphicPropAttr != null) {
96
+ const polymorphicPropValue = ER__namespace.getAttributeValue(
97
+ context,
98
+ polymorphicPropAttr,
99
+ polymorphicPropName
100
+ );
101
+ if (polymorphicPropValue.kind === "some" && typeof polymorphicPropValue.value === "string") {
102
+ return {
103
+ ...result,
104
+ domElementType: polymorphicPropValue.value
105
+ };
106
+ }
107
+ }
108
+ return result;
109
+ }
110
+ };
111
+ }
71
112
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("dom"));
72
113
 
73
114
  // src/utils/find-custom-component.ts
74
- function findCustomComponent(name3, components) {
75
- return components.findLast((c) => c.name === name3 || c.re.test(name3));
76
- }
77
115
  function findCustomComponentProp(name3, props) {
78
116
  return props.findLast((a) => a.as === name3);
79
117
  }
80
- function getElementTypeOnJsxAndDom(context, node, polymorphicPropName, additionalComponents = []) {
81
- const name3 = JSX__namespace.getElementType(node);
82
- if (name3 === name3.toLowerCase()) return [name3, name3];
83
- const component = additionalComponents.findLast((c) => c.name === name3 || c.re.test(name3));
84
- if (component != null) return [name3, component.as];
85
- if (polymorphicPropName == null) return [name3, name3];
86
- const initialScope = context.sourceCode.getScope(node);
87
- const attributeNode = JSX__namespace.getAttribute(
88
- polymorphicPropName,
89
- node.openingElement.attributes,
90
- initialScope
91
- );
92
- if (attributeNode == null) return [name3, name3];
93
- const polymorphicPropValue = JSX__namespace.getAttributeValue(attributeNode, polymorphicPropName, initialScope);
94
- if (polymorphicPropValue.kind === "some" && typeof polymorphicPropValue.value === "string") {
95
- return [name3, polymorphicPropValue.value];
96
- }
97
- return [name3, name3];
98
- }
99
118
 
100
119
  // src/rules/no-dangerously-set-innerhtml.ts
101
120
  var RULE_NAME = "no-dangerously-set-innerhtml";
@@ -121,7 +140,8 @@ function create(context) {
121
140
  return {
122
141
  JSXElement(node) {
123
142
  const attributes = node.openingElement.attributes;
124
- const attribute = JSX__namespace.getAttribute(
143
+ const attribute = ER__namespace.getAttribute(
144
+ context,
125
145
  "dangerouslySetInnerHTML",
126
146
  attributes,
127
147
  context.sourceCode.getScope(node)
@@ -158,8 +178,8 @@ function create2(context) {
158
178
  JSXElement(node) {
159
179
  const attributes = node.openingElement.attributes;
160
180
  const initialScope = context.sourceCode.getScope(node);
161
- const hasChildren = hasChildrenWithin(node) || JSX__namespace.hasAttribute("children", attributes, initialScope);
162
- if (hasChildren && JSX__namespace.hasAttribute("dangerouslySetInnerHTML", attributes, initialScope)) {
181
+ const hasChildren = hasChildrenWithin(node) || ER__namespace.hasAttribute(context, "children", attributes, initialScope);
182
+ if (hasChildren && ER__namespace.hasAttribute(context, "dangerouslySetInnerHTML", attributes, initialScope)) {
163
183
  context.report({
164
184
  messageId: "noDangerouslySetInnerhtmlWithChildren",
165
185
  node
@@ -343,30 +363,25 @@ var no_missing_button_type_default = createRule({
343
363
  defaultOptions: []
344
364
  });
345
365
  function create6(context) {
346
- const settings2 = shared.getSettingsFromContext(context);
347
- const polymorphicPropName = settings2.polymorphicPropName;
348
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "button");
366
+ const resolver = createJsxElementResolver(context);
349
367
  return {
350
368
  JSXElement(node) {
351
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
352
- context,
353
- node,
354
- polymorphicPropName,
355
- additionalComponents
356
- );
357
- if (elementNameOnDom !== "button") return;
358
- const elementScope = context.sourceCode.getScope(node);
359
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
360
- const customComponentProp = findCustomComponentProp("type", customComponent?.attributes ?? []);
369
+ const { attributes, domElementType } = resolver.resolve(node);
370
+ if (domElementType !== "button") return;
371
+ const customComponentProp = findCustomComponentProp("type", attributes);
361
372
  const propNameOnJsx = customComponentProp?.name ?? "type";
362
- const attributeNode = JSX__namespace.getAttribute(
373
+ const attributeNode = ER__namespace.getAttribute(
374
+ context,
363
375
  propNameOnJsx,
364
376
  node.openingElement.attributes,
365
- elementScope
377
+ context.sourceCode.getScope(node)
366
378
  );
367
379
  if (attributeNode != null) {
368
- const attributeScope = context.sourceCode.getScope(attributeNode);
369
- const attributeValue = JSX__namespace.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
380
+ const attributeValue = ER__namespace.getAttributeValue(
381
+ context,
382
+ attributeNode,
383
+ propNameOnJsx
384
+ );
370
385
  if (attributeValue.kind === "some" && typeof attributeValue.value !== "string") {
371
386
  context.report({
372
387
  messageId: "noMissingButtonType",
@@ -424,30 +439,25 @@ var no_missing_iframe_sandbox_default = createRule({
424
439
  defaultOptions: []
425
440
  });
426
441
  function create7(context) {
427
- const settings2 = shared.getSettingsFromContext(context);
428
- const polymorphicPropName = settings2.polymorphicPropName;
429
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "iframe");
442
+ const resolver = createJsxElementResolver(context);
430
443
  return {
431
444
  JSXElement(node) {
432
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
433
- context,
434
- node,
435
- polymorphicPropName,
436
- additionalComponents
437
- );
438
- if (elementNameOnDom !== "iframe") return;
439
- const elementScope = context.sourceCode.getScope(node);
440
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
441
- const customComponentProp = findCustomComponentProp("sandbox", customComponent?.attributes ?? []);
445
+ const { attributes, domElementType } = resolver.resolve(node);
446
+ if (domElementType !== "iframe") return;
447
+ const customComponentProp = findCustomComponentProp("sandbox", attributes);
442
448
  const propNameOnJsx = customComponentProp?.name ?? "sandbox";
443
- const attributeNode = JSX__namespace.getAttribute(
449
+ const attributeNode = ER__namespace.getAttribute(
450
+ context,
444
451
  propNameOnJsx,
445
452
  node.openingElement.attributes,
446
- elementScope
453
+ context.sourceCode.getScope(node)
447
454
  );
448
455
  if (attributeNode != null) {
449
- const attributeScope = context.sourceCode.getScope(attributeNode);
450
- const attributeValue = JSX__namespace.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
456
+ const attributeValue = ER__namespace.getAttributeValue(
457
+ context,
458
+ attributeNode,
459
+ propNameOnJsx
460
+ );
451
461
  if (attributeValue.kind === "some" && hasValidSandBox(attributeValue.value)) return;
452
462
  context.report({
453
463
  messageId: "noMissingIframeSandbox",
@@ -485,7 +495,7 @@ var no_namespace_default = createRule({
485
495
  function create8(context) {
486
496
  return {
487
497
  JSXElement(node) {
488
- const name3 = JSX__namespace.getElementType(node);
498
+ const name3 = ER__namespace.getElementType(context, node);
489
499
  if (typeof name3 !== "string" || !name3.includes(":")) {
490
500
  return;
491
501
  }
@@ -652,9 +662,8 @@ function create11(context) {
652
662
  if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier || node.value == null) {
653
663
  return;
654
664
  }
655
- const attributeScope = context.sourceCode.getScope(node);
656
- const attributeName = JSX__namespace.getAttributeName(node);
657
- const attributeValue = JSX__namespace.getAttributeValue(node, attributeName, attributeScope);
665
+ const attributeName = ER__namespace.getAttributeName(context, node);
666
+ const attributeValue = ER__namespace.getAttributeValue(context, node, attributeName);
658
667
  if (attributeValue.kind === "none" || typeof attributeValue.value !== "string") return;
659
668
  if (kit.RE.JAVASCRIPT_PROTOCOL.test(attributeValue.value)) {
660
669
  context.report({
@@ -1751,30 +1760,25 @@ var no_unsafe_iframe_sandbox_default = createRule({
1751
1760
  defaultOptions: []
1752
1761
  });
1753
1762
  function create13(context) {
1754
- const settings2 = shared.getSettingsFromContext(context);
1755
- const polymorphicPropName = settings2.polymorphicPropName;
1756
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "iframe");
1763
+ const resolver = createJsxElementResolver(context);
1757
1764
  return {
1758
1765
  JSXElement(node) {
1759
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
1760
- context,
1761
- node,
1762
- polymorphicPropName,
1763
- additionalComponents
1764
- );
1765
- if (elementNameOnDom !== "iframe") return;
1766
- const elementScope = context.sourceCode.getScope(node);
1767
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
1768
- const customComponentProp = findCustomComponentProp("sandbox", customComponent?.attributes ?? []);
1766
+ const { attributes, domElementType } = resolver.resolve(node);
1767
+ if (domElementType !== "iframe") return;
1768
+ const customComponentProp = findCustomComponentProp("sandbox", attributes);
1769
1769
  const propNameOnJsx = customComponentProp?.name ?? "sandbox";
1770
- const attributeNode = JSX__namespace.getAttribute(
1770
+ const attributeNode = ER__namespace.getAttribute(
1771
+ context,
1771
1772
  propNameOnJsx,
1772
1773
  node.openingElement.attributes,
1773
- elementScope
1774
+ context.sourceCode.getScope(node)
1774
1775
  );
1775
1776
  if (attributeNode != null) {
1776
- const attributeScope = context.sourceCode.getScope(attributeNode);
1777
- const attributeValue = JSX__namespace.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
1777
+ const attributeValue = ER__namespace.getAttributeValue(
1778
+ context,
1779
+ attributeNode,
1780
+ propNameOnJsx
1781
+ );
1778
1782
  if (attributeValue.kind === "some" && !hasSafeSandbox(attributeValue.value)) {
1779
1783
  context.report({
1780
1784
  messageId: "noUnsafeIframeSandbox",
@@ -1820,31 +1824,23 @@ var no_unsafe_target_blank_default = createRule({
1820
1824
  defaultOptions: []
1821
1825
  });
1822
1826
  function create14(context) {
1823
- const settings2 = shared.getSettingsFromContext(context);
1824
- const polymorphicPropName = settings2.polymorphicPropName;
1825
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "a");
1827
+ const resolver = createJsxElementResolver(context);
1826
1828
  return {
1827
1829
  JSXElement(node) {
1828
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
1829
- context,
1830
- node,
1831
- polymorphicPropName,
1832
- additionalComponents
1833
- );
1834
- if (elementNameOnDom !== "a") return;
1830
+ const { attributes, domElementType } = resolver.resolve(node);
1831
+ if (domElementType !== "a") return;
1835
1832
  const elementScope = context.sourceCode.getScope(node);
1836
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
1837
1833
  const getAttributeStringValue = (name3) => {
1838
- const customComponentProp = findCustomComponentProp(name3, customComponent?.attributes ?? []);
1834
+ const customComponentProp = findCustomComponentProp(name3, attributes);
1839
1835
  const propNameOnJsx = customComponentProp?.name ?? name3;
1840
- const attributeNode = JSX__namespace.getAttribute(
1836
+ const attributeNode = ER__namespace.getAttribute(
1837
+ context,
1841
1838
  propNameOnJsx,
1842
1839
  node.openingElement.attributes,
1843
1840
  elementScope
1844
1841
  );
1845
1842
  if (attributeNode == null) return customComponentProp?.defaultValue;
1846
- const attributeScope = context.sourceCode.getScope(attributeNode);
1847
- const attributeValue = JSX__namespace.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
1843
+ const attributeValue = ER__namespace.getAttributeValue(context, attributeNode, propNameOnJsx);
1848
1844
  if (attributeValue.kind === "some" && typeof attributeValue.value === "string") {
1849
1845
  return attributeValue.value;
1850
1846
  }
@@ -1981,7 +1977,7 @@ var no_void_elements_with_children_default = createRule({
1981
1977
  function create16(context) {
1982
1978
  return {
1983
1979
  JSXElement(node) {
1984
- const elementName = JSX__namespace.getElementType(node);
1980
+ const elementName = ER__namespace.getElementType(context, node);
1985
1981
  if (elementName.length === 0 || !voidElements.has(elementName)) {
1986
1982
  return;
1987
1983
  }
@@ -1996,7 +1992,7 @@ function create16(context) {
1996
1992
  }
1997
1993
  const { attributes } = node.openingElement;
1998
1994
  const initialScope = context.sourceCode.getScope(node);
1999
- const hasAttribute3 = (name3) => JSX__namespace.hasAttribute(name3, attributes, initialScope);
1995
+ const hasAttribute3 = (name3) => ER__namespace.hasAttribute(context, name3, attributes, initialScope);
2000
1996
  if (hasAttribute3("children") || hasAttribute3("dangerouslySetInnerHTML")) {
2001
1997
  context.report({
2002
1998
  messageId: "noVoidElementsWithChildren",
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { getDocsUrl, getSettingsFromContext, DEFAULT_ESLINT_REACT_SETTINGS } from '@eslint-react/shared';
2
- import * as JSX from '@eslint-react/jsx';
2
+ import * as ER from '@eslint-react/core';
3
3
  import { ESLintUtils } from '@typescript-eslint/utils';
4
4
  import * as AST from '@eslint-react/ast';
5
5
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
@@ -44,35 +44,54 @@ var settings = {
44
44
 
45
45
  // package.json
46
46
  var name2 = "eslint-plugin-react-dom";
47
- var version = "1.46.0";
47
+ var version = "1.47.0-next.0";
48
+ function createJsxElementResolver(context) {
49
+ const {
50
+ additionalComponents,
51
+ polymorphicPropName
52
+ } = getSettingsFromContext(context);
53
+ return {
54
+ resolve(node) {
55
+ const name3 = ER.getElementType(context, node);
56
+ const component = additionalComponents.findLast((c) => c.name === name3 || c.re.test(name3));
57
+ const result = {
58
+ attributes: component?.attributes ?? [],
59
+ domElementType: component?.as ?? name3,
60
+ jsxElementType: name3
61
+ };
62
+ if (name3 === name3.toLowerCase() || component != null || polymorphicPropName == null) {
63
+ return result;
64
+ }
65
+ const initialScope = context.sourceCode.getScope(node);
66
+ const polymorphicPropAttr = ER.getAttribute(
67
+ context,
68
+ polymorphicPropName,
69
+ node.openingElement.attributes,
70
+ initialScope
71
+ );
72
+ if (polymorphicPropAttr != null) {
73
+ const polymorphicPropValue = ER.getAttributeValue(
74
+ context,
75
+ polymorphicPropAttr,
76
+ polymorphicPropName
77
+ );
78
+ if (polymorphicPropValue.kind === "some" && typeof polymorphicPropValue.value === "string") {
79
+ return {
80
+ ...result,
81
+ domElementType: polymorphicPropValue.value
82
+ };
83
+ }
84
+ }
85
+ return result;
86
+ }
87
+ };
88
+ }
48
89
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("dom"));
49
90
 
50
91
  // src/utils/find-custom-component.ts
51
- function findCustomComponent(name3, components) {
52
- return components.findLast((c) => c.name === name3 || c.re.test(name3));
53
- }
54
92
  function findCustomComponentProp(name3, props) {
55
93
  return props.findLast((a) => a.as === name3);
56
94
  }
57
- function getElementTypeOnJsxAndDom(context, node, polymorphicPropName, additionalComponents = []) {
58
- const name3 = JSX.getElementType(node);
59
- if (name3 === name3.toLowerCase()) return [name3, name3];
60
- const component = additionalComponents.findLast((c) => c.name === name3 || c.re.test(name3));
61
- if (component != null) return [name3, component.as];
62
- if (polymorphicPropName == null) return [name3, name3];
63
- const initialScope = context.sourceCode.getScope(node);
64
- const attributeNode = JSX.getAttribute(
65
- polymorphicPropName,
66
- node.openingElement.attributes,
67
- initialScope
68
- );
69
- if (attributeNode == null) return [name3, name3];
70
- const polymorphicPropValue = JSX.getAttributeValue(attributeNode, polymorphicPropName, initialScope);
71
- if (polymorphicPropValue.kind === "some" && typeof polymorphicPropValue.value === "string") {
72
- return [name3, polymorphicPropValue.value];
73
- }
74
- return [name3, name3];
75
- }
76
95
 
77
96
  // src/rules/no-dangerously-set-innerhtml.ts
78
97
  var RULE_NAME = "no-dangerously-set-innerhtml";
@@ -98,7 +117,8 @@ function create(context) {
98
117
  return {
99
118
  JSXElement(node) {
100
119
  const attributes = node.openingElement.attributes;
101
- const attribute = JSX.getAttribute(
120
+ const attribute = ER.getAttribute(
121
+ context,
102
122
  "dangerouslySetInnerHTML",
103
123
  attributes,
104
124
  context.sourceCode.getScope(node)
@@ -135,8 +155,8 @@ function create2(context) {
135
155
  JSXElement(node) {
136
156
  const attributes = node.openingElement.attributes;
137
157
  const initialScope = context.sourceCode.getScope(node);
138
- const hasChildren = hasChildrenWithin(node) || JSX.hasAttribute("children", attributes, initialScope);
139
- if (hasChildren && JSX.hasAttribute("dangerouslySetInnerHTML", attributes, initialScope)) {
158
+ const hasChildren = hasChildrenWithin(node) || ER.hasAttribute(context, "children", attributes, initialScope);
159
+ if (hasChildren && ER.hasAttribute(context, "dangerouslySetInnerHTML", attributes, initialScope)) {
140
160
  context.report({
141
161
  messageId: "noDangerouslySetInnerhtmlWithChildren",
142
162
  node
@@ -320,30 +340,25 @@ var no_missing_button_type_default = createRule({
320
340
  defaultOptions: []
321
341
  });
322
342
  function create6(context) {
323
- const settings2 = getSettingsFromContext(context);
324
- const polymorphicPropName = settings2.polymorphicPropName;
325
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "button");
343
+ const resolver = createJsxElementResolver(context);
326
344
  return {
327
345
  JSXElement(node) {
328
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
329
- context,
330
- node,
331
- polymorphicPropName,
332
- additionalComponents
333
- );
334
- if (elementNameOnDom !== "button") return;
335
- const elementScope = context.sourceCode.getScope(node);
336
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
337
- const customComponentProp = findCustomComponentProp("type", customComponent?.attributes ?? []);
346
+ const { attributes, domElementType } = resolver.resolve(node);
347
+ if (domElementType !== "button") return;
348
+ const customComponentProp = findCustomComponentProp("type", attributes);
338
349
  const propNameOnJsx = customComponentProp?.name ?? "type";
339
- const attributeNode = JSX.getAttribute(
350
+ const attributeNode = ER.getAttribute(
351
+ context,
340
352
  propNameOnJsx,
341
353
  node.openingElement.attributes,
342
- elementScope
354
+ context.sourceCode.getScope(node)
343
355
  );
344
356
  if (attributeNode != null) {
345
- const attributeScope = context.sourceCode.getScope(attributeNode);
346
- const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
357
+ const attributeValue = ER.getAttributeValue(
358
+ context,
359
+ attributeNode,
360
+ propNameOnJsx
361
+ );
347
362
  if (attributeValue.kind === "some" && typeof attributeValue.value !== "string") {
348
363
  context.report({
349
364
  messageId: "noMissingButtonType",
@@ -401,30 +416,25 @@ var no_missing_iframe_sandbox_default = createRule({
401
416
  defaultOptions: []
402
417
  });
403
418
  function create7(context) {
404
- const settings2 = getSettingsFromContext(context);
405
- const polymorphicPropName = settings2.polymorphicPropName;
406
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "iframe");
419
+ const resolver = createJsxElementResolver(context);
407
420
  return {
408
421
  JSXElement(node) {
409
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
410
- context,
411
- node,
412
- polymorphicPropName,
413
- additionalComponents
414
- );
415
- if (elementNameOnDom !== "iframe") return;
416
- const elementScope = context.sourceCode.getScope(node);
417
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
418
- const customComponentProp = findCustomComponentProp("sandbox", customComponent?.attributes ?? []);
422
+ const { attributes, domElementType } = resolver.resolve(node);
423
+ if (domElementType !== "iframe") return;
424
+ const customComponentProp = findCustomComponentProp("sandbox", attributes);
419
425
  const propNameOnJsx = customComponentProp?.name ?? "sandbox";
420
- const attributeNode = JSX.getAttribute(
426
+ const attributeNode = ER.getAttribute(
427
+ context,
421
428
  propNameOnJsx,
422
429
  node.openingElement.attributes,
423
- elementScope
430
+ context.sourceCode.getScope(node)
424
431
  );
425
432
  if (attributeNode != null) {
426
- const attributeScope = context.sourceCode.getScope(attributeNode);
427
- const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
433
+ const attributeValue = ER.getAttributeValue(
434
+ context,
435
+ attributeNode,
436
+ propNameOnJsx
437
+ );
428
438
  if (attributeValue.kind === "some" && hasValidSandBox(attributeValue.value)) return;
429
439
  context.report({
430
440
  messageId: "noMissingIframeSandbox",
@@ -462,7 +472,7 @@ var no_namespace_default = createRule({
462
472
  function create8(context) {
463
473
  return {
464
474
  JSXElement(node) {
465
- const name3 = JSX.getElementType(node);
475
+ const name3 = ER.getElementType(context, node);
466
476
  if (typeof name3 !== "string" || !name3.includes(":")) {
467
477
  return;
468
478
  }
@@ -629,9 +639,8 @@ function create11(context) {
629
639
  if (node.name.type !== AST_NODE_TYPES.JSXIdentifier || node.value == null) {
630
640
  return;
631
641
  }
632
- const attributeScope = context.sourceCode.getScope(node);
633
- const attributeName = JSX.getAttributeName(node);
634
- const attributeValue = JSX.getAttributeValue(node, attributeName, attributeScope);
642
+ const attributeName = ER.getAttributeName(context, node);
643
+ const attributeValue = ER.getAttributeValue(context, node, attributeName);
635
644
  if (attributeValue.kind === "none" || typeof attributeValue.value !== "string") return;
636
645
  if (RE.JAVASCRIPT_PROTOCOL.test(attributeValue.value)) {
637
646
  context.report({
@@ -1728,30 +1737,25 @@ var no_unsafe_iframe_sandbox_default = createRule({
1728
1737
  defaultOptions: []
1729
1738
  });
1730
1739
  function create13(context) {
1731
- const settings2 = getSettingsFromContext(context);
1732
- const polymorphicPropName = settings2.polymorphicPropName;
1733
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "iframe");
1740
+ const resolver = createJsxElementResolver(context);
1734
1741
  return {
1735
1742
  JSXElement(node) {
1736
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
1737
- context,
1738
- node,
1739
- polymorphicPropName,
1740
- additionalComponents
1741
- );
1742
- if (elementNameOnDom !== "iframe") return;
1743
- const elementScope = context.sourceCode.getScope(node);
1744
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
1745
- const customComponentProp = findCustomComponentProp("sandbox", customComponent?.attributes ?? []);
1743
+ const { attributes, domElementType } = resolver.resolve(node);
1744
+ if (domElementType !== "iframe") return;
1745
+ const customComponentProp = findCustomComponentProp("sandbox", attributes);
1746
1746
  const propNameOnJsx = customComponentProp?.name ?? "sandbox";
1747
- const attributeNode = JSX.getAttribute(
1747
+ const attributeNode = ER.getAttribute(
1748
+ context,
1748
1749
  propNameOnJsx,
1749
1750
  node.openingElement.attributes,
1750
- elementScope
1751
+ context.sourceCode.getScope(node)
1751
1752
  );
1752
1753
  if (attributeNode != null) {
1753
- const attributeScope = context.sourceCode.getScope(attributeNode);
1754
- const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
1754
+ const attributeValue = ER.getAttributeValue(
1755
+ context,
1756
+ attributeNode,
1757
+ propNameOnJsx
1758
+ );
1755
1759
  if (attributeValue.kind === "some" && !hasSafeSandbox(attributeValue.value)) {
1756
1760
  context.report({
1757
1761
  messageId: "noUnsafeIframeSandbox",
@@ -1797,31 +1801,23 @@ var no_unsafe_target_blank_default = createRule({
1797
1801
  defaultOptions: []
1798
1802
  });
1799
1803
  function create14(context) {
1800
- const settings2 = getSettingsFromContext(context);
1801
- const polymorphicPropName = settings2.polymorphicPropName;
1802
- const additionalComponents = settings2.additionalComponents.filter((c) => c.as === "a");
1804
+ const resolver = createJsxElementResolver(context);
1803
1805
  return {
1804
1806
  JSXElement(node) {
1805
- const [elementNameOnJsx, elementNameOnDom] = getElementTypeOnJsxAndDom(
1806
- context,
1807
- node,
1808
- polymorphicPropName,
1809
- additionalComponents
1810
- );
1811
- if (elementNameOnDom !== "a") return;
1807
+ const { attributes, domElementType } = resolver.resolve(node);
1808
+ if (domElementType !== "a") return;
1812
1809
  const elementScope = context.sourceCode.getScope(node);
1813
- const customComponent = findCustomComponent(elementNameOnJsx, additionalComponents);
1814
1810
  const getAttributeStringValue = (name3) => {
1815
- const customComponentProp = findCustomComponentProp(name3, customComponent?.attributes ?? []);
1811
+ const customComponentProp = findCustomComponentProp(name3, attributes);
1816
1812
  const propNameOnJsx = customComponentProp?.name ?? name3;
1817
- const attributeNode = JSX.getAttribute(
1813
+ const attributeNode = ER.getAttribute(
1814
+ context,
1818
1815
  propNameOnJsx,
1819
1816
  node.openingElement.attributes,
1820
1817
  elementScope
1821
1818
  );
1822
1819
  if (attributeNode == null) return customComponentProp?.defaultValue;
1823
- const attributeScope = context.sourceCode.getScope(attributeNode);
1824
- const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
1820
+ const attributeValue = ER.getAttributeValue(context, attributeNode, propNameOnJsx);
1825
1821
  if (attributeValue.kind === "some" && typeof attributeValue.value === "string") {
1826
1822
  return attributeValue.value;
1827
1823
  }
@@ -1958,7 +1954,7 @@ var no_void_elements_with_children_default = createRule({
1958
1954
  function create16(context) {
1959
1955
  return {
1960
1956
  JSXElement(node) {
1961
- const elementName = JSX.getElementType(node);
1957
+ const elementName = ER.getElementType(context, node);
1962
1958
  if (elementName.length === 0 || !voidElements.has(elementName)) {
1963
1959
  return;
1964
1960
  }
@@ -1973,7 +1969,7 @@ function create16(context) {
1973
1969
  }
1974
1970
  const { attributes } = node.openingElement;
1975
1971
  const initialScope = context.sourceCode.getScope(node);
1976
- const hasAttribute3 = (name3) => JSX.hasAttribute(name3, attributes, initialScope);
1972
+ const hasAttribute3 = (name3) => ER.hasAttribute(context, name3, attributes, initialScope);
1977
1973
  if (hasAttribute3("children") || hasAttribute3("dangerouslySetInnerHTML")) {
1978
1974
  context.report({
1979
1975
  messageId: "noVoidElementsWithChildren",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-dom",
3
- "version": "1.46.0",
3
+ "version": "1.47.0-next.0",
4
4
  "description": "ESLint React's ESLint plugin for React DOM related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -49,13 +49,12 @@
49
49
  "compare-versions": "^6.1.1",
50
50
  "string-ts": "^2.2.1",
51
51
  "ts-pattern": "^5.7.0",
52
- "@eslint-react/ast": "1.46.0",
53
- "@eslint-react/core": "1.46.0",
54
- "@eslint-react/jsx": "1.46.0",
55
- "@eslint-react/eff": "1.46.0",
56
- "@eslint-react/shared": "1.46.0",
57
- "@eslint-react/var": "1.46.0",
58
- "@eslint-react/kit": "1.46.0"
52
+ "@eslint-react/ast": "1.47.0-next.0",
53
+ "@eslint-react/core": "1.47.0-next.0",
54
+ "@eslint-react/eff": "1.47.0-next.0",
55
+ "@eslint-react/kit": "1.47.0-next.0",
56
+ "@eslint-react/var": "1.47.0-next.0",
57
+ "@eslint-react/shared": "1.47.0-next.0"
59
58
  },
60
59
  "devDependencies": {
61
60
  "@types/react": "^19.1.1",