Skip to content

Commit 063f129

Browse files
authored
refactor: rename 'no-children-in-void-dom-elements' to 'no-void-eleme… (#888)
1 parent de5dff8 commit 063f129

File tree

17 files changed

+55
-42
lines changed

17 files changed

+55
-42
lines changed

CHANGELOG.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## v1.22.0 (Draft)
2+
3+
### 🪄 Improvements
4+
5+
- refactor(plugins/dom): rename `no-children-in-void-dom-elements` to `no-void-elements-with-children` (the previous rule will still be available until the next major update to avoid breaking changes).
6+
17
## v1.21.0 (Fri 20 Dec 2024)
28

39
### ✨ New
@@ -6,7 +12,7 @@
612

713
### 🪄 Improvements
814

9-
- refactor(plugins/hooks-extra): deprecate rule `hooks-extra/no-redundant-custom-hook` in favor of `hooks-extra/no-useless-custom-hooks` (the previous rule will still be available until the next major update to avoid breaking changes).
15+
- refactor(plugins/hooks-extra): deprecate rule `no-redundant-custom-hook` in favor of `no-useless-custom-hooks` (the previous rule will still be available until the next major update to avoid breaking changes).
1016

1117
### 📝 Changes in Rule implementation
1218

@@ -66,7 +72,7 @@ function useAuth() {
6672

6773
### 🪄 Improvements
6874

69-
- perf(plugins/dom): improve performance of `no-children-in-void-dom-elements` by @Rel1cx
75+
- perf(plugins/dom): improve performance of `no-void-elements-with-children` by @Rel1cx
7076

7177
## v1.17.3 (Tue 3 Dec 2024)
7278

@@ -766,7 +772,7 @@ function useAuth() {
766772
### 🐞 Fixes
767773

768774
- Fix rule `react-dom/no-namespace` not renamed in v1.0.0.
769-
- Fix rule `react-dom/no-children-in-void-dom-elements` not renamed in v1.0.0.
775+
- Fix rule `react-dom/no-void-elements-with-children` not renamed in v1.0.0.
770776

771777
### 🪄 Improvements
772778

@@ -788,7 +794,7 @@ function useAuth() {
788794

789795
#### All DOM related rules are moved to `react-dom` namespace
790796

791-
- Rename rule `react/no-children-in-void-dom-elements` to `react-dom/no-children-in-void-dom-elements`.
797+
- Rename rule `react/no-void-elements-with-children` to `react-dom/no-void-elements-with-children`.
792798
- Rename rule `react/no-dangerously-set-innerhtml-with-children` to `react-dom/no-dangerously-set-innerhtml-with-children`.
793799
- Rename rule `react/no-dangerously-set-innerhtml` to `react-dom/no-dangerously-set-innerhtml`.
794800
- Rename rule `react/no-find-dom-node` to `react-dom/no-find-dom-node`.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
130130
- [eslint-plugin-functional](https://github.com/eslint-functional/eslint-plugin-functional)
131131
- [eslint-plugin-perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist)
132132
- [eslint-plugin-filenames-simple](https://github.com/epaew/eslint-plugin-filenames-simple)
133-
- [rome/tools](https://github.com/rome/tools)
133+
- [biomejs.dev/linter/rules-sources/#eslint-plugin-react](https://biomejs.dev/linter/rules-sources/#eslint-plugin-react)

packages/plugins/eslint-plugin-react-debug/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export default {
1515
hook: hook,
1616
"is-from-react": isFromReact,
1717

18-
// Deprecated rules
19-
/** @deprecated Use `hook` rule instead */
18+
// Part: deprecated rules
19+
/** @deprecated Use `hook` instead */
2020
"react-hooks": hook,
2121
},
2222
} as const;

packages/plugins/eslint-plugin-react-dom/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default [
2929
},
3030
rules: {
3131
// react-dom recommended rules
32-
"react-dom/no-children-in-void-dom-elements": "warn",
3332
"react-dom/no-dangerously-set-innerhtml-with-children": "error",
3433
"react-dom/no-dangerously-set-innerhtml": "warn",
3534
"react-dom/no-find-dom-node": "error",
@@ -41,6 +40,7 @@ export default [
4140
"react-dom/no-unknown-property": "warn",
4241
"react-dom/no-unsafe-iframe-sandbox": "warn",
4342
"react-dom/no-unsafe-target-blank": "warn",
43+
"react-dom/no-void-elements-with-children": "warn",
4444
},
4545
},
4646
];

packages/plugins/eslint-plugin-react-dom/src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { name, version } from "../package.json";
2-
import noChildrenInVoidDomElements from "./rules/no-children-in-void-dom-elements";
32
import noDangerouslySetInnerHTML from "./rules/no-dangerously-set-innerhtml";
43
import noDangerouslySetInnerHTMLWithChildren from "./rules/no-dangerously-set-innerhtml-with-children";
54
import noFindDomNode from "./rules/no-find-dom-node";
@@ -11,14 +10,14 @@ import noScriptUrl from "./rules/no-script-url";
1110
import noUnknownProperty from "./rules/no-unknown-property";
1211
import noUnsafeIframeSandbox from "./rules/no-unsafe-iframe-sandbox";
1312
import noUnsafeTargetBlank from "./rules/no-unsafe-target-blank";
13+
import noVoidElementsWithChildren from "./rules/no-void-elements-with-children";
1414

1515
export default {
1616
meta: {
1717
name,
1818
version,
1919
},
2020
rules: {
21-
"no-children-in-void-dom-elements": noChildrenInVoidDomElements,
2221
"no-dangerously-set-innerhtml": noDangerouslySetInnerHTML,
2322
"no-dangerously-set-innerhtml-with-children": noDangerouslySetInnerHTMLWithChildren,
2423
"no-find-dom-node": noFindDomNode,
@@ -30,5 +29,10 @@ export default {
3029
"no-unknown-property": noUnknownProperty,
3130
"no-unsafe-iframe-sandbox": noUnsafeIframeSandbox,
3231
"no-unsafe-target-blank": noUnsafeTargetBlank,
32+
"no-void-elements-with-children": noVoidElementsWithChildren,
33+
34+
// Part: deprecated rules
35+
/** @deprecated Use `no-void-elements-with-children` instead */
36+
"no-children-in-void-dom-elements": noVoidElementsWithChildren,
3337
},
3438
} as const;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { allValid, ruleTester } from "../../../../../test";
2-
import rule, { RULE_NAME } from "./no-children-in-void-dom-elements";
2+
import rule, { RULE_NAME } from "./no-void-elements-with-children";
33

44
ruleTester.run(RULE_NAME, rule, {
55
invalid: [
66
{
77
code: /* tsx */ `<br>Foo</br>;`,
88
errors: [
99
{
10-
messageId: "noChildrenInVoidDomElements",
10+
messageId: "noVoidElementsWithChildren",
1111
data: { element: "br" },
1212
},
1313
],
@@ -16,7 +16,7 @@ ruleTester.run(RULE_NAME, rule, {
1616
code: /* tsx */ `<br children="Foo" />;`,
1717
errors: [
1818
{
19-
messageId: "noChildrenInVoidDomElements",
19+
messageId: "noVoidElementsWithChildren",
2020
data: { element: "br" },
2121
},
2222
],
@@ -25,7 +25,7 @@ ruleTester.run(RULE_NAME, rule, {
2525
code: /* tsx */ `<img {...props} children="Foo" />;`,
2626
errors: [
2727
{
28-
messageId: "noChildrenInVoidDomElements",
28+
messageId: "noVoidElementsWithChildren",
2929
data: { element: "img" },
3030
},
3131
],
@@ -34,7 +34,7 @@ ruleTester.run(RULE_NAME, rule, {
3434
code: /* tsx */ `<br dangerouslySetInnerHTML={{ __html: "Foo" }} />;`,
3535
errors: [
3636
{
37-
messageId: "noChildrenInVoidDomElements",
37+
messageId: "noVoidElementsWithChildren",
3838
data: { element: "br" },
3939
},
4040
],

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ import type { CamelCase } from "string-ts";
55

66
import { createRule } from "../utils";
77

8-
export const RULE_NAME = "no-children-in-void-dom-elements";
8+
export const RULE_NAME = "no-void-elements-with-children";
99

1010
export const RULE_FEATURES = [
1111
"CHK",
1212
] as const satisfies RuleFeature[];
1313

1414
export type MessageID = CamelCase<typeof RULE_NAME>;
1515

16-
const voidElements = [
16+
const voidElements = new Set([
1717
"area",
1818
"base",
1919
"br",
@@ -30,18 +30,18 @@ const voidElements = [
3030
"source",
3131
"track",
3232
"wbr",
33-
];
33+
]);
3434

3535
// TODO: Use the information in `settings["react-x"].additionalComponents` to add support for user-defined components that use the void element internally
3636
export default createRule<[], MessageID>({
3737
meta: {
3838
type: "problem",
3939
docs: {
40-
description: "disallow passing 'children' to void DOM elements",
40+
description: "disallow void elements (AKA self-closing elements) from having children",
4141
[Symbol.for("rule_features")]: RULE_FEATURES,
4242
},
4343
messages: {
44-
noChildrenInVoidDomElements: "A void DOM element '<{{element}} />' cannot have children.",
44+
noVoidElementsWithChildren: "'{{element}}' is a void element tag and must not have children.",
4545
},
4646
schema: [],
4747
},
@@ -50,10 +50,10 @@ export default createRule<[], MessageID>({
5050
return {
5151
JSXElement(node) {
5252
const elementName = JSX.getElementName(node.openingElement);
53-
if (!elementName || !voidElements.includes(elementName)) return;
53+
if (!elementName || !voidElements.has(elementName)) return;
5454
if (node.children.length > 0) {
5555
context.report({
56-
messageId: "noChildrenInVoidDomElements",
56+
messageId: "noVoidElementsWithChildren",
5757
node,
5858
data: {
5959
element: elementName,
@@ -67,7 +67,7 @@ export default createRule<[], MessageID>({
6767
if (hasChildrenOrDangerAttr) {
6868
// e.g. <br children="Foo" />
6969
context.report({
70-
messageId: "noChildrenInVoidDomElements",
70+
messageId: "noVoidElementsWithChildren",
7171
node,
7272
data: {
7373
element: elementName,

packages/plugins/eslint-plugin-react-hooks-extra/src/index.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable perfectionist/sort-objects */
21
import { name, version } from "../package.json";
32
import noDirectSetStateInUseEffect from "./rules/no-direct-set-state-in-use-effect";
43
import noDirectSetStateInUseLayoutEffect from "./rules/no-direct-set-state-in-use-layout-effect";
@@ -15,19 +14,19 @@ export default {
1514
rules: {
1615
"no-direct-set-state-in-use-effect": noDirectSetStateInUseEffect,
1716
"no-direct-set-state-in-use-layout-effect": noDirectSetStateInUseLayoutEffect,
18-
"no-useless-custom-hooks": noUselessCustomHooks,
1917
"no-unnecessary-use-callback": noUnnecessaryUseCallback,
2018
"no-unnecessary-use-memo": noUnnecessaryUseMemo,
19+
"no-useless-custom-hooks": noUselessCustomHooks,
2120
"prefer-use-state-lazy-initialization": preferUseStateLazyInitialization,
2221

23-
// Deprecated rules
24-
/** @deprecated Use `no-useless-custom-hooks` instead */
25-
"no-redundant-custom-hook": noUselessCustomHooks,
22+
// Part: deprecated rules
2623
/** @deprecated Use `no-useless-custom-hooks` instead */
2724
"ensure-custom-hooks-using-other-hooks": noUselessCustomHooks,
28-
/** @deprecated Use `no-unnecessary-use-memo` instead */
29-
"ensure-use-memo-has-non-empty-deps": noUnnecessaryUseMemo,
3025
/** @deprecated Use `no-unnecessary-use-callback` instead */
3126
"ensure-use-callback-has-non-empty-deps": noUnnecessaryUseCallback,
27+
/** @deprecated Use `no-unnecessary-use-memo` instead */
28+
"ensure-use-memo-has-non-empty-deps": noUnnecessaryUseMemo,
29+
/** @deprecated Use `no-useless-custom-hooks` instead */
30+
"no-redundant-custom-hook": noUselessCustomHooks,
3231
},
3332
} as const;

packages/plugins/eslint-plugin-react-x/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable perfectionist/sort-objects */
21
import { name, version } from "../package.json";
32
import avoidShorthandBoolean from "./rules/avoid-shorthand-boolean";
43
import avoidShorthandFragment from "./rules/avoid-shorthand-fragment";
@@ -108,7 +107,7 @@ export default {
108107
"prefer-shorthand-boolean": preferShorthandBoolean,
109108
"prefer-shorthand-fragment": preferShorthandFragment,
110109

111-
// Deprecated rules
110+
// Part: deprecated rules
112111
/** @deprecated Use `no-complex-conditional-rendering` instead. */
113112
"no-complicated-conditional-rendering": noComplexConditionalRendering,
114113
},

packages/plugins/eslint-plugin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
130130
- [eslint-plugin-functional](https://github.com/eslint-functional/eslint-plugin-functional)
131131
- [eslint-plugin-perfectionist](https://github.com/azat-io/eslint-plugin-perfectionist)
132132
- [eslint-plugin-filenames-simple](https://github.com/epaew/eslint-plugin-filenames-simple)
133-
- [rome/tools](https://github.com/rome/tools)
133+
- [biomejs.dev/linter/rules-sources/#eslint-plugin-react](https://biomejs.dev/linter/rules-sources/#eslint-plugin-react)

0 commit comments

Comments
 (0)