Skip to content

Commit 2292eb1

Browse files
committed
fix: update JSX debug rule description and error messages
1 parent 71503ea commit 2292eb1

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

apps/website/content/docs/rules/overview.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Linter rules can have false positives, false negatives, and some rules are depen
139139
| [`function-component`](./debug-function-component) | 0️⃣ | `🐞` | Reports all function components |
140140
| [`hook`](./debug-hook) | 0️⃣ | `🐞` | Reports all react hooks |
141141
| [`is-from-react`](./debug-is-from-react) | 0️⃣ | `🐞` | Reports all identifiers that are initialized from React |
142-
| [`jsx`](./debug-jsx) | 0️⃣ | `🐞` | Reports all JSX elements |
142+
| [`jsx`](./debug-jsx) | 0️⃣ | `🐞` | Reports all JSX elements and fragments |
143143

144144
## References
145145

packages/plugins/eslint-plugin-react-debug/src/rules/jsx.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ react-debug/jsx
2020

2121
## Description
2222

23-
Reports all JSX elements with config properties `jsx`, `jsxFactory`, `jsxFragmentFactory`, `jsxImportSource`, and `jsxRuntime`.
23+
Reports all JSX elements and fragments.
2424

2525
- `jsx`
2626
- `jsxFactory`
@@ -47,7 +47,7 @@ import React from "react";
4747

4848
const element = <div>Hello World</div>;
4949
// ^^^^^^^^^^^^^^^^^^^^^^
50-
// - [jsx] jsx: 'react-jsx', jsxFactory: 'React.createElement', jsxFragmentFactory: 'React.Fragment', jsxRuntime: 'automatic', jsxImportSource: 'react'
50+
// - [jsx element] jsx: 'react-jsx', jsxFactory: 'React.createElement', jsxFragmentFactory: 'React.Fragment', jsxRuntime: 'automatic', jsxImportSource: 'react'
5151
```
5252

5353
```tsx
@@ -60,7 +60,7 @@ import Preact from "preact";
6060

6161
const element = <div>Hello World</div>;
6262
// ^^^^^^^^^^^^^^^^^^^^^^
63-
// - [jsx] jsx: 'react', jsxFactory: 'Preact.h', jsxFragmentFactory: 'Preact.Fragment', jsxRuntime: 'classic', jsxImportSource: 'preact'
63+
// - [jsx element] jsx: 'react', jsxFactory: 'Preact.h', jsxFragmentFactory: 'Preact.Fragment', jsxRuntime: 'classic', jsxImportSource: 'preact'
6464
```
6565

6666
## Implementation

packages/plugins/eslint-plugin-react-debug/src/rules/jsx.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ruleTester.run(RULE_NAME, rule, {
2828
{
2929
messageId: "jsx",
3030
data: {
31+
type: "element",
3132
jsx: "react-jsx",
3233
jsxFactory: "React.createElement",
3334
jsxFragmentFactory: "React.Fragment",
@@ -50,6 +51,7 @@ ruleTester.run(RULE_NAME, rule, {
5051
{
5152
messageId: "jsx",
5253
data: {
54+
type: "element",
5355
jsx: "react",
5456
jsxFactory: "Preact.h",
5557
jsxFragmentFactory: "Preact.Fragment",
@@ -69,6 +71,7 @@ ruleTester.run(RULE_NAME, rule, {
6971
{
7072
messageId: "jsx",
7173
data: {
74+
type: "element",
7275
jsx: "react",
7376
jsxFactory: "React.createElement",
7477
jsxFragmentFactory: "React.Fragment",

packages/plugins/eslint-plugin-react-debug/src/rules/jsx.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { RuleListener } from "@typescript-eslint/utils/ts-eslint";
22
import type { CamelCase } from "string-ts";
3+
import * as JSX from "@eslint-react/jsx";
34
import { JsxConfig, type RuleContext, type RuleFeature } from "@eslint-react/kit";
45
import { match, P } from "ts-pattern";
5-
66
import { JsxEmit } from "typescript";
77
import { createRule } from "../utils";
88

@@ -18,12 +18,12 @@ export default createRule<[], MessageID>({
1818
meta: {
1919
type: "problem",
2020
docs: {
21-
description: "Reports all React Hooks.",
21+
description: "Reports all JSX elements and fragments.",
2222
[Symbol.for("rule_features")]: RULE_FEATURES,
2323
},
2424
messages: {
2525
jsx:
26-
"[jsx] jsx: '{{jsx}}', jsxFactory: '{{jsxFactory}}', jsxFragmentFactory: '{{jsxFragmentFactory}}', jsxRuntime: '{{jsxRuntime}}' jsxImportSource: '{{jsxImportSource}}'",
26+
"[jsx {{type}}] jsx: '{{jsx}}', jsxFactory: '{{jsxFactory}}', jsxFragmentFactory: '{{jsxFragmentFactory}}', jsxRuntime: '{{jsxRuntime}}' jsxImportSource: '{{jsxImportSource}}'",
2727
},
2828
schema: [],
2929
},
@@ -40,9 +40,10 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
4040
...jsxConfigFromAnnotation,
4141
};
4242

43-
const baseDescriptor = {
43+
const getDescriptor = (type: string) => ({
4444
messageId: "jsx",
4545
data: {
46+
type,
4647
jsx: match(jsxConfig.jsx)
4748
.with(JsxEmit.None, () => "none")
4849
.with(JsxEmit.ReactJSX, () => "react-jsx")
@@ -58,17 +59,19 @@ export function create(context: RuleContext<MessageID, []>): RuleListener {
5859
.with(P.union(JsxEmit.None, JsxEmit.ReactJSX, JsxEmit.ReactJSXDev), () => "automatic")
5960
.otherwise(() => "classic"),
6061
},
61-
} as const;
62+
} as const);
63+
6264
return {
6365
JSXElement(node) {
66+
const isFragment = JSX.isFragmentElement(node);
6467
context.report({
65-
...baseDescriptor,
68+
...getDescriptor(isFragment ? "fragment" : "element"),
6669
node,
6770
});
6871
},
6972
JSXFragment(node) {
7073
context.report({
71-
...baseDescriptor,
74+
...getDescriptor("fragment"),
7275
node,
7376
});
7477
},

0 commit comments

Comments
 (0)