@eslint-react/core 2.0.0-beta.19 → 2.0.0-beta.191

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +459 -282
  2. package/dist/index.js +1111 -893
  3. package/package.json +13 -12
package/dist/index.js CHANGED
@@ -1,965 +1,1183 @@
1
- import { AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import * as AST14 from '@eslint-react/ast';
3
- import { flip, dual, constFalse, identity, constTrue, unit } from '@eslint-react/eff';
4
- import { RegExp, Selector } from '@eslint-react/kit';
5
- import { coerceSettings, DEFAULT_ESLINT_REACT_SETTINGS, getId } from '@eslint-react/shared';
6
- import * as VAR3 from '@eslint-react/var';
7
- import { isMatching, P, match } from 'ts-pattern';
8
- import birecord from 'birecord';
9
-
10
- // src/component/component-children.ts
1
+ import { AST_NODE_TYPES } from "@typescript-eslint/types";
2
+ import * as AST from "@eslint-react/ast";
3
+ import { constFalse, constTrue, dual, flip, getOrElseUpdate, identity, unit } from "@eslint-react/eff";
4
+ import { RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE } from "@eslint-react/kit";
5
+ import { getId } from "@eslint-react/shared";
6
+ import * as VAR from "@eslint-react/var";
7
+ import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
8
+ import { P, isMatching, match } from "ts-pattern";
9
+ import birecord from "birecord";
10
+
11
+ //#region src/utils/is-react-api.ts
11
12
  function isReactAPI(api) {
12
- const func = (context, node) => {
13
- if (node == null) return false;
14
- const getText = (n) => context.sourceCode.getText(n);
15
- const name = AST14.toStringFormat(node, getText);
16
- if (name === api) return true;
17
- if (name.substring(name.indexOf(".") + 1) === api) return true;
18
- return false;
19
- };
20
- return dual(2, func);
13
+ const func = (context, node) => {
14
+ if (node == null) return false;
15
+ const getText = (n) => context.sourceCode.getText(n);
16
+ const name = AST.toStringFormat(node, getText);
17
+ if (name === api) return true;
18
+ if (name.substring(name.indexOf(".") + 1) === api) return true;
19
+ return false;
20
+ };
21
+ return dual(2, func);
21
22
  }
22
23
  function isReactAPICall(api) {
23
- const func = (context, node) => {
24
- if (node == null) return false;
25
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
26
- return isReactAPI(api)(context, node.callee);
27
- };
28
- return dual(2, func);
29
- }
30
- var isCaptureOwnerStack = isReactAPI("captureOwnerStack");
31
- var isChildrenCount = isReactAPI("Children.count");
32
- var isChildrenForEach = isReactAPI("Children.forEach");
33
- var isChildrenMap = isReactAPI("Children.map");
34
- var isChildrenOnly = isReactAPI("Children.only");
35
- var isChildrenToArray = isReactAPI("Children.toArray");
36
- var isCloneElement = isReactAPI("cloneElement");
37
- var isCreateContext = isReactAPI("createContext");
38
- var isCreateElement = isReactAPI("createElement");
39
- var isCreateRef = isReactAPI("createRef");
40
- var isForwardRef = isReactAPI("forwardRef");
41
- var isMemo = isReactAPI("memo");
42
- var isLazy = isReactAPI("lazy");
43
- var isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
44
- var isChildrenCountCall = isReactAPICall("Children.count");
45
- var isChildrenForEachCall = isReactAPICall("Children.forEach");
46
- var isChildrenMapCall = isReactAPICall("Children.map");
47
- var isChildrenOnlyCall = isReactAPICall("Children.only");
48
- var isChildrenToArrayCall = isReactAPICall("Children.toArray");
49
- var isCloneElementCall = isReactAPICall("cloneElement");
50
- var isCreateContextCall = isReactAPICall("createContext");
51
- var isCreateElementCall = isReactAPICall("createElement");
52
- var isCreateRefCall = isReactAPICall("createRef");
53
- var isForwardRefCall = isReactAPICall("forwardRef");
54
- var isMemoCall = isReactAPICall("memo");
55
- var isLazyCall = isReactAPICall("lazy");
56
-
57
- // src/component/component-children.ts
24
+ const func = (context, node) => {
25
+ if (node == null) return false;
26
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
27
+ return isReactAPI(api)(context, node.callee);
28
+ };
29
+ return dual(2, func);
30
+ }
31
+ const isCaptureOwnerStack = isReactAPI("captureOwnerStack");
32
+ const isChildrenCount = isReactAPI("Children.count");
33
+ const isChildrenForEach = isReactAPI("Children.forEach");
34
+ const isChildrenMap = isReactAPI("Children.map");
35
+ const isChildrenOnly = isReactAPI("Children.only");
36
+ const isChildrenToArray = isReactAPI("Children.toArray");
37
+ const isCloneElement = isReactAPI("cloneElement");
38
+ const isCreateContext = isReactAPI("createContext");
39
+ const isCreateElement = isReactAPI("createElement");
40
+ const isCreateRef = isReactAPI("createRef");
41
+ const isForwardRef = isReactAPI("forwardRef");
42
+ const isMemo = isReactAPI("memo");
43
+ const isLazy = isReactAPI("lazy");
44
+ const isCaptureOwnerStackCall = isReactAPICall("captureOwnerStack");
45
+ const isChildrenCountCall = isReactAPICall("Children.count");
46
+ const isChildrenForEachCall = isReactAPICall("Children.forEach");
47
+ const isChildrenMapCall = isReactAPICall("Children.map");
48
+ const isChildrenOnlyCall = isReactAPICall("Children.only");
49
+ const isChildrenToArrayCall = isReactAPICall("Children.toArray");
50
+ const isCloneElementCall = isReactAPICall("cloneElement");
51
+ const isCreateContextCall = isReactAPICall("createContext");
52
+ const isCreateElementCall = isReactAPICall("createElement");
53
+ const isCreateRefCall = isReactAPICall("createRef");
54
+ const isForwardRefCall = isReactAPICall("forwardRef");
55
+ const isMemoCall = isReactAPICall("memo");
56
+ const isLazyCall = isReactAPICall("lazy");
57
+
58
+ //#endregion
59
+ //#region src/component/component-children.ts
60
+ /**
61
+ * Determines whether inside `createElement`'s children.
62
+ * @param context The rule context
63
+ * @param node The AST node to check
64
+ * @returns `true` if the node is inside createElement's children
65
+ */
58
66
  function isChildrenOfCreateElement(context, node) {
59
- const parent = node.parent;
60
- if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
61
- if (!isCreateElementCall(context, parent)) return false;
62
- return parent.arguments.slice(2).some((arg) => arg === node);
67
+ const parent = node.parent;
68
+ if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
69
+ if (!isCreateElementCall(context, parent)) return false;
70
+ return parent.arguments.slice(2).some((arg) => arg === node);
63
71
  }
