Skip to content

Commit a77696f

Browse files
committed
refactor: reorganize JSX utilities and improve naming consistency
1 parent 5ca88f5 commit a77696f

File tree

21 files changed

+104
-115
lines changed

21 files changed

+104
-115
lines changed

.pkgs/configs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@eslint/js": "^9.24.0",
2323
"@stylistic/eslint-plugin": "^4.2.0",
2424
"eslint-plugin-de-morgan": "^1.2.1",
25-
"eslint-plugin-function": "^0.0.12",
25+
"eslint-plugin-function": "^0.0.13",
2626
"eslint-plugin-jsdoc": "^50.6.9",
2727
"eslint-plugin-perfectionist": "^4.11.0",
2828
"eslint-plugin-regexp": "^2.7.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"tsup": "^8.4.0",
8888
"tsx": "^4.19.3",
8989
"type-fest": "^4.39.1",
90-
"typedoc": "^0.28.1",
90+
"typedoc": "^0.28.2",
9191
"typedoc-plugin-markdown": "^4.6.1",
9292
"typedoc-plugin-mdn-links": "^5.0.1",
9393
"typescript": "^5.8.3",

packages/plugins/eslint-plugin-react-x/src/rules/no-useless-fragment.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ruleTester.run(RULE_NAME, rule, {
3535
{
3636
type: T.JSXFragment,
3737
messageId: "uselessFragment",
38-
data: { reason: "placed inside a built-in component" },
38+
data: { reason: "placed inside a host component" },
3939
},
4040
{
4141
type: T.JSXFragment,
@@ -68,7 +68,7 @@ ruleTester.run(RULE_NAME, rule, {
6868
{
6969
type: T.JSXFragment,
7070
messageId: "uselessFragment",
71-
data: { reason: "placed inside a built-in component" },
71+
data: { reason: "placed inside a host component" },
7272
},
7373
],
7474
output: "<p>{meow}</p>",
@@ -160,7 +160,7 @@ ruleTester.run(RULE_NAME, rule, {
160160
{
161161
type: T.JSXFragment,
162162
messageId: "uselessFragment",
163-
data: { reason: "placed inside a built-in component" },
163+
data: { reason: "placed inside a host component" },
164164
},
165165
{
166166
type: T.JSXFragment,
@@ -176,7 +176,7 @@ ruleTester.run(RULE_NAME, rule, {
176176
{
177177
type: T.JSXFragment,
178178
messageId: "uselessFragment",
179-
data: { reason: "placed inside a built-in component" },
179+
data: { reason: "placed inside a host component" },
180180
},
181181
],
182182
output: '<div>{"a"}{"b"}</div>',
@@ -192,7 +192,7 @@ ruleTester.run(RULE_NAME, rule, {
192192
{
193193
type: T.JSXFragment,
194194
messageId: "uselessFragment",
195-
data: { reason: "placed inside a built-in component" },
195+
data: { reason: "placed inside a host component" },
196196
},
197197
],
198198
output: `
@@ -208,7 +208,7 @@ ruleTester.run(RULE_NAME, rule, {
208208
{
209209
type: T.JSXElement,
210210
messageId: "uselessFragment",
211-
data: { reason: "placed inside a built-in component" },
211+
data: { reason: "placed inside a host component" },
212212
},
213213
],
214214
output: '<div>{"a"}{"b"}</div>',
@@ -227,13 +227,13 @@ ruleTester.run(RULE_NAME, rule, {
227227
{
228228
type: T.JSXFragment,
229229
messageId: "uselessFragment",
230-
data: { reason: "placed inside a built-in component" },
230+
data: { reason: "placed inside a host component" },
231231
line: 3,
232232
},
233233
{
234234
type: T.JSXFragment,
235235
messageId: "uselessFragment",
236-
data: { reason: "placed inside a built-in component" },
236+
data: { reason: "placed inside a host component" },
237237
line: 7,
238238
},
239239
],
@@ -250,7 +250,7 @@ ruleTester.run(RULE_NAME, rule, {
250250
{
251251
type: T.JSXFragment,
252252
messageId: "uselessFragment",
253-
data: { reason: "placed inside a built-in component" },
253+
data: { reason: "placed inside a host component" },
254254
},
255255
],
256256
output: '<div>a {""}{""} a</div>',
@@ -267,7 +267,7 @@ ruleTester.run(RULE_NAME, rule, {
267267
{
268268
type: T.JSXElement,
269269
messageId: "uselessFragment",
270-
data: { reason: "placed inside a built-in component" },
270+
data: { reason: "placed inside a host component" },
271271
line: 4,
272272
},
273273
{

packages/plugins/eslint-plugin-react-x/src/rules/no-useless-fragment.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function create(context: RuleContext<MessageID, Options>, [option]: Optio
5757
const { allowExpressions = true } = option;
5858
return {
5959
JSXElement(node) {
60-
if (!JSX.isJsxFragmentElement(node)) return;
60+
if (!JSX.isFragmentElement(node)) return;
6161
checkNode(context, node, allowExpressions);
6262
},
6363
JSXFragment(node) {
@@ -103,16 +103,16 @@ function checkNode(
103103
) {
104104
const initialScope = context.sourceCode.getScope(node);
105105
// return if the fragment is keyed (e.g. <Fragment key={key}>)
106-
if (JSX.isJsxKeyedElement(node, initialScope)) {
106+
if (JSX.isKeyedElement(node, initialScope)) {
107107
return;
108108
}
109-
// report if the fragment is placed inside a built-in component (e.g. <div><></></div>)
110-
if (JSX.isJsxBuiltInElement(node.parent)) {
109+
// report if the fragment is placed inside a host component (e.g. <div><></></div>)
110+
if (JSX.isHostElement(node.parent)) {
111111
context.report({
112112
messageId: "uselessFragment",
113113
node,
114114
data: {
115-
reason: "placed inside a built-in component",
115+
reason: "placed inside a host component",
116116
},
117117
fix: getFix(context, node),
118118
});
@@ -204,7 +204,7 @@ function getFix(context: RuleContext, node: TSESTree.JSXElement | TSESTree.JSXFr
204204
function canFix(node: TSESTree.JSXElement | TSESTree.JSXFragment) {
205205
if (node.parent.type === T.JSXElement || node.parent.type === T.JSXFragment) {
206206
// Not safe to fix `<Eeee><>foo</></Eeee>` because `Eeee` might require its children be a ReactElement.
207-
return !JSX.isJsxUserDefinedElement(node.parent);
207+
return JSX.isHostElement(node.parent);
208208
}
209209
// Not safe to fix fragments without a jsx parent.
210210
// const a = <></>

packages/plugins/eslint-plugin-react-x/src/rules/prefer-shorthand-fragment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default createRule<[], MessageID>({
3535
export function create(context: RuleContext<MessageID, []>): RuleListener {
3636
return {
3737
JSXElement(node: TSESTree.JSXElement) {
38-
if (!JSX.isJsxFragmentElement(node)) return;
38+
if (!JSX.isFragmentElement(node)) return;
3939
const hasAttributes = node.openingElement.attributes.length > 0;
4040
if (hasAttributes) {
4141
return;

packages/shared/src/schemas.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const CustomComponentPropSchema = object({
1010
*/
1111
name: string(),
1212
/**
13-
* The name of the prop in the built-in component.
13+
* The name of the prop in the host component.
1414
* @example
1515
* "href"
1616
*/
@@ -44,13 +44,13 @@ export const CustomComponentSchema = object({
4444
*/
4545
name: string(),
4646
/**
47-
* The name of the built-in component that the user-defined component represents.
47+
* The name of the host component that the user-defined component represents.
4848
* @example
4949
* "a"
5050
*/
5151
as: optional(string()),
5252
/**
53-
* Attributes mapping between the user-defined component and the built-in component.
53+
* Attributes mapping between the user-defined component and the host component.
5454
* @example
5555
* `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
5656
*/

packages/utilities/jsx/src/get-attribute-name.ts renamed to packages/utilities/jsx/src/attribute/attribute-name.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { TSESTree } from "@typescript-eslint/utils";
22

3-
import { toString } from "./to-string";
3+
import { toString } from "../to-string";
44

55
/**
66
* Get the stringified name of a JSX attribute

packages/utilities/jsx/src/get-attribute.ts renamed to packages/utilities/jsx/src/attribute/attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { TSESTree } from "@typescript-eslint/utils";
44
import * as VAR from "@eslint-react/var";
55
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
66

7-
import { getAttributeName } from "./get-attribute-name";
7+
import { getAttributeName } from "./attribute-name";
88

99
/**
1010
* Get the JSX attribute node with the given name

0 commit comments

Comments
 (0)