Skip to content

Commit c01d92a

Browse files
committed
refactor: clean up redundant code
1 parent 4849949 commit c01d92a

2 files changed

Lines changed: 29 additions & 47 deletions

File tree

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

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import type { TSESTreeJSXElementLike } from "@eslint-react/ast";
44
import * as core from "@eslint-react/core";
55
import { type RuleContext, type RuleFeature, type RuleListener } from "@eslint-react/eslint";
66
import { getElementFullType, isFragmentElement } from "@eslint-react/jsx";
7-
import { flow } from "@local/eff";
87
import { AST_NODE_TYPES as AST } from "@typescript-eslint/types";
98
import { P, match } from "ts-pattern";
109
import ts from "typescript";
11-
import { report } from "./lib";
1210

1311
export const RULE_NAME = "jsx";
1412

@@ -36,37 +34,35 @@ export default createRule<[], MessageID>({
3634

3735
export function create(context: RuleContext<MessageID, []>): RuleListener {
3836
const jsxConfig = core.getJsxConfig(context);
39-
40-
function visit(node: TSESTreeJSXElementLike) {
41-
return {
42-
data: {
43-
json: stringify({
44-
kind: match(node)
45-
.with({ type: AST.JSXElement }, (n) => isFragmentElement(n, jsxConfig.jsxFragmentFactory) ? "fragment" : "element")
46-
.with({ type: AST.JSXFragment }, () => "fragment")
47-
.exhaustive(),
48-
type: getElementFullType(node),
49-
jsx: match(jsxConfig.jsx)
50-
.with(ts.JsxEmit.None, () => "none")
51-
.with(ts.JsxEmit.ReactJSX, () => "react-jsx")
52-
.with(ts.JsxEmit.ReactJSXDev, () => "react-jsx-dev")
53-
.with(ts.JsxEmit.React, () => "react")
54-
.with(ts.JsxEmit.ReactNative, () => "react-native")
55-
.with(ts.JsxEmit.Preserve, () => "preserve")
56-
.otherwise(() => "unknown"),
57-
jsxFactory: jsxConfig.jsxFactory,
58-
jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
59-
jsxImportSource: jsxConfig.jsxImportSource,
60-
jsxRuntime: match(jsxConfig.jsx)
61-
.with(P.union(ts.JsxEmit.None, ts.JsxEmit.ReactJSX, ts.JsxEmit.ReactJSXDev), () => "automatic")
62-
.otherwise(() => "classic"),
63-
}),
64-
},
65-
messageId: "default",
66-
node,
67-
} as const;
68-
}
6937
return {
70-
"JSXElement, JSXFragment": flow(visit, report(context)),
38+
"JSXElement, JSXFragment": (node: TSESTreeJSXElementLike) => {
39+
context.report({
40+
data: {
41+
json: stringify({
42+
kind: match(node)
43+
.with({ type: AST.JSXElement }, (n) => isFragmentElement(n, jsxConfig.jsxFragmentFactory) ? "fragment" : "element")
44+
.with({ type: AST.JSXFragment }, () => "fragment")
45+
.exhaustive(),
46+
type: getElementFullType(node),
47+
jsx: match(jsxConfig.jsx)
48+
.with(ts.JsxEmit.None, () => "none")
49+
.with(ts.JsxEmit.ReactJSX, () => "react-jsx")
50+
.with(ts.JsxEmit.ReactJSXDev, () => "react-jsx-dev")
51+
.with(ts.JsxEmit.React, () => "react")
52+
.with(ts.JsxEmit.ReactNative, () => "react-native")
53+
.with(ts.JsxEmit.Preserve, () => "preserve")
54+
.otherwise(() => "unknown"),
55+
jsxFactory: jsxConfig.jsxFactory,
56+
jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
57+
jsxImportSource: jsxConfig.jsxImportSource,
58+
jsxRuntime: match(jsxConfig.jsx)
59+
.with(P.union(ts.JsxEmit.None, ts.JsxEmit.ReactJSX, ts.JsxEmit.ReactJSXDev), () => "automatic")
60+
.otherwise(() => "classic"),
61+
}),
62+
},
63+
messageId: "default",
64+
node,
65+
});
66+
},
7167
};
7268
}

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

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)