64
- function getInstanceId(node, prev) {
65
- switch (true) {
66
- case (node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev):
67
- return node.id;
68
- case (node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev):
69
- return node.left;
70
- case (node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev):
71
- return node.key;
72
- case (node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node):
73
- return unit;
74
- default:
75
- return getInstanceId(node.parent, node);
76
- }
77
- }
78
- function getRequireExpressionArguments(node) {
79
- return match(node).with({ type: AST_NODE_TYPES.CallExpression, arguments: P.select(), callee: { type: AST_NODE_TYPES.Identifier, name: "require" } }, identity).with({ type: AST_NODE_TYPES.MemberExpression, object: P.select() }, getRequireExpressionArguments).otherwise(() => null);
80
- }
81
- function isInitializedFromReact(name, importSource, initialScope) {
82
- if (name.toLowerCase() === "react") return true;
83
- const latestDef = VAR3.findVariable(name, initialScope)?.defs.at(-1);
84
- if (latestDef == null) return false;
85
- const { node, parent } = latestDef;
86
- if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
87
- const { init } = node;
88
- if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) {
89
- return isInitializedFromReact(init.object.name, importSource, initialScope);
90
- }
91
- if (init.type === AST_NODE_TYPES.Identifier) {
92
- return isInitializedFromReact(init.name, importSource, initialScope);
93
- }
94
- const args = getRequireExpressionArguments(init);
95
- const arg0 = args?.[0];
96
- if (arg0 == null || !AST14.isLiteral(arg0, "string")) {
97
- return false;
98
- }
99
- return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
100
- }
101
- return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
102
- }
103
- function isInstanceIdEqual(context, a, b) {
104
- return AST14.isNodeEqual(a, b) || VAR3.isNodeValueEqual(a, b, [
105
- context.sourceCode.getScope(a),
106
- context.sourceCode.getScope(b)
107
- ]);
108
- }
109
-
110
- // src/hook/hook-name.ts
111
- var REACT_BUILTIN_HOOK_NAMES = [
112
- "use",
113
- "useActionState",
114
- "useCallback",
115
- "useContext",
116
- "useDebugValue",
117
- "useDeferredValue",
118
- "useEffect",
119
- "useFormStatus",
120
- "useId",
121
- "useImperativeHandle",
122
- "useInsertionEffect",
123
- "useLayoutEffect",
124
- "useMemo",
125
- "useOptimistic",
126
- "useReducer",
127
- "useRef",
128
- "useState",
129
- "useSyncExternalStore",
130
- "useTransition"
72
+
73
+ //#endregion
74
+ //#region src/hook/hook-name.ts
75
+ const REACT_BUILTIN_HOOK_NAMES = [
76
+ "use",
77
+ "useActionState",
78
+ "useCallback",
79
+ "useContext",
80
+ "useDebugValue",
81
+ "useDeferredValue",
82
+ "useEffect",
83
+ "useFormStatus",
84
+ "useId",
85
+ "useImperativeHandle",
86
+ "useInsertionEffect",
87
+ "useLayoutEffect",
88
+ "useMemo",
89
+ "useOptimistic",
90
+ "useReducer",
91
+ "useRef",
92
+ "useState",
93
+ "useSyncExternalStore",
94
+ "useTransition"
131
95
  ];
96
+ /**
97
+ * Catch all identifiers that begin with "use" followed by an uppercase Latin
98
+ * character to exclude identifiers like "user".
99
+ * @param name The name of the identifier to check.
100
+ * @see https://github.com/facebook/react/blob/1d6c8168db1d82713202e842df3167787ffa00ed/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts#L16
101
+ */
132
102
  function isReactHookName(name) {
133
- return name === "use" || /^use[A-Z0-9]/.test(name);
103
+ return name === "use" || /^use[A-Z0-9]/.test(name);
134
104
  }
135
105
 
136
- // src/hook/hook-is.ts
106
+ //#endregion
107
+ //#region src/hook/hook-is.ts
108
+ /**
109
+ * Determines if a function node is a React Hook based on its name.
110
+ * @param node The function node to check
111
+ * @returns True if the function is a React Hook, false otherwise
112
+ */
137
113
  function isReactHook(node) {
138
- if (node == null) return false;
139
- const id = AST14.getFunctionId(node);
140
- return id?.name != null && isReactHookName(id.name);
141
- }
114
+ if (node == null) return false;
115
+ const id = AST.getFunctionId(node);
116
+ return id?.name != null && isReactHookName(id.name);
117
+ }
118
+ /**
119
+ * Check if the given node is a React Hook call by its name.
120
+ * @param node The node to check.
121
+ * @returns `true` if the node is a React Hook call, `false` otherwise.
122
+ */
142
123
  function isReactHookCall(node) {
143
- if (node == null) return false;
144
- if (node.type !== AST_NODE_TYPES.CallExpression) {
145
- return false;
146
- }
147
- if (node.callee.type === AST_NODE_TYPES.Identifier) {
148
- return isReactHookName(node.callee.name);
149
- }
150
- if (node.callee.type === AST_NODE_TYPES.MemberExpression) {
151
- return node.callee.property.type === AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
152
- }
153
- return false;
154
- }
155
- function isReactHookCallWithName(context, node) {
156
- if (node == null || node.type !== AST_NODE_TYPES.CallExpression) return constFalse;
157
- const {
158
- importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
159
- skipImportCheck = true
160
- } = coerceSettings(context.settings);
161
- const initialScope = context.sourceCode.getScope(node);
162
- return (name) => {
163
- switch (true) {
164
- case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === name):
165
- return skipImportCheck || isInitializedFromReact(name, importSource, initialScope);
166
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
167
- return skipImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
168
- default:
169
- return false;
170
- }
171
- };
172
- }
173
- function isReactHookCallWithNameLoose(node) {
174
- if (node == null || node.type !== AST_NODE_TYPES.CallExpression) return constFalse;
175
- return (name) => {
176
- switch (node.callee.type) {
177
- case AST_NODE_TYPES.Identifier:
178
- return node.callee.name === name;
179
- case AST_NODE_TYPES.MemberExpression:
180
- return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name;
181
- default:
182
- return false;
183
- }
184
- };
185
- }
186
- function isReactHookCallWithNameAlias(context, name, alias = []) {
187
- const {
188
- importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
189
- skipImportCheck = true
190
- } = coerceSettings(context.settings);
191
- return (node) => {
192
- const initialScope = context.sourceCode.getScope(node);
193
- switch (true) {
194
- case (node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === name):
195
- return skipImportCheck || isInitializedFromReact(name, importSource, initialScope);
196
- case (node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object):
197
- return skipImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
198
- default:
199
- return alias.some(isReactHookCallWithNameLoose(node));
200
- }
201
- };
202
- }
203
- function isUseEffectCallLoose(node) {
204
- if (node == null) return false;
205
- if (node.type !== AST_NODE_TYPES.CallExpression) {
206
- return false;
207
- }
208
- switch (node.callee.type) {
209
- case AST_NODE_TYPES.Identifier:
210
- return /^use\w*Effect$/u.test(node.callee.name);
211
- case AST_NODE_TYPES.MemberExpression:
212
- return node.callee.property.type === AST_NODE_TYPES.Identifier && /^use\w*Effect$/u.test(node.callee.property.name);
213
- default:
214
- return false;
215
- }
216
- }
217
- var isUseCall = flip(isReactHookCallWithName)("use");
218
- var isUseActionStateCall = flip(isReactHookCallWithName)("useActionState");
219
- var isUseCallbackCall = flip(isReactHookCallWithName)("useCallback");
220
- var isUseContextCall = flip(isReactHookCallWithName)("useContext");
221
- var isUseDebugValueCall = flip(isReactHookCallWithName)("useDebugValue");
222
- var isUseDeferredValueCall = flip(isReactHookCallWithName)("useDeferredValue");
223
- var isUseEffectCall = flip(isReactHookCallWithName)("useEffect");
224
- var isUseFormStatusCall = flip(isReactHookCallWithName)("useFormStatus");
225
- var isUseIdCall = flip(isReactHookCallWithName)("useId");
226
- var isUseImperativeHandleCall = flip(isReactHookCallWithName)("useImperativeHandle");
227
- var isUseInsertionEffectCall = flip(isReactHookCallWithName)("useInsertionEffect");
228
- var isUseLayoutEffectCall = flip(isReactHookCallWithName)("useLayoutEffect");
229
- var isUseMemoCall = flip(isReactHookCallWithName)("useMemo");
230
- var isUseOptimisticCall = flip(isReactHookCallWithName)("useOptimistic");
231
- var isUseReducerCall = flip(isReactHookCallWithName)("useReducer");
232
- var isUseRefCall = flip(isReactHookCallWithName)("useRef");
233
- var isUseStateCall = flip(isReactHookCallWithName)("useState");
234
- var isUseSyncExternalStoreCall = flip(isReactHookCallWithName)("useSyncExternalStore");
235
- var isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
236
-
237
- // src/hook/hook-collector.ts
124
+ if (node == null) return false;
125
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
126
+ if (node.callee.type === AST_NODE_TYPES.Identifier) return isReactHookName(node.callee.name);
127
+ if (node.callee.type === AST_NODE_TYPES.MemberExpression) return node.callee.property.type === AST_NODE_TYPES.Identifier && isReactHookName(node.callee.property.name);
128
+ return false;
129
+ }
130
+ /**
131
+ * Checks if a node is a call to a specific React hook.
132
+ * Returns a function that accepts a hook name to check against.
133
+ * @param node The AST node to check
134
+ * @returns A function that takes a hook name and returns boolean
135
+ */
136
+ function isReactHookCallWithName(node) {
137
+ if (node == null || node.type !== AST_NODE_TYPES.CallExpression) return constFalse;
138
+ return (name) => {
139
+ switch (node.callee.type) {
140
+ case AST_NODE_TYPES.Identifier: return node.callee.name === name;
141
+ case AST_NODE_TYPES.MemberExpression: return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name;
142
+ default: return false;
143
+ }
144
+ };
145
+ }
146
+ /**
147
+ * Checks if a node is a call to a specific React hook or one of its aliases.
148
+ * @param name The primary hook name to check
149
+ * @param alias Optional array of alias names to also accept
150
+ * @returns Function that checks if a node matches the hook name or aliases
151
+ */
152
+ function isReactHookCallWithNameAlias(name, alias = []) {
153
+ return (node) => {
154
+ switch (true) {
155
+ case node.callee.type === AST_NODE_TYPES.Identifier && node.callee.name === name: return true;
156
+ case node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === name && "name" in node.callee.object: return true;
157
+ default: return alias.some(isReactHookCallWithName(node));
158
+ }
159
+ };
160
+ }
161
+ /**
162
+ * Detects useEffect calls and variations (useLayoutEffect, etc.) using regex pattern.
163
+ * @param node The AST node to check
164
+ * @returns True if the node is a useEffect-like call
165
+ */
166
+ function isUseEffectLikeCall(node) {
167
+ if (node == null) return false;
168
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
169
+ switch (node.callee.type) {
170
+ case AST_NODE_TYPES.Identifier: return /^use\w*Effect$/u.test(node.callee.name);
171
+ case AST_NODE_TYPES.MemberExpression: return node.callee.property.type === AST_NODE_TYPES.Identifier && /^use\w*Effect$/u.test(node.callee.property.name);
172
+ default: return false;
173
+ }
174
+ }
175
+ const isUseCall = flip(isReactHookCallWithName)("use");
176
+ const isUseActionStateCall = flip(isReactHookCallWithName)("useActionState");
177
+ const isUseCallbackCall = flip(isReactHookCallWithName)("useCallback");
178
+ const isUseContextCall = flip(isReactHookCallWithName)("useContext");
179
+ const isUseDebugValueCall = flip(isReactHookCallWithName)("useDebugValue");
180
+ const isUseDeferredValueCall = flip(isReactHookCallWithName)("useDeferredValue");
181
+ const isUseEffectCall = flip(isReactHookCallWithName)("useEffect");
182
+ const isUseFormStatusCall = flip(isReactHookCallWithName)("useFormStatus");
183
+ const isUseIdCall = flip(isReactHookCallWithName)("useId");
184
+ const isUseImperativeHandleCall = flip(isReactHookCallWithName)("useImperativeHandle");
185
+ const isUseInsertionEffectCall = flip(isReactHookCallWithName)("useInsertionEffect");
186
+ const isUseLayoutEffectCall = flip(isReactHookCallWithName)("useLayoutEffect");
187
+ const isUseMemoCall = flip(isReactHookCallWithName)("useMemo");
188
+ const isUseOptimisticCall = flip(isReactHookCallWithName)("useOptimistic");
189
+ const isUseReducerCall = flip(isReactHookCallWithName)("useReducer");
190
+ const isUseRefCall = flip(isReactHookCallWithName)("useRef");
191
+ const isUseStateCall = flip(isReactHookCallWithName)("useState");
192
+ const isUseSyncExternalStoreCall = flip(isReactHookCallWithName)("useSyncExternalStore");
193
+ const isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
194
+
195
+ //#endregion
196
+ //#region src/hook/hook-collector.ts
238
197
  function useHookCollector() {
239
- const hooks = /* @__PURE__ */ new Map();
240
- const functionEntries = [];
241
- const onFunctionEnter = (node) => {
242
- const id = AST14.getFunctionId(node);
243
- const key = getId();
244
- const name = id?.name;
245
- if (name != null && isReactHookName(name)) {
246
- functionEntries.push({ key, node, isHook: true });
247
- hooks.set(key, {
248
- id,
249
- key,
250
- kind: "function",
251
- name,
252
- node,
253
- flag: 0n,
254
- hint: 0n,
255
- hookCalls: []
256
- });
257
- return;
258
- }
259
- functionEntries.push({ key, node, isHook: false });
260
- };
261
- const onFunctionExit = () => {
262
- functionEntries.pop();
263
- };
264
- const ctx = {
265
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
266
- getAllHooks(node) {
267
- return hooks;
268
- }
269
- };
270
- const listeners = {
271
- ":function[type]": onFunctionEnter,
272
- ":function[type]:exit": onFunctionExit,
273
- "CallExpression[type]"(node) {
274
- if (!isReactHookCall(node)) {
275
- return;
276
- }
277
- const fEntry = functionEntries.at(-1);
278
- if (fEntry?.key == null) {
279
- return;
280
- }
281
- const hook = hooks.get(fEntry.key);
282
- if (hook == null) {
283
- return;
284
- }
285
- hook.hookCalls.push(node);
286
- }
287
- };
288
- return { ctx, listeners };
198
+ const hooks = /* @__PURE__ */ new Map();
199
+ const functionEntries = [];
200
+ const onFunctionEnter = (node) => {
201
+ const id = AST.getFunctionId(node);
202
+ const key = getId();
203
+ const name = id?.name;
204
+ if (name != null && isReactHookName(name)) {
205
+ functionEntries.push({
206
+ key,
207
+ node,
208
+ isHook: true
209
+ });
210
+ hooks.set(key, {
211
+ id,
212
+ key,
213
+ kind: "function",
214
+ name,
215
+ node,
216
+ flag: 0n,
217
+ hint: 0n,
218
+ hookCalls: []
219
+ });
220
+ return;
221
+ }
222
+ functionEntries.push({
223
+ key,
224
+ node,
225
+ isHook: false
226
+ });
227
+ };
228
+ const onFunctionExit = () => {
229
+ functionEntries.pop();
230
+ };
231
+ return {
232
+ ctx: { getAllHooks(node) {
233
+ return hooks;
234
+ } },
235
+ listeners: {
236
+ ":function[type]": onFunctionEnter,
237
+ ":function[type]:exit": onFunctionExit,
238
+ "CallExpression[type]"(node) {
239
+ if (!isReactHookCall(node)) return;
240
+ const fEntry = functionEntries.at(-1);
241
+ if (fEntry?.key == null) return;
242
+ const hook = hooks.get(fEntry.key);
243
+ if (hook == null) return;
244
+ hook.hookCalls.push(node);
245
+ }
246
+ }
247
+ };
289
248
  }
