Skip to content

Commit e4328b2

Browse files
committed
perf(plugins/dom): improve pref of 'no-children-in-void-dom-elements'
1 parent ad4133e commit e4328b2

File tree

2 files changed

+1
-58
lines changed

2 files changed

+1
-58
lines changed

packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.spec.ts

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -39,62 +39,6 @@ ruleTester.run(RULE_NAME, rule, {
3939
},
4040
],
4141
},
42-
{
43-
code: /* tsx */ `<PolyComponent as="br">Foo</PolyComponent>;`,
44-
errors: [
45-
{
46-
messageId: "noChildrenInVoidDomElements",
47-
data: { element: "br" },
48-
},
49-
],
50-
settings: {
51-
"react-x": {
52-
polymorphicPropName: "as",
53-
},
54-
},
55-
},
56-
{
57-
code: /* tsx */ `<PolyComponent as="br" children="Foo" />;`,
58-
errors: [
59-
{
60-
messageId: "noChildrenInVoidDomElements",
61-
data: { element: "br" },
62-
},
63-
],
64-
settings: {
65-
"react-x": {
66-
polymorphicPropName: "as",
67-
},
68-
},
69-
},
70-
{
71-
code: /* tsx */ `<PolyComponent as="img" {...props} children="Foo" />;`,
72-
errors: [
73-
{
74-
messageId: "noChildrenInVoidDomElements",
75-
data: { element: "img" },
76-
},
77-
],
78-
settings: {
79-
"react-x": {
80-
polymorphicPropName: "as",
81-
},
82-
},
83-
},
84-
{
85-
code: /* tsx */ `<PolyComponent as="br" dangerouslySetInnerHTML={{ __html: "Foo" }} />;`,
86-
errors: [
87-
{
88-
messageId: "noChildrenInVoidDomElements",
89-
data: { element: "br" },
90-
},
91-
],
92-
settings: {
93-
"react-x": {
94-
polymorphicPropName: "as",
95-
},
96-
},
97-
},
9842
],
9943
valid: [
10044
...allValid,

packages/plugins/eslint-plugin-react-dom/src/rules/no-children-in-void-dom-elements.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { getElementRepresentName } from "@eslint-react/core";
21
import * as JSX from "@eslint-react/jsx";
32
import { O } from "@eslint-react/tools";
43
import type { CamelCase } from "string-ts";
@@ -44,7 +43,7 @@ export default createRule<[], MessageID>({
4443
create(context) {
4544
return {
4645
JSXElement(node) {
47-
const elementName = getElementRepresentName(node.openingElement, context);
46+
const elementName = JSX.getElementName(node.openingElement);
4847
if (!elementName || !voidElements.includes(elementName)) return;
4948
if (node.children.length > 0) {
5049
context.report({

0 commit comments

Comments
 (0)