249
+
250
+ //#endregion
251
+ //#region src/hook/hook-id.ts
290
252
  function isReactHookId(id) {
291
- switch (id.type) {
292
- case AST_NODE_TYPES.Identifier:
293
- return isReactHookName(id.name);
294
- case AST_NODE_TYPES.MemberExpression:
295
- return "name" in id.property && isReactHookName(id.property.name);
296
- default:
297
- return false;
298
- }
253
+ switch (id.type) {
254
+ case AST_NODE_TYPES.Identifier: return isReactHookName(id.name);
255
+ case AST_NODE_TYPES.MemberExpression: return "name" in id.property && isReactHookName(id.property.name);
256
+ default: return false;
257
+ }
299
258
  }
259
+
260
+ //#endregion
261
+ //#region src/jsx/jsx-stringify.ts
262
+ /**
263
+ * Incomplete but sufficient stringification of JSX nodes for common use cases
264
+ *
265
+ * @param node - JSX node from TypeScript ESTree
266
+ * @returns String representation of the JSX node
267
+ */
300
268
  function stringifyJsx(node) {
301
- switch (node.type) {
302
- case AST_NODE_TYPES.JSXIdentifier:
303
- return node.name;
304
- case AST_NODE_TYPES.JSXNamespacedName:
305
- return `${node.namespace.name}:${node.name.name}`;
306
- case AST_NODE_TYPES.JSXMemberExpression:
307
- return `${stringifyJsx(node.object)}.${stringifyJsx(node.property)}`;
308
- case AST_NODE_TYPES.JSXText:
309
- return node.value;
310
- case AST_NODE_TYPES.JSXOpeningElement:
311
- return `<${stringifyJsx(node.name)}>`;
312
- case AST_NODE_TYPES.JSXClosingElement:
313
- return `</${stringifyJsx(node.name)}>`;
314
- case AST_NODE_TYPES.JSXOpeningFragment:
315
- return "<>";
316
- case AST_NODE_TYPES.JSXClosingFragment:
317
- return "</>";
318
- }
319
- }
320
-
321
- // src/jsx/jsx-attribute-name.ts
269
+ switch (node.type) {
270
+ case AST_NODE_TYPES.JSXIdentifier: return node.name;
271
+ case AST_NODE_TYPES.JSXNamespacedName: return `${node.namespace.name}:${node.name.name}`;
272
+ case AST_NODE_TYPES.JSXMemberExpression: return `${stringifyJsx(node.object)}.${stringifyJsx(node.property)}`;
273
+ case AST_NODE_TYPES.JSXText: return node.value;
274
+ case AST_NODE_TYPES.JSXOpeningElement: return `<${stringifyJsx(node.name)}>`;
275
+ case AST_NODE_TYPES.JSXClosingElement: return `</${stringifyJsx(node.name)}>`;
276
+ case AST_NODE_TYPES.JSXOpeningFragment: return "<>";
277
+ case AST_NODE_TYPES.JSXClosingFragment: return "</>";
278
+ }
279
+ }
280
+
281
+ //#endregion
282
+ //#region src/jsx/jsx-attribute-name.ts
283
+ /**
284
+ * Get the stringified name of a JSX attribute
285
+ * @param context The ESLint rule context
286
+ * @param node The JSX attribute node
287
+ * @returns The name of the attribute
288
+ */
322
289
  function getAttributeName(context, node) {
323
- return stringifyJsx(node.name);
324
- }
325
-
326
- // src/jsx/jsx-attribute.ts
327
- function getAttribute(context, name, attributes, initialScope) {
328
- return attributes.findLast((attr) => {
329
- if (attr.type === AST_NODE_TYPES.JSXAttribute) {
330
- return getAttributeName(context, attr) === name;
331
- }
332
- if (initialScope == null) return false;
333
- switch (attr.argument.type) {
334
- case AST_NODE_TYPES.Identifier: {
335
- const variable = VAR3.findVariable(attr.argument.name, initialScope);
336
- const variableNode = VAR3.getVariableInitNode(variable, 0);
337
- if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) {
338
- return VAR3.findPropertyInProperties(name, variableNode.properties, initialScope) != null;
339
- }
340
- return false;
341
- }
342
- case AST_NODE_TYPES.ObjectExpression:
343
- return VAR3.findPropertyInProperties(name, attr.argument.properties, initialScope) != null;
344
- }
345
- return false;
346
- });
347
- }
348
- function getAttributeValue(context, node, name) {
349
- const initialScope = context.sourceCode.getScope(node);
350
- switch (node.type) {
351
- case AST_NODE_TYPES.JSXAttribute:
352
- if (node.value?.type === AST_NODE_TYPES.Literal) {
353
- return {
354
- kind: "some",
355
- node: node.value,
356
- initialScope,
357
- value: node.value.value
358
- };
359
- }
360
- if (node.value?.type === AST_NODE_TYPES.JSXExpressionContainer) {
361
- return VAR3.toStaticValue({
362
- kind: "lazy",
363
- node: node.value.expression,
364
- initialScope
365
- });
366
- }
367
- return { kind: "none", node, initialScope };
368
- case AST_NODE_TYPES.JSXSpreadAttribute: {
369
- const staticValue = VAR3.toStaticValue({
370
- kind: "lazy",
371
- node: node.argument,
372
- initialScope
373
- });
374
- if (staticValue.kind === "none") {
375
- return staticValue;
376
- }
377
- return match(staticValue.value).with({ [name]: P.select(P.any) }, (value) => ({
378
- kind: "some",
379
- node: node.argument,
380
- initialScope,
381
- value
382
- })).otherwise(() => ({ kind: "none", node, initialScope }));
383
- }
384
- default:
385
- return { kind: "none", node, initialScope };
386
- }
387
- }
388
-
389
- // src/jsx/jsx-detection-hint.ts
390
- var JSXDetectionHint = {
391
- None: 0n,
392
- SkipUndefined: 1n << 0n,
393
- SkipNullLiteral: 1n << 1n,
394
- SkipBooleanLiteral: 1n << 2n,
395
- SkipStringLiteral: 1n << 3n,
396
- SkipNumberLiteral: 1n << 4n,
397
- SkipBigIntLiteral: 1n << 5n,
398
- SkipEmptyArray: 1n << 6n,
399
- SkipCreateElement: 1n << 7n,
400
- StrictArray: 1n << 8n,
401
- StrictLogical: 1n << 9n,
402
- StrictConditional: 1n << 10n
290
+ return stringifyJsx(node.name);
291
+ }
292
+
293
+ //#endregion
294
+ //#region src/jsx/jsx-attribute.ts
295
+ function getAttribute(context, attributes, initialScope) {
296
+ return (name) => {
297
+ return attributes.findLast((attr) => {
298
+ if (attr.type === AST_NODE_TYPES.JSXAttribute) return getAttributeName(context, attr) === name;
299
+ if (initialScope == null) return false;
300
+ switch (attr.argument.type) {
301
+ case AST_NODE_TYPES.Identifier: {
302
+ const variable = VAR.findVariable(attr.argument.name, initialScope);
303
+ const variableNode = VAR.getVariableDefinitionNode(variable, 0);
304
+ if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) return VAR.findProperty(name, variableNode.properties, initialScope) != null;
305
+ return false;
306
+ }
307
+ case AST_NODE_TYPES.ObjectExpression: return VAR.findProperty(name, attr.argument.properties, initialScope) != null;
308
+ }
309
+ return false;
310
+ });
311
+ };
312
+ }
313
+
314
+ //#endregion
315
+ //#region src/jsx/jsx-attribute-value.ts
316
+ function resolveAttributeValue(context, attribute) {
317
+ const initialScope = context.sourceCode.getScope(attribute);
318
+ function handleJsxAttribute(node) {
319
+ if (node.value == null) return {
320
+ kind: "boolean",
321
+ toStatic() {
322
+ return true;
323
+ }
324
+ };
325
+ switch (node.value.type) {
326
+ case AST_NODE_TYPES.Literal: {
327
+ const staticValue = node.value.value;
328
+ return {
329
+ kind: "literal",
330
+ node: node.value,
331
+ toStatic() {
332
+ return staticValue;
333
+ }
334
+ };
335
+ }
336
+ case AST_NODE_TYPES.JSXExpressionContainer: {
337
+ const expr = node.value.expression;
338
+ return {
339
+ kind: "expression",
340
+ node: expr,
341
+ toStatic() {
342
+ return getStaticValue(expr, initialScope)?.value;
343
+ }
344
+ };
345
+ }
346
+ case AST_NODE_TYPES.JSXElement: return {
347
+ kind: "element",
348
+ node: node.value,
349
+ toStatic() {
350
+ return unit;
351
+ }
352
+ };
353
+ case AST_NODE_TYPES.JSXSpreadChild: return {
354
+ kind: "spreadChild",
355
+ node: node.value.expression,
356
+ toStatic() {
357
+ return unit;
358
+ }
359
+ };
360
+ }
361
+ }
362
+ function handleJsxSpreadAttribute(node) {
363
+ return {
364
+ kind: "spreadProps",
365
+ node: node.argument,
366
+ toStatic(name) {
367
+ if (name == null) return unit;
368
+ return match(getStaticValue(node.argument, initialScope)?.value).with({ [name]: P.select(P.any) }, identity).otherwise(() => unit);
369
+ }
370
+ };
371
+ }
372
+ switch (attribute.type) {
373
+ case AST_NODE_TYPES.JSXAttribute: return handleJsxAttribute(attribute);
374
+ case AST_NODE_TYPES.JSXSpreadAttribute: return handleJsxSpreadAttribute(attribute);
375
+ }
376
+ }
377
+
378
+ //#endregion
379
+ //#region src/jsx/jsx-config.ts
380
+ const JsxEmit = {
381
+ None: 0,
382
+ Preserve: 1,
383
+ React: 2,
384
+ ReactNative: 3,
385
+ ReactJSX: 4,
386
+ ReactJSXDev: 5
403
387
  };
404
- var DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
388
+ /**
389
+ * Get JsxConfig from the rule context by reading compiler options.
390
+ * @param context The RuleContext.
391
+ * @returns JsxConfig derived from compiler options.
392
+ */
393
+ function getJsxConfigFromContext(context) {
394
+ const options = context.sourceCode.parserServices?.program?.getCompilerOptions() ?? {};
395
+ return {
396
+ jsx: options.jsx ?? JsxEmit.ReactJSX,
397
+ jsxFactory: options.jsxFactory ?? "React.createElement",
398
+ jsxFragmentFactory: options.jsxFragmentFactory ?? "React.Fragment",
399
+ jsxImportSource: options.jsxImportSource ?? "react"
400
+ };
401
+ }
402
+ const cache = /* @__PURE__ */ new WeakMap();
403
+ /**
404
+ * Get JsxConfig from pragma comments (annotations) in the source code.
405
+ * @param context The RuleContext.
406
+ * @returns JsxConfig derived from pragma comments.
407
+ */
408
+ function getJsxConfigFromAnnotation(context) {
409
+ return getOrElseUpdate(cache, context.sourceCode, () => {
410
+ const options = {};
411
+ if (!context.sourceCode.text.includes("@jsx")) return options;
412
+ let jsx, jsxFrag, jsxRuntime, jsxImportSource;
413
+ for (const comment of context.sourceCode.getAllComments().reverse()) {
414
+ const value = comment.value;
415
+ jsx ??= value.match(RE_ANNOTATION_JSX)?.[1];
416
+ jsxFrag ??= value.match(RE_ANNOTATION_JSX_FRAG)?.[1];
417
+ jsxRuntime ??= value.match(RE_ANNOTATION_JSX_RUNTIME)?.[1];
418
+ jsxImportSource ??= value.match(RE_ANNOTATION_JSX_IMPORT_SOURCE)?.[1];
419
+ }
420
+ if (jsx != null) options.jsxFactory = jsx;
421
+ if (jsxFrag != null) options.jsxFragmentFactory = jsxFrag;
422
+ if (jsxRuntime != null) options.jsx = jsxRuntime === "classic" ? JsxEmit.React : JsxEmit.ReactJSX;
423
+ if (jsxImportSource != null) options.jsxImportSource = jsxImportSource;
424
+ return options;
425
+ });
426
+ }
405
427
 
406
- // src/jsx/jsx-detection.ts
428
+ //#endregion
429
+ //#region src/jsx/jsx-detection.ts
430
+ /**
431
+ * Flags to control JSX detection behavior:
432
+ * - Skip* flags: Ignore specific node types when detecting JSX
433
+ * - Strict* flags: Enforce stricter rules for container types
434
+ */
435
+ const JSXDetectionHint = {
436
+ None: 0n,
437
+ SkipUndefined: 1n << 0n,
438
+ SkipNullLiteral: 1n << 1n,
439
+ SkipBooleanLiteral: 1n << 2n,
440
+ SkipStringLiteral: 1n << 3n,
441
+ SkipNumberLiteral: 1n << 4n,
442
+ SkipBigIntLiteral: 1n << 5n,
443
+ SkipEmptyArray: 1n << 6n,
444
+ SkipCreateElement: 1n << 7n,
445
+ StrictArray: 1n << 8n,
446
+ StrictLogical: 1n << 9n,
447
+ StrictConditional: 1n << 10n
448
+ };
449
+ /**
450
+ * Default JSX detection configuration
451
+ * Skips undefined and boolean literals (common in React)
452
+ */
453
+ const DEFAULT_JSX_DETECTION_HINT = 0n | JSXDetectionHint.SkipUndefined | JSXDetectionHint.SkipBooleanLiteral;
454
+ /**
455
+ * Checks if a node is a `JSXText` or a `Literal` node
456
+ * @param node The AST node to check
457
+ * @returns `true` if the node is a `JSXText` or a `Literal` node
458
+ */
407
459
  function isJsxText(node) {
408
- if (node == null) return false;
409
- return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
410
- }
460
+ if (node == null) return false;
461
+ return node.type === AST_NODE_TYPES.JSXText || node.type === AST_NODE_TYPES.Literal;
462
+ }
463
+ /**
464
+ * Determines if a node represents JSX-like content based on heuristics
465
+ * Supports configuration through hint flags to customize detection behavior
466
+ *
467
+ * @param code The source code with scope lookup capability
468
+ * @param code.getScope The function to get the scope of a node
469
+ * @param node The AST node to analyze
470
+ * @param hint The configuration flags to adjust detection behavior
471
+ * @returns boolean Whether the node is considered JSX-like
472
+ */
411
473
  function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
412
- if (node == null) return false;
413
- if (AST14.isJSX(node)) return true;
414
- switch (node.type) {
415
- case AST_NODE_TYPES.Literal: {
416
- switch (typeof node.value) {
417
- case "boolean":
418
- return !(hint & JSXDetectionHint.SkipBooleanLiteral);
419
- case "string":
420
- return !(hint & JSXDetectionHint.SkipStringLiteral);
421
- case "number":
422
- return !(hint & JSXDetectionHint.SkipNumberLiteral);
423
- case "bigint":
424
- return !(hint & JSXDetectionHint.SkipBigIntLiteral);
425
- }
426
- if (node.value == null) {
427
- return !(hint & JSXDetectionHint.SkipNullLiteral);
428
- }
429
- return false;
430
- }
431
- case AST_NODE_TYPES.TemplateLiteral: {
432
- return !(hint & JSXDetectionHint.SkipStringLiteral);
433
- }
434
- case AST_NODE_TYPES.ArrayExpression: {
435
- if (node.elements.length === 0) {
436
- return !(hint & JSXDetectionHint.SkipEmptyArray);
437
- }
438
- if (hint & JSXDetectionHint.StrictArray) {
439
- return node.elements.every((n) => isJsxLike(code, n, hint));
440
- }
441
- return node.elements.some((n) => isJsxLike(code, n, hint));
442
- }
443
- case AST_NODE_TYPES.LogicalExpression: {
444
- if (hint & JSXDetectionHint.StrictLogical) {
445
- return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
446
- }
447
- return isJsxLike(code, node.left, hint) || isJsxLike(code, node.right, hint);
448
- }
449
- case AST_NODE_TYPES.ConditionalExpression: {
450
- let leftHasJSX2 = function(node2) {
451
- if (Array.isArray(node2.consequent)) {
452
- if (node2.consequent.length === 0) {
453
- return !(hint & JSXDetectionHint.SkipEmptyArray);
454
- }
455
- if (hint & JSXDetectionHint.StrictArray) {
456
- return node2.consequent.every((n) => isJsxLike(code, n, hint));
457
- }
458
- return node2.consequent.some((n) => isJsxLike(code, n, hint));
459
- }
460
- return isJsxLike(code, node2.consequent, hint);
461
- }, rightHasJSX2 = function(node2) {
462
- return isJsxLike(code, node2.alternate, hint);
463
- };
464
- if (hint & JSXDetectionHint.StrictConditional) {
465
- return leftHasJSX2(node) && rightHasJSX2(node);
466
- }
467
- return leftHasJSX2(node) || rightHasJSX2(node);
468
- }
469
- case AST_NODE_TYPES.SequenceExpression: {
470
- const exp = node.expressions.at(-1);
471
- return isJsxLike(code, exp, hint);
472
- }
473
- case AST_NODE_TYPES.CallExpression: {
474
- if (hint & JSXDetectionHint.SkipCreateElement) {
475
- return false;
476
- }
477
- switch (node.callee.type) {
478
- case AST_NODE_TYPES.Identifier:
479
- return node.callee.name === "createElement";
480
- case AST_NODE_TYPES.MemberExpression:
481
- return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
482
- }
483
- return false;
484
- }
485
- case AST_NODE_TYPES.Identifier: {
486
- const { name } = node;
487
- if (name === "undefined") {
488
- return !(hint & JSXDetectionHint.SkipUndefined);
489
- }
490
- if (AST14.isJSXTagNameExpression(node)) {
491
- return true;
492
- }
493
- const variable = VAR3.findVariable(name, code.getScope(node));
494
- const variableNode = variable && VAR3.getVariableInitNode(variable, 0);
495
- return !!variableNode && isJsxLike(code, variableNode, hint);
496
- }
497
- }
498
- return false;
474
+ if (node == null) return false;
475
+ if (AST.isJSX(node)) return true;
476
+ switch (node.type) {
477
+ case AST_NODE_TYPES.Literal:
478
+ switch (typeof node.value) {
479
+ case "boolean": return !(hint & JSXDetectionHint.SkipBooleanLiteral);
480
+ case "string": return !(hint & JSXDetectionHint.SkipStringLiteral);
481
+ case "number": return !(hint & JSXDetectionHint.SkipNumberLiteral);
482
+ case "bigint": return !(hint & JSXDetectionHint.SkipBigIntLiteral);
483
+ }
484
+ if (node.value == null) return !(hint & JSXDetectionHint.SkipNullLiteral);
485
+ return false;
486
+ case AST_NODE_TYPES.TemplateLiteral: return !(hint & JSXDetectionHint.SkipStringLiteral);
487
+ case AST_NODE_TYPES.ArrayExpression:
488
+ if (node.elements.length === 0) return !(hint & JSXDetectionHint.SkipEmptyArray);
489
+ if (hint & JSXDetectionHint.StrictArray) return node.elements.every((n) => isJsxLike(code, n, hint));
490
+ return node.elements.some((n) => isJsxLike(code, n, hint));
491
+ case AST_NODE_TYPES.LogicalExpression:
492
+ if (hint & JSXDetectionHint.StrictLogical) return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
493
+ return isJsxLike(code, node.left, hint) || isJsxLike(code, node.right, hint);
494
+ case AST_NODE_TYPES.ConditionalExpression: {
495
+ function leftHasJSX(node$1) {
496
+ if (Array.isArray(node$1.consequent)) {
497
+ if (node$1.consequent.length === 0) return !(hint & JSXDetectionHint.SkipEmptyArray);
498
+ if (hint & JSXDetectionHint.StrictArray) return node$1.consequent.every((n) => isJsxLike(code, n, hint));
499
+ return node$1.consequent.some((n) => isJsxLike(code, n, hint));
500
+ }
501
+ return isJsxLike(code, node$1.consequent, hint);
502
+ }
503
+ function rightHasJSX(node$1) {
504
+ return isJsxLike(code, node$1.alternate, hint);
505
+ }
506
+ if (hint & JSXDetectionHint.StrictConditional) return leftHasJSX(node) && rightHasJSX(node);
507
+ return leftHasJSX(node) || rightHasJSX(node);
508
+ }
509
+ case AST_NODE_TYPES.SequenceExpression: {
510
+ const exp = node.expressions.at(-1);
511
+ return isJsxLike(code, exp, hint);
512
+ }
513
+ case AST_NODE_TYPES.CallExpression:
514
+ if (hint & JSXDetectionHint.SkipCreateElement) return false;
515
+ switch (node.callee.type) {
516
+ case AST_NODE_TYPES.Identifier: return node.callee.name === "createElement";
517
+ case AST_NODE_TYPES.MemberExpression: return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
518
+ }
519
+ return false;
520
+ case AST_NODE_TYPES.Identifier: {
521
+ const { name } = node;
522
+ if (name === "undefined") return !(hint & JSXDetectionHint.SkipUndefined);
523
+ if (AST.isJSXTagNameExpression(node)) return true;
524
+ const variable = VAR.findVariable(name, code.getScope(node));
525
+ const variableNode = variable && VAR.getVariableDefinitionNode(variable, 0);
526
+ return !!variableNode && isJsxLike(code, variableNode, hint);
527
+ }
528
+ }
529
+ return false;
499
530
  }
531
+
532
+ //#endregion
533
+ //#region src/jsx/jsx-element-type.ts
534
+ /**
535
+ * Extracts the element type name from a JSX element or fragment
536
+ * For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
537
+ * For JSX fragments, returns an empty string
538
+ *
539
+ * @param context - ESLint rule context
540
+ * @param node - JSX element or fragment node
541
+ * @returns String representation of the element type
542
+ */
500
543
  function getElementType(context, node) {
501
- if (node.type === AST_NODE_TYPES.JSXFragment) {
502
- return "";
503
- }
504
- return stringifyJsx(node.openingElement.name);
544
+ if (node.type === AST_NODE_TYPES.JSXFragment) return "";
545
+ return stringifyJsx(node.openingElement.name);
505
546
  }
506
547
 
507
- // src/jsx/jsx-has.ts
508
- function hasAttribute(context, name, attributes, initialScope) {
509
- return getAttribute(context, name, attributes, initialScope) != null;
548
+ //#endregion
549
+ //#region src/jsx/jsx-element-is.ts
550
+ /**
551
+ * Determines if a JSX element is a host element
552
+ * Host elements in React start with lowercase letters (e.g., div, span)
553
+ *
554
+ * @param context - ESLint rule context
555
+ * @param node - AST node to check
556
+ * @returns boolean indicating if the element is a host element
557
+ */
558
+ function isHostElement(context, node) {
559
+ return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
560
+ }
561
+ /**
562
+ * Determines if a JSX element is a React Fragment
563
+ * Fragments can be imported from React and used like <Fragment> or <React.Fragment>
564
+ *
565
+ * @param context - ESLint rule context
566
+ * @param node - AST node to check
567
+ * @returns boolean indicating if the element is a Fragment with type narrowing
568
+ */
569
+ function isFragmentElement(context, node) {
570
+ if (node.type !== AST_NODE_TYPES.JSXElement) return false;
571
+ return getElementType(context, node).split(".").at(-1) === "Fragment";
510
572
  }
573
+
574
+ //#endregion
575
+ //#region src/jsx/jsx-has.ts
576
+ /**
577
+ * Checks if a JSX element has a specific attribute
578
+ *
579
+ * @param context - ESLint rule context
580
+ * @param name - Name of the attribute to check for
581
+ * @param attributes - List of JSX attributes from opening element
582
+ * @param initialScope - Optional scope for resolving variables in spread attributes
583
+ * @returns boolean indicating whether the attribute exists
584
+ */
585
+ function hasAttribute(context, name, attributes, initialScope) {
586
+ return getAttribute(context, attributes, initialScope)(name) != null;
587
+ }
588
+ /**
589
+ * Checks if a JSX element has at least one of the specified attributes
590
+ *
591
+ * @param context - ESLint rule context
592
+ * @param names - Array of attribute names to check for
593
+ * @param attributes - List of JSX attributes from opening element
594
+ * @param initialScope - Optional scope for resolving variables in spread attributes
595
+ * @returns boolean indicating whether any of the attributes exist
596
+ */
511
597
  function hasAnyAttribute(context, names, attributes, initialScope) {
512
- return names.some((n) => hasAttribute(context, n, attributes, initialScope));
513
- }
598
+ return names.some((n) => hasAttribute(context, n, attributes, initialScope));
599
+ }
600
+ /**
601
+ * Checks if a JSX element has all of the specified attributes
602
+ *
603
+ * @param context - ESLint rule context
604
+ * @param names - Array of attribute names to check for
605
+ * @param attributes - List of JSX attributes from opening element
606
+ * @param initialScope - Optional scope for resolving variables in spread attributes
607
+ * @returns boolean indicating whether all of the attributes exist
608
+ */
514
609
  function hasEveryAttribute(context, names, attributes, initialScope) {
515
- return names.every((n) => hasAttribute(context, n, attributes, initialScope));
610
+ return names.every((n) => hasAttribute(context, n, attributes, initialScope));
516
611
  }
612
+
613
+ //#endregion
614
+ //#region src/jsx/jsx-hierarchy.ts
615
+ /**
616
+ * Traverses up the AST to find a parent JSX attribute node that matches a given test
617
+ *
618
+ * @param node - The starting AST node
619
+ * @param test - Optional predicate function to test if the attribute meets criteria
620
+ * Defaults to always returning true (matches any attribute)
621
+ * @returns The first matching JSX attribute node found when traversing upwards, or undefined
622
+ */
517
623
  function findParentAttribute(node, test = constTrue) {
518
- const guard = (node2) => {
519
- return node2.type === AST_NODE_TYPES.JSXAttribute && test(node2);
520
- };
521
- return AST14.findParentNode(node, guard);
624
+ const guard = (node$1) => {
625
+ return node$1.type === AST_NODE_TYPES.JSXAttribute && test(node$1);
626
+ };
627
+ return AST.findParentNode(node, guard);
522
628
  }
523
- function isHostElement(context, node) {
524
- return node.type === AST_NODE_TYPES.JSXElement && node.openingElement.name.type === AST_NODE_TYPES.JSXIdentifier && /^[a-z]/u.test(node.openingElement.name.name);
525
- }
526
- function isKeyedElement(context, node, initialScope) {
527
- return node.type === AST_NODE_TYPES.JSXElement && hasAttribute(context, "key", node.openingElement.attributes, initialScope);
528
- }
529
- function isFragmentElement(context, node, allowJSXFragment = false) {
530
- if (node == null) return false;
531
- if (node.type !== AST_NODE_TYPES.JSXElement && node.type !== AST_NODE_TYPES.JSXFragment) return false;
532
- if (node.type === AST_NODE_TYPES.JSXFragment) return allowJSXFragment;
533
- return getElementType(context, node).split(".").at(-1) === "Fragment";
534
- }
535
-
536
- // src/component/component-detection-hint.ts
537
- var ComponentDetectionHint = {
538
- /**
539
- * 1n << 0n - 1n << 63n are reserved for JSXDetectionHint
540
- */
541
- ...JSXDetectionHint,
542
- /**
543
- * Skip function component created by React.memo
544
- */
545
- SkipMemo: 1n << 64n,
546
- /**
547
- * Skip function component created by React.forwardRef
548
- */
549
- SkipForwardRef: 1n << 65n,
550
- /**
551
- * Skip function component defined as array map argument
552
- */
553
- SkipArrayMapArgument: 1n << 66n,
554
- /**
555
- * Skip function component defined on object method
556
- */
557
- SkipObjectMethod: 1n << 67n,
558
- /**
559
- * Skip function component defined on class method
560
- */
561
- SkipClassMethod: 1n << 68n,
562
- /**
563
- * Skip function component defined on class property
564
- */
565
- SkipClassProperty: 1n << 69n
629
+
630
+ //#endregion
631
+ //#region src/component/component-detection-hint.ts
632
+ /**
633
+ * Hints for component collector
634
+ */
635
+ const ComponentDetectionHint = {
636
+ ...JSXDetectionHint,
637
+ SkipMemo: 1n << 64n,
638
+ SkipForwardRef: 1n << 65n,
639
+ SkipArrayMapArgument: 1n << 66n,
640
+ SkipObjectMethod: 1n << 67n,
641
+ SkipClassMethod: 1n << 68n,
642
+ SkipClassProperty: 1n << 69n
566
643
  };
567
- var DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipEmptyArray | ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.StrictArray | ComponentDetectionHint.StrictConditional | ComponentDetectionHint.StrictLogical;
644
+ /**
645
+ * Default component detection hint
646
+ */
647
+ const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipEmptyArray | ComponentDetectionHint.SkipArrayMapArgument | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.StrictArray | ComponentDetectionHint.StrictConditional | ComponentDetectionHint.StrictLogical;
648
+
649
+ //#endregion
650
+ //#region src/component/component-is.ts
651
+ /**
652
+ * Check if a node is a React class component
653
+ * @param node The AST node to check
654
+ * @returns `true` if the node is a class component, `false` otherwise
655
+ */
568
656
  function isClassComponent(node) {
569
- if ("superClass" in node && node.superClass != null) {
570
- const re = /^(?:Pure)?Component$/u;
571
- switch (true) {
572
- case node.superClass.type === AST_NODE_TYPES.Identifier:
573
- return re.test(node.superClass.name);
574
- case (node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property.type === AST_NODE_TYPES.Identifier):
575
- return re.test(node.superClass.property.name);
576
- }
577
- }
578
- return false;
579
- }
657
+ if ("superClass" in node && node.superClass != null) {
658
+ const re = /^(?:Pure)?Component$/u;
659
+ switch (true) {
660
+ case node.superClass.type === AST_NODE_TYPES.Identifier: return re.test(node.superClass.name);
661
+ case node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property.type === AST_NODE_TYPES.Identifier: return re.test(node.superClass.property.name);
662
+ }
663
+ }
664
+ return false;
665
+ }
666
+ /**
667
+ * Check if a node is a React PureComponent
668
+ * @param node The AST node to check
669
+ * @returns `true` if the node is a pure component, `false` otherwise
670
+ */
580
671
  function isPureComponent(node) {
581
- if ("superClass" in node && node.superClass != null) {
582
- const re = /^PureComponent$/u;
583
- switch (true) {
584
- case node.superClass.type === AST_NODE_TYPES.Identifier:
585
- return re.test(node.superClass.name);
586
- case (node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property.type === AST_NODE_TYPES.Identifier):
587
- return re.test(node.superClass.property.name);
588
- }
589
- }
590
- return false;
672
+ if ("superClass" in node && node.superClass != null) {
673
+ const re = /^PureComponent$/u;
674
+ switch (true) {
675
+ case node.superClass.type === AST_NODE_TYPES.Identifier: return re.test(node.superClass.name);
676
+ case node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property.type === AST_NODE_TYPES.Identifier: return re.test(node.superClass.property.name);
677
+ }
678
+ }
679
+ return false;
591
680
  }
681
+
682
+ //#endregion
683
+ //#region src/component/component-render-method.ts
684
+ /**
685
+ * Check whether given node is a render method of a class component
686
+ * @example
687
+ * ```tsx
688
+ * class Component extends React.Component {
689
+ * renderHeader = () => <div />;
690
+ * renderFooter = () => <div />;
691
+ * }
692
+ * ```
693
+ * @param node The AST node to check
694
+ * @returns `true` if node is a render function, `false` if not
695
+ */
592
696
  function isRenderMethodLike(node) {
593
- return AST14.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
697
+ return AST.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name.startsWith("render") && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
594
698
  }
595
699
 
596
- // src/component/component-definition.ts
597
- var isFunctionOfClassMethod = isMatching({
598
- type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
599
- parent: AST_NODE_TYPES.MethodDefinition
600
- });
601
- var isFunctionOfClassProperty = isMatching({
602
- type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
603
- parent: AST_NODE_TYPES.Property
604
- });
605
- var isFunctionOfObjectMethod = isMatching({
606
- type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
607
- parent: {
608
- type: AST_NODE_TYPES.Property,
609
- parent: {
610
- type: AST_NODE_TYPES.ObjectExpression
611
- }
612
- }
613
- });
700
+ //#endregion
701
+ //#region src/component/component-definition.ts
702
+ /**
703
+ * Function pattern matchers for different contexts
704
+ */
705
+ const functionPatterns = {
706
+ classMethod: {
707
+ type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
708
+ parent: AST_NODE_TYPES.MethodDefinition
709
+ },
710
+ classProperty: {
711
+ type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
712
+ parent: AST_NODE_TYPES.Property
713
+ },
714
+ objectMethod: {
715
+ type: P.union(AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression),
716
+ parent: {
717
+ type: AST_NODE_TYPES.Property,
718
+ parent: { type: AST_NODE_TYPES.ObjectExpression }
719
+ }
720
+ }
721
+ };
722
+ /**
723
+ * Check whether given node is a function of a render method of a class component
724
+ * @example
725
+ * ```tsx
726
+ * class Component extends React.Component {
727
+ * renderHeader = () => <div />;
728
+ * renderFooter = () => <div />;
729
+ * }
730
+ * ```
731
+ * @param node The AST node to check
732
+ * @returns `true` if node is a render function, `false` if not
733
+ */
614
734
  function isFunctionOfRenderMethod(node) {
615
- if (!isRenderMethodLike(node.parent)) {
616
- return false;
617
- }
618
- return isClassComponent(node.parent.parent.parent);
619
- }
620
- function isValidComponentDefinition(context, node, hint) {
621
- if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
622
- return false;
623
- }
624
- if (hint & ComponentDetectionHint.SkipObjectMethod && isFunctionOfObjectMethod(node.parent)) {
625
- return false;
626
- }
627
- if (hint & ComponentDetectionHint.SkipClassMethod && isFunctionOfClassMethod(node.parent)) {
628
- return false;
629
- }
630
- if (hint & ComponentDetectionHint.SkipClassProperty && isFunctionOfClassProperty(node.parent)) {
631
- return false;
632
- }
633
- if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST14.isArrayMapCall(node.parent)) {
634
- return false;
635
- }
636
- const significantParent = AST14.findParentNode(
637
- node,
638
- AST14.isOneOf([
639
- AST_NODE_TYPES.JSXExpressionContainer,
640
- AST_NODE_TYPES.ArrowFunctionExpression,
641
- AST_NODE_TYPES.FunctionExpression,
642
- AST_NODE_TYPES.Property,
643
- AST_NODE_TYPES.ClassBody
644
- ])
645
- );
646
- return significantParent == null || significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
735
+ return isRenderMethodLike(node.parent) && isClassComponent(node.parent.parent.parent);
736
+ }
737
+ /**
738
+ * Checks if a function node should be excluded based on detection hints
739
+ * @param node The function node to check
740
+ * @param hint Component detection hints as bit flags
741
+ * @returns `true` if the function should be excluded, `false` otherwise
742
+ */
743
+ function shouldExcludeBasedOnHint(node, hint) {
744
+ if (hint & ComponentDetectionHint.SkipObjectMethod && isMatching(functionPatterns.objectMethod)(node)) return true;
745
+ if (hint & ComponentDetectionHint.SkipClassMethod && isMatching(functionPatterns.classMethod)(node)) return true;
746
+ if (hint & ComponentDetectionHint.SkipClassProperty && isMatching(functionPatterns.classProperty)(node)) return true;
747
+ if (hint & ComponentDetectionHint.SkipArrayMapArgument && AST.isArrayMapCall(node.parent)) return true;
748
+ return false;
749
+ }
750
+ /**
751
+ * Determines if a function node represents a valid React component definition
752
+ * @param context The rule context
753
+ * @param node The function node to check
754
+ * @param hint Component detection hints as bit flags
755
+ * @returns `true` if the node is a valid component definition, `false` otherwise
756
+ */
757
+ function isComponentDefinition(context, node, hint) {
758
+ if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) return false;
759
+ if (shouldExcludeBasedOnHint(node, hint)) return false;
760
+ const significantParent = AST.findParentNode(node, AST.isOneOf([
761
+ AST_NODE_TYPES.JSXExpressionContainer,
762
+ AST_NODE_TYPES.ArrowFunctionExpression,
763
+ AST_NODE_TYPES.FunctionExpression,
764
+ AST_NODE_TYPES.Property,
765
+ AST_NODE_TYPES.ClassBody
766
+ ]));
767
+ return significantParent == null || significantParent.type !== AST_NODE_TYPES.JSXExpressionContainer;
647
768
  }
648
- function isComponentWrapperCall(context, node) {
649
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
650
- return isMemoCall(context, node) || isForwardRefCall(context, node);
769
+
770
+ //#endregion
771
+ //#region src/utils/get-instance-id.ts
772
+ /**
773
+ * Gets the identifier node of an instance based on AST node relationships.
774
+ * Used for tracking where hooks or components are being assigned in the code.
775
+ * @param node The current AST node to evaluate
776
+ * @param prev The previous AST node in the traversal (used for context)
777
+ * @internal
778
+ */
779
+ function getInstanceId(node, prev) {
780
+ switch (true) {
781
+ case node.type === AST_NODE_TYPES.VariableDeclarator && node.init === prev: return node.id;
782
+ case node.type === AST_NODE_TYPES.AssignmentExpression && node.right === prev: return node.left;
783
+ case node.type === AST_NODE_TYPES.PropertyDefinition && node.value === prev: return node.key;
784
+ case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program || node.parent === node: return unit;
785
+ default: return getInstanceId(node.parent, node);
786
+ }
787
+ }
788
+
789
+ //#endregion
790
+ //#region src/utils/is-from-react.ts
791
+ /**
792
+ * Get the arguments of a require expression
793
+ * @param node The node to match
794
+ * @returns The require expression arguments or undefined if the node is not a require expression
795
+ */
796
+ function getRequireExpressionArguments(node) {
797
+ return match(node).with({
798
+ type: AST_NODE_TYPES.CallExpression,
799
+ arguments: P.select(),
800
+ callee: {
801
+ type: AST_NODE_TYPES.Identifier,
802
+ name: "require"
803
+ }
804
+ }, identity).with({
805
+ type: AST_NODE_TYPES.MemberExpression,
806
+ object: P.select()
807
+ }, getRequireExpressionArguments).otherwise(() => null);
808
+ }
809
+ /**
810
+ * Check if an identifier name is initialized from react
811
+ * @param name The top-level identifier's name
812
+ * @param importSource The import source to check against
813
+ * @param initialScope Initial scope to search for the identifier
814
+ * @returns Whether the identifier name is initialized from react
815
+ * @internal
816
+ */
817
+ function isInitializedFromReact(name, importSource, initialScope) {
818
+ if (name.toLowerCase() === "react") return true;
819
+ const latestDef = VAR.findVariable(name, initialScope)?.defs.at(-1);
820
+ if (latestDef == null) return false;
821
+ const { node, parent } = latestDef;
822
+ if (node.type === AST_NODE_TYPES.VariableDeclarator && node.init != null) {
823
+ const { init } = node;
824
+ if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return isInitializedFromReact(init.object.name, importSource, initialScope);
825
+ if (init.type === AST_NODE_TYPES.Identifier) return isInitializedFromReact(init.name, importSource, initialScope);
826
+ const arg0 = getRequireExpressionArguments(init)?.[0];
827
+ if (arg0 == null || !AST.isLiteral(arg0, "string")) return false;
828
+ return arg0.value === importSource || arg0.value.startsWith(`${importSource}/`);
829
+ }
830
+ return parent?.type === AST_NODE_TYPES.ImportDeclaration && parent.source.value === importSource;
831
+ }
832
+
833
+ //#endregion
834
+ //#region src/utils/is-instance-id-equal.ts
835
+ /** @internal */
836
+ function isInstanceIdEqual(context, a, b) {
837
+ return AST.isNodeEqual(a, b) || VAR.isNodeValueEqual(a, b, [context.sourceCode.getScope(a), context.sourceCode.getScope(b)]);
651
838
  }
839
+
840
+ //#endregion
841
+ //#region src/component/component-wrapper.ts
842
+ /**
843
+ * Check if the node is a call expression for a component wrapper
844
+ * @param context The ESLint rule context
845
+ * @param node The node to check
846
+ * @returns `true` if the node is a call expression for a component wrapper
847
+ */
848
+ function isComponentWrapperCall(context, node) {
849
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
850
+ return isMemoCall(context, node) || isForwardRefCall(context, node);
851
+ }
852
+ /**
853
+ * Check if the node is a call expression for a component wrapper loosely
854
+ * @param context The ESLint rule context
855
+ * @param node The node to check
856
+ * @returns `true` if the node is a call expression for a component wrapper loosely
857
+ */
652
858
  function isComponentWrapperCallLoose(context, node) {
653
- if (node.type !== AST_NODE_TYPES.CallExpression) return false;
654
- return isComponentWrapperCall(context, node) || isUseCallbackCall(context, node);
859
+ if (node.type !== AST_NODE_TYPES.CallExpression) return false;
860
+ return isComponentWrapperCall(context, node) || isUseCallbackCall(node);
655
861
  }
656
862
 
657
- // src/component/component-id.ts
863
+ //#endregion
864
+ //#region src/component/component-id.ts
658
865
  function getFunctionComponentId(context, node) {
659
- const functionId = AST14.getFunctionId(node);
660
- if (functionId != null) {
661
- return functionId;
662
- }
663
- const { parent } = node;
664
- if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === AST_NODE_TYPES.Identifier) {
665
- return parent.parent.id;
666
- }
667
- if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === AST_NODE_TYPES.Identifier) {
668
- return parent.parent.parent.id;
669
- }
670
- return unit;
671
- }
672
-
673
- // src/component/component-flag.ts
674
- var ComponentFlag = {
675
- None: 0n,
676
- PureComponent: 1n << 0n,
677
- CreateElement: 1n << 1n,
678
- Memo: 1n << 2n,
679
- ForwardRef: 1n << 3n,
680
- Async: 1n << 4n
866
+ const functionId = AST.getFunctionId(node);
867
+ if (functionId != null) return functionId;
868
+ const { parent } = node;
869
+ if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === AST_NODE_TYPES.Identifier) return parent.parent.id;
870
+ if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCallLoose(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === AST_NODE_TYPES.Identifier) return parent.parent.parent.id;
871
+ return unit;
872
+ }
873
+
874
+ //#endregion
875
+ //#region src/component/component-flag.ts
876
+ const ComponentFlag = {
877
+ None: 0n,
878
+ PureComponent: 1n << 0n,
879
+ CreateElement: 1n << 1n,
880
+ Memo: 1n << 2n,
881
+ ForwardRef: 1n << 3n,
882
+ Async: 1n << 4n
681
883
  };
682
884
 
683
- // src/component/component-init-path.ts
885
+ //#endregion
886
+ //#region src/component/component-init-path.ts
684
887
  function getComponentFlagFromInitPath(initPath) {
685
- let flag = ComponentFlag.None;
686
- if (initPath != null && AST14.hasCallInFunctionInitPath("memo", initPath)) {
687
- flag |= ComponentFlag.Memo;
688
- }
689
- if (initPath != null && AST14.hasCallInFunctionInitPath("forwardRef", initPath)) {
690
- flag |= ComponentFlag.ForwardRef;
691
- }
692
- return flag;
888
+ let flag = ComponentFlag.None;
889
+ if (initPath != null && AST.hasCallInFunctionInitPath("memo", initPath)) flag |= ComponentFlag.Memo;
890
+ if (initPath != null && AST.hasCallInFunctionInitPath("forwardRef", initPath)) flag |= ComponentFlag.ForwardRef;
891
+ return flag;
693
892
  }
893
+
894
+ //#endregion
895
+ //#region src/component/component-name.ts
694
896
  function isComponentName(name) {
695
- return RegExp.COMPONENT_NAME.test(name);
897
+ return RE_COMPONENT_NAME.test(name);
696
898
  }
697
899
  function isComponentNameLoose(name) {
698
- return RegExp.COMPONENT_NAME_LOOSE.test(name);
900
+ return RE_COMPONENT_NAME_LOOSE.test(name);
699
901
  }
700
902
  function getComponentNameFromId(id) {
701
- if (id == null) return unit;
702
- return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
903
+ if (id == null) return unit;
904
+ return Array.isArray(id) ? id.map((n) => n.name).join(".") : id.name;
703
905
  }
704
906
  function hasNoneOrLooseComponentName(context, fn) {
705
- const id = getFunctionComponentId(context, fn);
706
- if (id == null) return true;
707
- const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
708
- return name != null && isComponentNameLoose(name);
907
+ const id = getFunctionComponentId(context, fn);
908
+ if (id == null) return true;
909
+ const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
910
+ return name != null && isComponentNameLoose(name);
709
911
  }
710
912
 
711
- // src/component/component-collector.ts
913
+ //#endregion
914
+ //#region src/component/component-collector.ts
915
+ /**
916
+ * Get a ctx and listeners for the rule to collect function components
917
+ * @param context The ESLint rule context
918
+ * @param options The options to use
919
+ * @returns The component collector
920
+ */
712
921
  function useComponentCollector(context, options = {}) {
713
- const {
714
- collectDisplayName = false,
715
- collectHookCalls = false,
716
- hint = DEFAULT_COMPONENT_DETECTION_HINT
717
- } = options;
718
- const components = /* @__PURE__ */ new Map();
719
- const functionEntries = [];
720
- const getCurrentEntry = () => functionEntries.at(-1);
721
- const onFunctionEnter = (node) => {
722
- const key = getId();
723
- functionEntries.push({ key, node, hookCalls: [], isComponent: false });
724
- };
725
- const onFunctionExit = () => {
726
- const entry = functionEntries.at(-1);
727
- if (entry == null) return;
728
- if (!entry.isComponent) return functionEntries.pop();
729
- const rets = AST14.getNestedReturnStatements(entry.node.body);
730
- for (let i = rets.length - 1; i >= 0; i--) {
731
- const ret = rets[i];
732
- if (ret == null) continue;
733
- const shouldDrop = context.sourceCode.getScope(ret).block === entry.node && ret.argument != null && !isJsxLike(context.sourceCode, ret.argument, hint);
734
- if (shouldDrop) {
735
- components.delete(entry.key);
736
- break;
737
- }
738
- }
739
- return functionEntries.pop();
740
- };
741
- const ctx = {
742
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
743
- getAllComponents(node) {
744
- return components;
745
- },
746
- getCurrentEntries() {
747
- return [...functionEntries];
748
- },
749
- getCurrentEntry
750
- };
751
- const listeners = {
752
- ":function[type]": onFunctionEnter,
753
- ":function[type]:exit": onFunctionExit,
754
- "ArrowFunctionExpression[body.type!='BlockStatement']"() {
755
- const entry = getCurrentEntry();
756
- if (entry == null) return;
757
- const { body } = entry.node;
758
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isValidComponentDefinition(context, entry.node, hint);
759
- if (!isComponent) return;
760
- const initPath = AST14.getFunctionInitPath(entry.node);
761
- const id = getFunctionComponentId(context, entry.node);
762
- const name = getComponentNameFromId(id);
763
- const key = getId();
764
- components.set(key, {
765
- id,
766
- key,
767
- kind: "function",
768
- name,
769
- node: entry.node,
770
- displayName: unit,
771
- flag: getComponentFlagFromInitPath(initPath),
772
- hint,
773
- hookCalls: entry.hookCalls,
774
- initPath
775
- });
776
- },
777
- ...collectDisplayName ? {
778
- [Selector.DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
779
- const { left, right } = node;
780
- if (left.type !== AST_NODE_TYPES.MemberExpression) return;
781
- const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : unit;
782
- const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
783
- if (component == null) return;
784
- component.displayName = right;
785
- }
786
- } : {},
787
- ...collectHookCalls ? {
788
- "CallExpression[type]:exit"(node) {
789
- if (!isReactHookCall(node)) return;
790
- const entry = getCurrentEntry();
791
- if (entry == null) return;
792
- entry.hookCalls.push(node);
793
- }
794
- } : {},
795
- "ReturnStatement[type]"(node) {
796
- const entry = getCurrentEntry();
797
- if (entry == null) return;
798
- const isComponent = hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isValidComponentDefinition(context, entry.node, hint);
799
- if (!isComponent) return;
800
- entry.isComponent = true;
801
- const initPath = AST14.getFunctionInitPath(entry.node);
802
- const id = getFunctionComponentId(context, entry.node);
803
- const name = getComponentNameFromId(id);
804
- components.set(entry.key, {
805
- id,
806
- key: entry.key,
807
- kind: "function",
808
- name,
809
- node: entry.node,
810
- displayName: unit,
811
- flag: getComponentFlagFromInitPath(initPath),
812
- hint,
813
- hookCalls: entry.hookCalls,
814
- initPath
815
- });
816
- }
817
- };
818
- return { ctx, listeners };
922
+ const { collectDisplayName = false, collectHookCalls = false, hint = DEFAULT_COMPONENT_DETECTION_HINT } = options;
923
+ const components = /* @__PURE__ */ new Map();
924
+ const functionEntries = [];
925
+ const getCurrentEntry = () => functionEntries.at(-1);
926
+ const onFunctionEnter = (node) => {
927
+ const key = getId();
928
+ functionEntries.push({
929
+ key,
930
+ node,
931
+ hookCalls: [],
932
+ isComponent: false
933
+ });
934
+ };
935
+ const onFunctionExit = () => {
936
+ const entry = functionEntries.at(-1);
937
+ if (entry == null) return;
938
+ if (!entry.isComponent) return functionEntries.pop();
939
+ const rets = AST.getNestedReturnStatements(entry.node.body);
940
+ for (let i = rets.length - 1; i >= 0; i--) {
941
+ const ret = rets[i];
942
+ if (ret == null) continue;
943
+ if (context.sourceCode.getScope(ret).block === entry.node && ret.argument != null && !isJsxLike(context.sourceCode, ret.argument, hint)) {
944
+ components.delete(entry.key);
945
+ break;
946
+ }
947
+ }
948
+ return functionEntries.pop();
949
+ };
950
+ const ctx = {
951
+ getAllComponents(node) {
952
+ return components;
953
+ },
954
+ getCurrentEntries() {
955
+ return [...functionEntries];
956
+ },
957
+ getCurrentEntry
958
+ };
959
+ const listeners = {
960
+ ":function[type]": onFunctionEnter,
961
+ ":function[type]:exit": onFunctionExit,
962
+ "ArrowFunctionExpression[body.type!='BlockStatement']"() {
963
+ const entry = getCurrentEntry();
964
+ if (entry == null) return;
965
+ const { body } = entry.node;
966
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, body, hint) && isComponentDefinition(context, entry.node, hint))) return;
967
+ const initPath = AST.getFunctionInitPath(entry.node);
968
+ const id = getFunctionComponentId(context, entry.node);
969
+ const name = getComponentNameFromId(id);
970
+ const key = getId();
971
+ components.set(key, {
972
+ id,
973
+ key,
974
+ kind: "function",
975
+ name,
976
+ node: entry.node,
977
+ displayName: unit,
978
+ flag: getComponentFlagFromInitPath(initPath),
979
+ hint,
980
+ hookCalls: entry.hookCalls,
981
+ initPath
982
+ });
983
+ },
984
+ ...collectDisplayName ? { [AST.SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION](node) {
985
+ const { left, right } = node;
986
+ if (left.type !== AST_NODE_TYPES.MemberExpression) return;
987
+ const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : unit;
988
+ const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
989
+ if (component == null) return;
990
+ component.displayName = right;
991
+ } } : {},
992
+ ...collectHookCalls ? { "CallExpression[type]:exit"(node) {
993
+ if (!isReactHookCall(node)) return;
994
+ const entry = getCurrentEntry();
995
+ if (entry == null) return;
996
+ entry.hookCalls.push(node);
997
+ } } : {},
998
+ "ReturnStatement[type]"(node) {
999
+ const entry = getCurrentEntry();
1000
+ if (entry == null) return;
1001
+ if (!(hasNoneOrLooseComponentName(context, entry.node) && isJsxLike(context.sourceCode, node.argument, hint) && isComponentDefinition(context, entry.node, hint))) return;
1002
+ entry.isComponent = true;
1003
+ const initPath = AST.getFunctionInitPath(entry.node);
1004
+ const id = getFunctionComponentId(context, entry.node);
1005
+ const name = getComponentNameFromId(id);
1006
+ components.set(entry.key, {
1007
+ id,
1008
+ key: entry.key,
1009
+ kind: "function",
1010
+ name,
1011
+ node: entry.node,
1012
+ displayName: unit,
1013
+ flag: getComponentFlagFromInitPath(initPath),
1014
+ hint,
1015
+ hookCalls: entry.hookCalls,
1016
+ initPath
1017
+ });
1018
+ }
1019
+ };
1020
+ return {
1021
+ ctx,
1022
+ listeners
1023
+ };
819
1024
  }
1025
+
1026
+ //#endregion
1027
+ //#region src/component/component-collector-legacy.ts
1028
+ /**
1029
+ * Get a ctx and listeners object for the rule to collect class components
1030
+ * @returns The context and listeners for the rule
1031
+ */
820
1032
  function useComponentCollectorLegacy() {
821
- const components = /* @__PURE__ */ new Map();
822
- const ctx = {
823
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
824
- getAllComponents(node) {
825
- return components;
826
- }
827
- };
828
- const collect = (node) => {
829
- if (!isClassComponent(node)) {
830
- return;
831
- }
832
- const id = AST14.getClassId(node);
833
- const key = getId();
834
- const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
835
- components.set(
836
- key,
837
- {
838
- id,
839
- key,
840
- kind: "class",
841
- name: id?.name,
842
- node,
843
- // TODO: Get displayName of class component
844
- displayName: unit,
845
- flag,
846
- hint: 0n,
847
- // TODO: Get methods of class component
848
- methods: []
849
- }
850
- );
851
- };
852
- const listeners = {
853
- "ClassDeclaration[type]": collect,
854
- "ClassExpression[type]": collect
855
- };
856
- return { ctx, listeners };
857
- }
858
- function isComponentDidCatch(node) {
859
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidCatch";
860
- }
861
- function isComponentDidMount(node) {
862
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidMount";
863
- }
864
- function isComponentDidUpdate(node) {
865
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentDidUpdate";
866
- }
867
- function isComponentWillMount(node) {
868
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillMount";
869
- }
870
- function isComponentWillReceiveProps(node) {
871
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillReceiveProps";
872
- }
873
- function isComponentWillUnmount(node) {
874
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUnmount";
875
- }
876
- function isComponentWillUpdate(node) {
877
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "componentWillUpdate";
878
- }
879
- function isGetChildContext(node) {
880
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getChildContext";
881
- }
882
- function isGetDefaultProps(node) {
883
- return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDefaultProps";
884
- }
885
- function isGetInitialState(node) {
886
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getInitialState";
887
- }
888
- function isGetSnapshotBeforeUpdate(node) {
889
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getSnapshotBeforeUpdate";
890
- }
891
- function isShouldComponentUpdate(node) {
892
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "shouldComponentUpdate";
893
- }
894
- function isUnsafeComponentWillMount(node) {
895
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillMount";
896
- }
897
- function isUnsafeComponentWillReceiveProps(node) {
898
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillReceiveProps";
899
- }
900
- function isUnsafeComponentWillUpdate(node) {
901
- return AST14.isMethodOrProperty(node) && !node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "UNSAFE_componentWillUpdate";
902
- }
903
- function isGetDerivedStateFromProps(node) {
904
- return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromProps";
905
- }
906
- function isGetDerivedStateFromError(node) {
907
- return AST14.isMethodOrProperty(node) && node.static && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "getDerivedStateFromError";
908
- }
909
- var ComponentPhaseRelevance = birecord({
910
- mount: "unmount",
911
- setup: "cleanup"
912
- });
913
- var isInversePhase = dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
914
- function isRenderLike(node) {
915
- return AST14.isMethodOrProperty(node) && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === "render" && node.parent.parent.type === AST_NODE_TYPES.ClassDeclaration;
916
- }
917
- function isFunctionOfRender(node) {
918
- if (!isRenderLike(node.parent)) {
919
- return false;
920
- }
921
- return isClassComponent(node.parent.parent.parent);
1033
+ const components = /* @__PURE__ */ new Map();
1034
+ const ctx = { getAllComponents(node) {
1035
+ return components;
1036
+ } };
1037
+ const collect = (node) => {
1038
+ if (!isClassComponent(node)) return;
1039
+ const id = AST.getClassId(node);
1040
+ const key = getId();
1041
+ const flag = isPureComponent(node) ? ComponentFlag.PureComponent : ComponentFlag.None;
1042
+ components.set(key, {
1043
+ id,
1044
+ key,
1045
+ kind: "class",
1046
+ name: id?.name,
1047
+ node,
1048
+ displayName: unit,
1049
+ flag,
1050
+ hint: 0n,
1051
+ methods: []
1052
+ });
1053
+ };
1054
+ return {
1055
+ ctx,
1056
+ listeners: {
1057
+ "ClassDeclaration[type]": collect,
1058
+ "ClassExpression[type]": collect
1059
+ }
1060
+ };
922
1061
  }
1062
+
1063
+ //#endregion
1064
+ //#region src/component/component-method.ts
1065
+ /**
1066
+ * Create a lifecycle method checker function
1067
+ * @param methodName The lifecycle method name
1068
+ * @param isStatic Whether the method is static
1069
+ */
1070
+ function createLifecycleChecker(methodName, isStatic) {
1071
+ return function(node) {
1072
+ return AST.isMethodOrProperty(node) && node.static === isStatic && node.key.type === AST_NODE_TYPES.Identifier && node.key.name === methodName;
1073
+ };
1074
+ }
1075
+ const isRender = createLifecycleChecker("render", false);
1076
+ const isComponentDidCatch = createLifecycleChecker("componentDidCatch", false);
1077
+ const isComponentDidMount = createLifecycleChecker("componentDidMount", false);
1078
+ const isComponentDidUpdate = createLifecycleChecker("componentDidUpdate", false);
1079
+ const isComponentWillMount = createLifecycleChecker("componentWillMount", false);
1080
+ const isComponentWillReceiveProps = createLifecycleChecker("componentWillReceiveProps", false);
1081
+ const isComponentWillUnmount = createLifecycleChecker("componentWillUnmount", false);
1082
+ const isComponentWillUpdate = createLifecycleChecker("componentWillUpdate", false);
1083
+ const isGetChildContext = createLifecycleChecker("getChildContext", false);
1084
+ const isGetInitialState = createLifecycleChecker("getInitialState", false);
1085
+ const isGetSnapshotBeforeUpdate = createLifecycleChecker("getSnapshotBeforeUpdate", false);
1086
+ const isShouldComponentUpdate = createLifecycleChecker("shouldComponentUpdate", false);
1087
+ const isUnsafeComponentWillMount = createLifecycleChecker("UNSAFE_componentWillMount", false);
1088
+ const isUnsafeComponentWillReceiveProps = createLifecycleChecker("UNSAFE_componentWillReceiveProps", false);
1089
+ const isUnsafeComponentWillUpdate = createLifecycleChecker("UNSAFE_componentWillUpdate", false);
1090
+ const isGetDefaultProps = createLifecycleChecker("getDefaultProps", true);
1091
+ const isGetDerivedStateFromProps = createLifecycleChecker("getDerivedStateFromProps", true);
1092
+ const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromError", true);
1093
+
1094
+ //#endregion
1095
+ //#region src/component/component-phase.ts
1096
+ const ComponentPhaseRelevance = birecord({
1097
+ mount: "unmount",
1098
+ setup: "cleanup"
1099
+ });
1100
+ const isInversePhase = dual(2, (a, b) => ComponentPhaseRelevance.get(a) === b);
1101
+
1102
+ //#endregion
1103
+ //#region src/component/component-render-prop.ts
1104
+ /**
1105
+ * Unsafe check whether given node is a render function
1106
+ * ```tsx
1107
+ * const renderRow = () => <div />
1108
+ * ` ^^^^^^^^^^^^`
1109
+ * _ = <Component renderRow={() => <div />} />
1110
+ * ` ^^^^^^^^^^^^^ `
1111
+ * ```
1112
+ * @param context The rule context
1113
+ * @param node The AST node to check
1114
+ * @returns `true` if node is a render function, `false` if not
1115
+ */
923
1116
  function isRenderFunctionLoose(context, node) {
924
- const { body, parent } = node;
925
- if (AST14.getFunctionId(node)?.name.startsWith("render")) {
926
- return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
927
- }
928
- return isJsxLike(
929
- context.sourceCode,
930
- body,
931
- JSXDetectionHint.SkipNullLiteral | JSXDetectionHint.SkipUndefined | JSXDetectionHint.StrictLogical | JSXDetectionHint.StrictConditional
932
- );
933
- }
1117
+ const { body, parent } = node;
1118
+ if (AST.getFunctionId(node)?.name.startsWith("render")) return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
1119
+ return isJsxLike(context.sourceCode, body, JSXDetectionHint.SkipNullLiteral | JSXDetectionHint.SkipUndefined | JSXDetectionHint.StrictLogical | JSXDetectionHint.StrictConditional);
1120
+ }
1121
+ /**
1122
+ * Unsafe check whether given JSXAttribute is a render prop
1123
+ * ```tsx
1124
+ * _ = <Component renderRow={() => <div />} />
1125
+ * ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
1126
+ * ```
1127
+ * @param context The rule context
1128
+ * @param node The AST node to check
1129
+ * @returns `true` if node is a render prop, `false` if not
1130
+ */
934
1131
  function isRenderPropLoose(context, node) {
935
- if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
936
- return false;
937
- }
938
- return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST14.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
939
- }
1132
+ if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) return false;
1133
+ return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
1134
+ }
1135
+ /**
1136
+ * Unsafe check whether given node is declared directly inside a render property
1137
+ * ```tsx
1138
+ * const rows = { render: () => <div /> }
1139
+ * ` ^^^^^^^^^^^^^ `
1140
+ * _ = <Component rows={ [{ render: () => <div /> }] } />
1141
+ * ` ^^^^^^^^^^^^^ `
1142
+ * ```
1143
+ * @internal
1144
+ * @param node The AST node to check
1145
+ * @returns `true` if component is declared inside a render property, `false` if not
1146
+ */
940
1147
  function isDirectValueOfRenderPropertyLoose(node) {
941
- const matching = (node2) => {
942
- return node2.type === AST_NODE_TYPES.Property && node2.key.type === AST_NODE_TYPES.Identifier && node2.key.name.startsWith("render");
943
- };
944
- return matching(node) || node.parent != null && matching(node.parent);
945
- }
1148
+ const matching = (node$1) => {
1149
+ return node$1.type === AST_NODE_TYPES.Property && node$1.key.type === AST_NODE_TYPES.Identifier && node$1.key.name.startsWith("render");
1150
+ };
1151
+ return matching(node) || node.parent != null && matching(node.parent);
1152
+ }
1153
+ /**
1154
+ * Unsafe check whether given node is declared inside a render prop
1155
+ * ```tsx
1156
+ * _ = <Component renderRow={"node"} />
1157
+ * ` ^^^^^^ `
1158
+ * _ = <Component rows={ [{ render: "node" }] } />
1159
+ * ` ^^^^^^ `
1160
+ * ```
1161
+ * @param node The AST node to check
1162
+ * @returns `true` if component is declared inside a render prop, `false` if not
1163
+ */
946
1164
  function isDeclaredInRenderPropLoose(node) {
947
- if (isDirectValueOfRenderPropertyLoose(node)) {
948
- return true;
949
- }
950
- const parent = AST14.findParentNode(node, AST14.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
951
- if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
952
- return false;
953
- }
954
- return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
1165
+ if (isDirectValueOfRenderPropertyLoose(node)) return true;
1166
+ const parent = AST.findParentNode(node, AST.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
1167
+ if (parent?.type !== AST_NODE_TYPES.JSXAttribute) return false;
1168
+ return parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.name.name.startsWith("render");
955
1169
  }
1170
+
1171
+ //#endregion
1172
+ //#region src/component/component-state.ts
956
1173
  function isThisSetState(node) {
957
- const { callee } = node;
958
- return callee.type === AST_NODE_TYPES.MemberExpression && AST14.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
1174
+ const { callee } = node;
1175
+ return callee.type === AST_NODE_TYPES.MemberExpression && AST.isThisExpression(callee.object) && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
959
1176
  }
960
1177
  function isAssignmentToThisState(node) {
961
- const { left } = node;
962
- return left.type === AST_NODE_TYPES.MemberExpression && AST14.isThisExpression(left.object) && AST14.getPropertyName(left.property) === "state";
1178
+ const { left } = node;
1179
+ return left.type === AST_NODE_TYPES.MemberExpression && AST.isThisExpression(left.object) && AST.getPropertyName(left.property) === "state";
963
1180
  }
964
1181
 
965
- export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getAttributeValue, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRender, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isKeyedElement, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRenderFunctionLoose, isRenderLike, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, isValidComponentDefinition, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
1182
+ //#endregion
1183
+ export { ComponentDetectionHint, ComponentFlag, ComponentPhaseRelevance, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, JSXDetectionHint, JsxEmit, REACT_BUILTIN_HOOK_NAMES, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getJsxConfigFromAnnotation, getJsxConfigFromContext, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectLikeCall, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };