@eslint-react/core 5.17.3 → 5.18.0
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.
- package/dist/index.d.ts +263 -92
- package/dist/index.js +233 -47
- package/package.json +13 -13
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { RuleContext } from "@eslint-react/eslint";
|
|
|
6
6
|
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
7
7
|
//#region src/api.d.ts
|
|
8
8
|
declare namespace isAPI {
|
|
9
|
+
/** The dual-signature predicate type returned by {@link isAPI}. */
|
|
9
10
|
type ReturnType = {
|
|
10
11
|
(context: RuleContext, node: null | TSESTree.Node): boolean;
|
|
11
12
|
(context: RuleContext): (node: null | TSESTree.Node) => boolean;
|
|
@@ -18,6 +19,7 @@ declare namespace isAPI {
|
|
|
18
19
|
*/
|
|
19
20
|
declare function isAPI(api: string): isAPI.ReturnType;
|
|
20
21
|
declare namespace isAPICall {
|
|
22
|
+
/** The dual-signature predicate type returned by {@link isAPICall}. */
|
|
21
23
|
type ReturnType = {
|
|
22
24
|
(context: RuleContext, node: null | TSESTree.Node): node is TSESTree.CallExpression;
|
|
23
25
|
(context: RuleContext): (node: null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
@@ -29,76 +31,140 @@ declare namespace isAPICall {
|
|
|
29
31
|
* @returns A predicate function to check if a node is a call to the API.
|
|
30
32
|
*/
|
|
31
33
|
declare function isAPICall(api: string): isAPICall.ReturnType;
|
|
34
|
+
/** Check if the node is a React `captureOwnerStack` API identifier or member expression. */
|
|
32
35
|
declare const isCaptureOwnerStack: isAPI.ReturnType;
|
|
36
|
+
/** Check if the node is a React `Children.count` API identifier or member expression. */
|
|
33
37
|
declare const isChildrenCount: isAPI.ReturnType;
|
|
38
|
+
/** Check if the node is a React `Children.forEach` API identifier or member expression. */
|
|
34
39
|
declare const isChildrenForEach: isAPI.ReturnType;
|
|
40
|
+
/** Check if the node is a React `Children.map` API identifier or member expression. */
|
|
35
41
|
declare const isChildrenMap: isAPI.ReturnType;
|
|
42
|
+
/** Check if the node is a React `Children.only` API identifier or member expression. */
|
|
36
43
|
declare const isChildrenOnly: isAPI.ReturnType;
|
|
44
|
+
/** Check if the node is a React `Children.toArray` API identifier or member expression. */
|
|
37
45
|
declare const isChildrenToArray: isAPI.ReturnType;
|
|
46
|
+
/** Check if the node is a React `cloneElement` API identifier or member expression. */
|
|
38
47
|
declare const isCloneElement: isAPI.ReturnType;
|
|
48
|
+
/** Check if the node is a React `createContext` API identifier or member expression. */
|
|
39
49
|
declare const isCreateContext: isAPI.ReturnType;
|
|
50
|
+
/** Check if the node is a React `createElement` API identifier or member expression. */
|
|
40
51
|
declare const isCreateElement: isAPI.ReturnType;
|
|
52
|
+
/** Check if the node is a React `createRef` API identifier or member expression. */
|
|
41
53
|
declare const isCreateRef: isAPI.ReturnType;
|
|
54
|
+
/** Check if the node is a React `forwardRef` API identifier or member expression. */
|
|
42
55
|
declare const isForwardRef: isAPI.ReturnType;
|
|
56
|
+
/** Check if the node is a React `memo` API identifier or member expression. */
|
|
43
57
|
declare const isMemo: isAPI.ReturnType;
|
|
58
|
+
/** Check if the node is a React `lazy` API identifier or member expression. */
|
|
44
59
|
declare const isLazy: isAPI.ReturnType;
|
|
60
|
+
/** Check if the node is a call expression to the React `captureOwnerStack` API. */
|
|
45
61
|
declare const isCaptureOwnerStackCall: isAPICall.ReturnType;
|
|
62
|
+
/** Check if the node is a call expression to the React `Children.count` API. */
|
|
46
63
|
declare const isChildrenCountCall: isAPICall.ReturnType;
|
|
64
|
+
/** Check if the node is a call expression to the React `Children.forEach` API. */
|
|
47
65
|
declare const isChildrenForEachCall: isAPICall.ReturnType;
|
|
66
|
+
/** Check if the node is a call expression to the React `Children.map` API. */
|
|
48
67
|
declare const isChildrenMapCall: isAPICall.ReturnType;
|
|
68
|
+
/** Check if the node is a call expression to the React `Children.only` API. */
|
|
49
69
|
declare const isChildrenOnlyCall: isAPICall.ReturnType;
|
|
70
|
+
/** Check if the node is a call expression to the React `Children.toArray` API. */
|
|
50
71
|
declare const isChildrenToArrayCall: isAPICall.ReturnType;
|
|
72
|
+
/** Check if the node is a call expression to the React `cloneElement` API. */
|
|
51
73
|
declare const isCloneElementCall: isAPICall.ReturnType;
|
|
74
|
+
/** Check if the node is a call expression to the React `createContext` API. */
|
|
52
75
|
declare const isCreateContextCall: isAPICall.ReturnType;
|
|
76
|
+
/** Check if the node is a call expression to the React `createElement` API. */
|
|
53
77
|
declare const isCreateElementCall: isAPICall.ReturnType;
|
|
78
|
+
/** Check if the node is a call expression to the React `createRef` API. */
|
|
54
79
|
declare const isCreateRefCall: isAPICall.ReturnType;
|
|
80
|
+
/** Check if the node is a call expression to the React `forwardRef` API. */
|
|
55
81
|
declare const isForwardRefCall: isAPICall.ReturnType;
|
|
82
|
+
/** Check if the node is a call expression to the React `memo` API. */
|
|
56
83
|
declare const isMemoCall: isAPICall.ReturnType;
|
|
84
|
+
/** Check if the node is a call expression to the React `lazy` API. */
|
|
57
85
|
declare const isLazyCall: isAPICall.ReturnType;
|
|
86
|
+
/** Check if the node is a React `use` API identifier or member expression. */
|
|
58
87
|
declare const isUse: isAPI.ReturnType;
|
|
88
|
+
/** Check if the node is a React `useActionState` API identifier or member expression. */
|
|
59
89
|
declare const isUseActionState: isAPI.ReturnType;
|
|
90
|
+
/** Check if the node is a React `useCallback` API identifier or member expression. */
|
|
60
91
|
declare const isUseCallback: isAPI.ReturnType;
|
|
92
|
+
/** Check if the node is a React `useContext` API identifier or member expression. */
|
|
61
93
|
declare const isUseContext: isAPI.ReturnType;
|
|
94
|
+
/** Check if the node is a React `useDebugValue` API identifier or member expression. */
|
|
62
95
|
declare const isUseDebugValue: isAPI.ReturnType;
|
|
96
|
+
/** Check if the node is a React `useDeferredValue` API identifier or member expression. */
|
|
63
97
|
declare const isUseDeferredValue: isAPI.ReturnType;
|
|
98
|
+
/** Check if the node is a React `useEffect` API identifier or member expression. */
|
|
64
99
|
declare const isUseEffect: isAPI.ReturnType;
|
|
100
|
+
/** Check if the node is a React `useFormStatus` API identifier or member expression. */
|
|
65
101
|
declare const isUseFormStatus: isAPI.ReturnType;
|
|
102
|
+
/** Check if the node is a React `useId` API identifier or member expression. */
|
|
66
103
|
declare const isUseId: isAPI.ReturnType;
|
|
104
|
+
/** Check if the node is a React `useImperativeHandle` API identifier or member expression. */
|
|
67
105
|
declare const isUseImperativeHandle: isAPI.ReturnType;
|
|
106
|
+
/** Check if the node is a React `useInsertionEffect` API identifier or member expression. */
|
|
68
107
|
declare const isUseInsertionEffect: isAPI.ReturnType;
|
|
108
|
+
/** Check if the node is a React `useLayoutEffect` API identifier or member expression. */
|
|
69
109
|
declare const isUseLayoutEffect: isAPI.ReturnType;
|
|
110
|
+
/** Check if the node is a React `useMemo` API identifier or member expression. */
|
|
70
111
|
declare const isUseMemo: isAPI.ReturnType;
|
|
112
|
+
/** Check if the node is a React `useOptimistic` API identifier or member expression. */
|
|
71
113
|
declare const isUseOptimistic: isAPI.ReturnType;
|
|
114
|
+
/** Check if the node is a React `useReducer` API identifier or member expression. */
|
|
72
115
|
declare const isUseReducer: isAPI.ReturnType;
|
|
116
|
+
/** Check if the node is a React `useRef` API identifier or member expression. */
|
|
73
117
|
declare const isUseRef: isAPI.ReturnType;
|
|
118
|
+
/** Check if the node is a React `useState` API identifier or member expression. */
|
|
74
119
|
declare const isUseState: isAPI.ReturnType;
|
|
120
|
+
/** Check if the node is a React `useSyncExternalStore` API identifier or member expression. */
|
|
75
121
|
declare const isUseSyncExternalStore: isAPI.ReturnType;
|
|
122
|
+
/** Check if the node is a React `useTransition` API identifier or member expression. */
|
|
76
123
|
declare const isUseTransition: isAPI.ReturnType;
|
|
124
|
+
/** Check if the node is a call expression to the React `use` API. */
|
|
77
125
|
declare const isUseCall: isAPICall.ReturnType;
|
|
126
|
+
/** Check if the node is a call expression to the React `useActionState` API. */
|
|
78
127
|
declare const isUseActionStateCall: isAPICall.ReturnType;
|
|
128
|
+
/** Check if the node is a call expression to the React `useCallback` API. */
|
|
79
129
|
declare const isUseCallbackCall: isAPICall.ReturnType;
|
|
130
|
+
/** Check if the node is a call expression to the React `useContext` API. */
|
|
80
131
|
declare const isUseContextCall: isAPICall.ReturnType;
|
|
132
|
+
/** Check if the node is a call expression to the React `useDebugValue` API. */
|
|
81
133
|
declare const isUseDebugValueCall: isAPICall.ReturnType;
|
|
134
|
+
/** Check if the node is a call expression to the React `useDeferredValue` API. */
|
|
82
135
|
declare const isUseDeferredValueCall: isAPICall.ReturnType;
|
|
136
|
+
/** Check if the node is a call expression to the React `useEffect` API. */
|
|
83
137
|
declare const isUseEffectCall: isAPICall.ReturnType;
|
|
138
|
+
/** Check if the node is a call expression to the React `useFormStatus` API. */
|
|
84
139
|
declare const isUseFormStatusCall: isAPICall.ReturnType;
|
|
140
|
+
/** Check if the node is a call expression to the React `useId` API. */
|
|
85
141
|
declare const isUseIdCall: isAPICall.ReturnType;
|
|
142
|
+
/** Check if the node is a call expression to the React `useImperativeHandle` API. */
|
|
86
143
|
declare const isUseImperativeHandleCall: isAPICall.ReturnType;
|
|
144
|
+
/** Check if the node is a call expression to the React `useInsertionEffect` API. */
|
|
87
145
|
declare const isUseInsertionEffectCall: isAPICall.ReturnType;
|
|
146
|
+
/** Check if the node is a call expression to the React `useLayoutEffect` API. */
|
|
88
147
|
declare const isUseLayoutEffectCall: isAPICall.ReturnType;
|
|
148
|
+
/** Check if the node is a call expression to the React `useMemo` API. */
|
|
89
149
|
declare const isUseMemoCall: isAPICall.ReturnType;
|
|
150
|
+
/** Check if the node is a call expression to the React `useOptimistic` API. */
|
|
90
151
|
declare const isUseOptimisticCall: isAPICall.ReturnType;
|
|
152
|
+
/** Check if the node is a call expression to the React `useReducer` API. */
|
|
91
153
|
declare const isUseReducerCall: isAPICall.ReturnType;
|
|
154
|
+
/** Check if the node is a call expression to the React `useRef` API. */
|
|
92
155
|
declare const isUseRefCall: isAPICall.ReturnType;
|
|
156
|
+
/** Check if the node is a call expression to the React `useState` API. */
|
|
93
157
|
declare const isUseStateCall: isAPICall.ReturnType;
|
|
158
|
+
/** Check if the node is a call expression to the React `useSyncExternalStore` API. */
|
|
94
159
|
declare const isUseSyncExternalStoreCall: isAPICall.ReturnType;
|
|
160
|
+
/** Check if the node is a call expression to the React `useTransition` API. */
|
|
95
161
|
declare const isUseTransitionCall: isAPICall.ReturnType;
|
|
96
162
|
//#endregion
|
|
97
163
|
//#region src/class.d.ts
|
|
98
164
|
/**
|
|
99
165
|
* Get the class identifier of a class node.
|
|
100
166
|
* @param node The class node to get the identifier from.
|
|
101
|
-
* @returns The class identifier or null if not found.
|
|
167
|
+
* @returns The class identifier or `null` if not found.
|
|
102
168
|
*/
|
|
103
169
|
declare function getClassId(node: TSESTreeClass): TSESTree.BindingName | null;
|
|
104
170
|
//#endregion
|
|
@@ -151,17 +217,31 @@ interface SemanticFunc extends SemanticNode {
|
|
|
151
217
|
* @deprecated Class components are legacy. This type exists only to support legacy rules.
|
|
152
218
|
*/
|
|
153
219
|
interface ClassComponentSemanticNode extends SemanticNode {
|
|
220
|
+
/** The identifier of the class component. */
|
|
154
221
|
id: null | TSESTree.BindingName;
|
|
222
|
+
/** The kind of component. */
|
|
155
223
|
kind: "class-component";
|
|
224
|
+
/** The display name of the component. */
|
|
156
225
|
displayName: null | TSESTree.Expression;
|
|
226
|
+
/** Flags describing the component's characteristics. */
|
|
157
227
|
flag: bigint;
|
|
228
|
+
/** Hint for how the component was detected. */
|
|
158
229
|
hint: bigint;
|
|
230
|
+
/** The methods of the class component. */
|
|
159
231
|
methods: TSESTreeMethodOrPropertyDefinition[];
|
|
232
|
+
/** The AST node of the class. */
|
|
160
233
|
node: TSESTreeClass;
|
|
161
234
|
}
|
|
235
|
+
/**
|
|
236
|
+
* Check if the node is a class component (extends `Component` or `PureComponent`).
|
|
237
|
+
* @param node The node to check.
|
|
238
|
+
* @returns `true` if the node is a class component.
|
|
239
|
+
*/
|
|
162
240
|
declare function isClassComponent(node: TSESTree.Node): node is TSESTreeClass;
|
|
163
241
|
/**
|
|
242
|
+
* Check if the node is a pure component (extends `PureComponent`).
|
|
164
243
|
* @param node The AST node to check.
|
|
244
|
+
* @returns `true` if the node is a pure component.
|
|
165
245
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
166
246
|
*/
|
|
167
247
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
@@ -202,18 +282,29 @@ declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is TSEST
|
|
|
202
282
|
/** @deprecated Class components are legacy. */
|
|
203
283
|
declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is TSESTreeMethodOrPropertyDefinition;
|
|
204
284
|
/**
|
|
285
|
+
* Check if the node is a render-like method of a class component.
|
|
205
286
|
* @param node The AST node to check.
|
|
287
|
+
* @returns `true` if the node is a render-like method.
|
|
206
288
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
207
289
|
*/
|
|
208
290
|
declare function isRenderMethodLike(node: TSESTree.Node): node is TSESTreeMethodOrPropertyDefinition;
|
|
291
|
+
/**
|
|
292
|
+
* Check if the function is a callback passed to a class component's render method.
|
|
293
|
+
* @param node The function node to check.
|
|
294
|
+
* @returns `true` if the function is a render method callback.
|
|
295
|
+
*/
|
|
209
296
|
declare function isRenderMethodCallback(node: TSESTreeFunction): boolean;
|
|
210
297
|
/**
|
|
298
|
+
* Check if the call expression is a `this.setState(...)` call.
|
|
211
299
|
* @param node The call expression node to check.
|
|
300
|
+
* @returns `true` if the node is a `this.setState(...)` call.
|
|
212
301
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
213
302
|
*/
|
|
214
303
|
declare function isThisSetStateCall(node: TSESTree.CallExpression): boolean;
|
|
215
304
|
/**
|
|
305
|
+
* Check if the assignment expression assigns to `this.state`.
|
|
216
306
|
* @param node The assignment expression node to check.
|
|
307
|
+
* @returns `true` if the node assigns to `this.state`.
|
|
217
308
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
218
309
|
*/
|
|
219
310
|
declare function isAssignmentToThisState(node: TSESTree.AssignmentExpression): boolean;
|
|
@@ -223,6 +314,7 @@ declare function isAssignmentToThisState(node: TSESTree.AssignmentExpression): b
|
|
|
223
314
|
* @deprecated Class components are legacy. This namespace exists only to support legacy rules.
|
|
224
315
|
*/
|
|
225
316
|
declare namespace getClassComponentCollector {
|
|
317
|
+
/** The api and visitor pair returned by {@link getClassComponentCollector}. */
|
|
226
318
|
type ReturnType = {
|
|
227
319
|
api: {
|
|
228
320
|
getAllComponents: (node: TSESTree.Program) => ClassComponentSemanticNode[];
|
|
@@ -231,15 +323,14 @@ declare namespace getClassComponentCollector {
|
|
|
231
323
|
};
|
|
232
324
|
}
|
|
233
325
|
/**
|
|
326
|
+
* Get an api and visitor object for the rule to collect class components.
|
|
234
327
|
* @param context The rule context.
|
|
235
328
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
236
329
|
*/
|
|
237
330
|
declare function getClassComponentCollector(context: RuleContext): getClassComponentCollector.ReturnType;
|
|
238
331
|
//#endregion
|
|
239
332
|
//#region src/function.d.ts
|
|
240
|
-
/**
|
|
241
|
-
* Type representing the return type of `getFunctionId`.
|
|
242
|
-
*/
|
|
333
|
+
/** The return type of {@link getFunctionId}. */
|
|
243
334
|
type FunctionID = ReturnType<typeof getFunctionId>;
|
|
244
335
|
/**
|
|
245
336
|
* Represents various AST paths for function declarations.
|
|
@@ -254,18 +345,14 @@ type FunctionKind = "client-function" | "server-function";
|
|
|
254
345
|
* Represents a client function semantic node.
|
|
255
346
|
*/
|
|
256
347
|
interface ClientFunctionSemanticNode extends SemanticFunc {
|
|
257
|
-
/**
|
|
258
|
-
* The kind of function.
|
|
259
|
-
*/
|
|
348
|
+
/** The kind of function. */
|
|
260
349
|
kind: "client-function";
|
|
261
350
|
}
|
|
262
351
|
/**
|
|
263
352
|
* Represents a server function semantic node.
|
|
264
353
|
*/
|
|
265
354
|
interface ServerFunctionSemanticNode extends SemanticFunc {
|
|
266
|
-
/**
|
|
267
|
-
* The kind of function.
|
|
268
|
-
*/
|
|
355
|
+
/** The kind of function. */
|
|
269
356
|
kind: "server-function";
|
|
270
357
|
}
|
|
271
358
|
/**
|
|
@@ -273,7 +360,7 @@ interface ServerFunctionSemanticNode extends SemanticFunc {
|
|
|
273
360
|
*/
|
|
274
361
|
type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticNode;
|
|
275
362
|
/**
|
|
276
|
-
*
|
|
363
|
+
* Get the static identifier of a function AST node.
|
|
277
364
|
*
|
|
278
365
|
* @remarks
|
|
279
366
|
* For function declarations this is straightforward. For anonymous function
|
|
@@ -286,16 +373,16 @@ type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticN
|
|
|
286
373
|
* @param node The function node to analyze.
|
|
287
374
|
* @returns The identifier node if found, `null` otherwise.
|
|
288
375
|
*/
|
|
289
|
-
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.
|
|
376
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | TSESTree.PrivateIdentifier | null;
|
|
290
377
|
/**
|
|
291
|
-
*
|
|
378
|
+
* Get the initialization path of a function node in the AST.
|
|
292
379
|
*
|
|
293
380
|
* @param node The function node to analyze.
|
|
294
381
|
* @returns The function initialization path or `null` if not identifiable.
|
|
295
382
|
*/
|
|
296
383
|
declare function getFunctionInitPath(node: TSESTreeFunction): null | FunctionInitPath;
|
|
297
384
|
/**
|
|
298
|
-
*
|
|
385
|
+
* Check if a specific function call exists in the function initialization path.
|
|
299
386
|
*
|
|
300
387
|
* @param callName The name of the call to check for (e.g., "memo", "forwardRef").
|
|
301
388
|
* @param initPath The function initialization path to search in.
|
|
@@ -303,21 +390,27 @@ declare function getFunctionInitPath(node: TSESTreeFunction): null | FunctionIni
|
|
|
303
390
|
*/
|
|
304
391
|
declare function isFunctionHasCallInInitPath(callName: string, initPath: FunctionInitPath): boolean;
|
|
305
392
|
/**
|
|
306
|
-
*
|
|
393
|
+
* Check if a function is empty.
|
|
307
394
|
*
|
|
308
395
|
* @param node The function node to check.
|
|
309
396
|
* @returns `true` if the function is empty, `false` otherwise.
|
|
310
397
|
*/
|
|
311
398
|
declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Get the directives of a function (ex: "use strict", "use client", "use server").
|
|
401
|
+
* @param node The function node to get the directives from.
|
|
402
|
+
* @returns The directives of the function.
|
|
403
|
+
*/
|
|
312
404
|
declare function getFunctionDirectives(node: TSESTreeFunction): TSESTreeDirective[];
|
|
313
405
|
/**
|
|
314
|
-
*
|
|
406
|
+
* Check if a directive with the given name exists in the function directives.
|
|
315
407
|
*
|
|
316
408
|
* @param node The function AST node.
|
|
317
409
|
* @param name The directive name to check (e.g., "use memo", "use no memo").
|
|
318
410
|
* @returns `true` if the directive exists, `false` otherwise.
|
|
319
411
|
*/
|
|
320
412
|
declare function isFunctionHasDirective(node: TSESTreeFunction, name: string): boolean;
|
|
413
|
+
/** Represents a `displayName` assignment expression (ex: `Component.displayName = "MyComponent"`). */
|
|
321
414
|
type FunctionDisplayNameAssignment = TSESTree.AssignmentExpression & {
|
|
322
415
|
left: TSESTree.MemberExpression & {
|
|
323
416
|
property: TSESTree.Identifier & {
|
|
@@ -327,6 +420,7 @@ type FunctionDisplayNameAssignment = TSESTree.AssignmentExpression & {
|
|
|
327
420
|
operator: "=";
|
|
328
421
|
right: TSESTree.Literal;
|
|
329
422
|
};
|
|
423
|
+
/** The esquery selector matching `displayName` assignment expressions. */
|
|
330
424
|
declare const SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT: string;
|
|
331
425
|
//#endregion
|
|
332
426
|
//#region src/hook.d.ts
|
|
@@ -347,12 +441,14 @@ interface HookSemanticNode extends SemanticNode {
|
|
|
347
441
|
/** The directives used in the function (ex: "use strict", "use client", etc.). */
|
|
348
442
|
directives: TSESTreeDirective[];
|
|
349
443
|
}
|
|
444
|
+
/** Represents a hook call, which can be a call expression or a tagged template expression. */
|
|
350
445
|
type HookCall = TSESTree.CallExpression | TSESTree.TaggedTemplateExpression;
|
|
446
|
+
/** The names of React's built-in hooks. */
|
|
351
447
|
declare const REACT_BUILTIN_HOOK_NAMES: readonly ["use", "useActionState", "useCallback", "useContext", "useDebugValue", "useDeferredValue", "useEffect", "useFormStatus", "useId", "useImperativeHandle", "useInsertionEffect", "useLayoutEffect", "useMemo", "useOptimistic", "useReducer", "useRef", "useState", "useSyncExternalStore", "useTransition"];
|
|
352
448
|
/**
|
|
353
|
-
*
|
|
354
|
-
* character to exclude identifiers like "user".
|
|
449
|
+
* Check if the name is a hook name (starts with `use` followed by an uppercase letter or digit).
|
|
355
450
|
* @param name The name of the identifier to check.
|
|
451
|
+
* @returns `true` if the name is a hook name.
|
|
356
452
|
* @see https://github.com/facebook/react/blob/1d6c8168db1d82713202e842df3167787ffa00ed/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts#L16
|
|
357
453
|
*/
|
|
358
454
|
declare function isHookName(name: string): boolean;
|
|
@@ -369,39 +465,48 @@ declare function isHookId(id: TSESTree.Node): id is TSESTree.Identifier | TSESTr
|
|
|
369
465
|
*/
|
|
370
466
|
declare function isHookTag(tag: TSESTree.Node | null): boolean;
|
|
371
467
|
/**
|
|
372
|
-
*
|
|
468
|
+
* Check if the function node is a hook definition based on its name.
|
|
373
469
|
* @param node The function node to check.
|
|
374
|
-
* @returns
|
|
470
|
+
* @returns `true` if the function is a hook definition.
|
|
375
471
|
*/
|
|
376
472
|
declare function isHookDefinition(node: TSESTreeFunction | null): boolean;
|
|
377
473
|
/**
|
|
378
|
-
* Check if the
|
|
474
|
+
* Check if the node is a React Hook call by its name.
|
|
379
475
|
* @param node The node to check.
|
|
380
476
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
381
477
|
*/
|
|
382
478
|
declare function isHookCall(node: TSESTree.Node | null): node is TSESTree.CallExpression;
|
|
383
479
|
/**
|
|
384
|
-
*
|
|
480
|
+
* Check if the node is a useRef-like call (ex: `useRef` or a custom ref hook).
|
|
385
481
|
* @param node The AST node to check.
|
|
386
|
-
* @param
|
|
387
|
-
* @returns
|
|
482
|
+
* @param additionalRefHooks Regex pattern matching custom hooks that should be treated as ref hooks.
|
|
483
|
+
* @returns `true` if the node is a useRef-like call.
|
|
388
484
|
*/
|
|
389
|
-
declare function
|
|
485
|
+
declare function isUseRefLikeCall(node: TSESTree.Node | null, additionalRefHooks?: RegExpLike): node is TSESTree.CallExpression;
|
|
390
486
|
/**
|
|
391
|
-
*
|
|
487
|
+
* Check if the node is a useState-like call (ex: `useState` or a custom state hook).
|
|
392
488
|
* @param node The AST node to check.
|
|
393
489
|
* @param additionalStateHooks Regex pattern matching custom hooks that should be treated as state hooks.
|
|
394
|
-
* @returns
|
|
490
|
+
* @returns `true` if the node is a useState-like call.
|
|
395
491
|
*/
|
|
396
492
|
declare function isUseStateLikeCall(node: TSESTree.Node | null, additionalStateHooks?: RegExpLike): node is TSESTree.CallExpression;
|
|
397
493
|
/**
|
|
398
|
-
*
|
|
494
|
+
* Check if the node is a useEffect-like call (ex: `useEffect`, `useLayoutEffect`, or a custom effect hook).
|
|
399
495
|
* @param node The AST node to check.
|
|
496
|
+
* @param additionalEffectHooks Regex pattern matching custom hooks that should be treated as effect hooks.
|
|
497
|
+
* @returns `true` if the node is a useEffect-like call.
|
|
498
|
+
*/
|
|
499
|
+
declare function isUseEffectLikeCall(node: TSESTree.Node | null, additionalEffectHooks?: RegExpLike): node is TSESTree.CallExpression;
|
|
500
|
+
/**
|
|
501
|
+
* Check if the node is the setup callback passed to a useEffect-like call.
|
|
502
|
+
* @param node The AST node to check.
|
|
503
|
+
* @returns `true` if the node is a useEffect setup callback.
|
|
400
504
|
*/
|
|
401
505
|
declare function isUseEffectSetupCallback(node: TSESTree.Node | null): boolean;
|
|
402
506
|
/**
|
|
403
|
-
*
|
|
507
|
+
* Check if the node is the cleanup callback returned by a useEffect-like setup callback.
|
|
404
508
|
* @param node The AST node to check.
|
|
509
|
+
* @returns `true` if the node is a useEffect cleanup callback.
|
|
405
510
|
*/
|
|
406
511
|
declare function isUseEffectCleanupCallback(node: TSESTree.Node | null): boolean;
|
|
407
512
|
//#endregion
|
|
@@ -410,53 +515,29 @@ declare function isUseEffectCleanupCallback(node: TSESTree.Node | null): boolean
|
|
|
410
515
|
* Represents a React Function Component.
|
|
411
516
|
*/
|
|
412
517
|
interface FunctionComponentSemanticNode extends SemanticNode {
|
|
413
|
-
/**
|
|
414
|
-
* The identifier or identifier sequence of the component.
|
|
415
|
-
*/
|
|
518
|
+
/** The identifier or identifier sequence of the component. */
|
|
416
519
|
id: FunctionID;
|
|
417
|
-
/**
|
|
418
|
-
* The kind of component.
|
|
419
|
-
*/
|
|
520
|
+
/** The kind of component. */
|
|
420
521
|
kind: "component";
|
|
421
|
-
/**
|
|
422
|
-
* The AST node of the function.
|
|
423
|
-
*/
|
|
522
|
+
/** The AST node of the function. */
|
|
424
523
|
node: TSESTreeFunction;
|
|
425
|
-
/**
|
|
426
|
-
* Flags describing the component's characteristics.
|
|
427
|
-
*/
|
|
524
|
+
/** Flags describing the component's characteristics. */
|
|
428
525
|
flag: bigint;
|
|
429
|
-
/**
|
|
430
|
-
* Hint for how the component was detected.
|
|
431
|
-
*/
|
|
526
|
+
/** Hint for how the component was detected. */
|
|
432
527
|
hint: bigint;
|
|
433
|
-
/**
|
|
434
|
-
* List of expressions returned by the component.
|
|
435
|
-
*/
|
|
528
|
+
/** List of expressions returned by the component. */
|
|
436
529
|
rets: TSESTree.ReturnStatement["argument"][];
|
|
437
|
-
/**
|
|
438
|
-
* The initialization path of the function.
|
|
439
|
-
*/
|
|
530
|
+
/** The initialization path of the function. */
|
|
440
531
|
initPath: null | FunctionInitPath;
|
|
441
|
-
/**
|
|
442
|
-
* Indicates if the component is inside an export default declaration.
|
|
443
|
-
*/
|
|
532
|
+
/** Indicates if the component is inside an export default declaration. */
|
|
444
533
|
isExportDefault: boolean;
|
|
445
|
-
/**
|
|
446
|
-
* Indicates if the component is itself an export default declaration.
|
|
447
|
-
*/
|
|
534
|
+
/** Indicates if the component is itself an export default declaration. */
|
|
448
535
|
isExportDefaultDeclaration: boolean;
|
|
449
|
-
/**
|
|
450
|
-
* List of hook calls within the component.
|
|
451
|
-
*/
|
|
536
|
+
/** List of hook calls within the component. */
|
|
452
537
|
hookCalls: HookCall[];
|
|
453
|
-
/**
|
|
454
|
-
* The display name of the component.
|
|
455
|
-
*/
|
|
538
|
+
/** The display name of the component. */
|
|
456
539
|
displayName: null | TSESTree.Expression;
|
|
457
|
-
/**
|
|
458
|
-
* The directives used in the function (ex: "use strict", "use client", etc.).
|
|
459
|
-
*/
|
|
540
|
+
/** The directives used in the function (ex: "use strict", "use client", etc.). */
|
|
460
541
|
directives: TSESTreeDirective[];
|
|
461
542
|
}
|
|
462
543
|
/**
|
|
@@ -505,11 +586,13 @@ declare function getFunctionComponentId(context: RuleContext, node: TSESTreeFunc
|
|
|
505
586
|
/**
|
|
506
587
|
* Check if a string matches the strict component name pattern.
|
|
507
588
|
* @param name The name to check.
|
|
589
|
+
* @returns `true` if the name matches the strict component name pattern.
|
|
508
590
|
*/
|
|
509
591
|
declare function isFunctionComponentName(name: string): boolean;
|
|
510
592
|
/**
|
|
511
593
|
* Check if a string matches the loose component name pattern.
|
|
512
594
|
* @param name The name to check.
|
|
595
|
+
* @returns `true` if the name matches the loose component name pattern.
|
|
513
596
|
*/
|
|
514
597
|
declare function isFunctionComponentNameLoose(name: string): boolean;
|
|
515
598
|
/**
|
|
@@ -517,21 +600,30 @@ declare function isFunctionComponentNameLoose(name: string): boolean;
|
|
|
517
600
|
* @param context The rule context.
|
|
518
601
|
* @param fn The function to check.
|
|
519
602
|
* @param allowNone Whether to allow no name.
|
|
520
|
-
* @returns
|
|
603
|
+
* @returns `true` if the function has a loose component name.
|
|
521
604
|
*/
|
|
522
605
|
declare function isFunctionWithLooseComponentName(context: RuleContext, fn: TSESTreeFunction, allowNone?: boolean): boolean;
|
|
606
|
+
/** The bit-flags for customizing function component detection. */
|
|
523
607
|
type FunctionComponentDetectionHint = bigint;
|
|
524
608
|
/**
|
|
525
609
|
* Hints for component collector.
|
|
526
610
|
*/
|
|
527
611
|
declare const FunctionComponentDetectionHint: {
|
|
612
|
+
/** Exclude functions defined as class methods from component detection. */
|
|
528
613
|
readonly DoNotIncludeFunctionDefinedAsClassMethod: bigint;
|
|
614
|
+
/** Exclude functions defined as class properties from component detection. */
|
|
529
615
|
readonly DoNotIncludeFunctionDefinedAsClassProperty: bigint;
|
|
616
|
+
/** Exclude functions defined as object methods from component detection. */
|
|
530
617
|
readonly DoNotIncludeFunctionDefinedAsObjectMethod: bigint;
|
|
618
|
+
/** Exclude functions defined as array expression elements from component detection. */
|
|
531
619
|
readonly DoNotIncludeFunctionDefinedAsArrayExpressionElement: bigint;
|
|
620
|
+
/** Exclude functions defined as array pattern elements from component detection. */
|
|
532
621
|
readonly DoNotIncludeFunctionDefinedAsArrayPatternElement: bigint;
|
|
622
|
+
/** Exclude functions defined as array flatMap callbacks from component detection. */
|
|
533
623
|
readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
|
|
624
|
+
/** Exclude functions defined as array map callbacks from component detection. */
|
|
534
625
|
readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
|
|
626
|
+
/** Exclude functions defined as arbitrary call expression callbacks from component detection. */
|
|
535
627
|
readonly DoNotIncludeFunctionDefinedAsArbitraryCallExpressionCallback: bigint;
|
|
536
628
|
readonly None: 0n;
|
|
537
629
|
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
@@ -551,7 +643,7 @@ declare const FunctionComponentDetectionHint: {
|
|
|
551
643
|
*/
|
|
552
644
|
declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
553
645
|
/**
|
|
554
|
-
*
|
|
646
|
+
* Check if the function node is a valid React component definition.
|
|
555
647
|
*
|
|
556
648
|
* @param context The rule context.
|
|
557
649
|
* @param node The function node to analyze.
|
|
@@ -562,10 +654,12 @@ declare function isFunctionComponentDefinition(context: RuleContext, node: TSEST
|
|
|
562
654
|
//#endregion
|
|
563
655
|
//#region src/function-component-collector.d.ts
|
|
564
656
|
declare namespace getFunctionComponentCollector {
|
|
657
|
+
/** The options for {@link getFunctionComponentCollector}. */
|
|
565
658
|
type Options = {
|
|
566
659
|
collectDisplayName?: boolean;
|
|
567
660
|
hint?: FunctionComponentDetectionHint;
|
|
568
661
|
};
|
|
662
|
+
/** The api and visitor pair returned by {@link getFunctionComponentCollector}. */
|
|
569
663
|
type ReturnType = {
|
|
570
664
|
api: {
|
|
571
665
|
getAllComponents: (node: TSESTree.Program) => FunctionComponentSemanticNode[];
|
|
@@ -583,6 +677,7 @@ declare function getFunctionComponentCollector(context: RuleContext, options?: g
|
|
|
583
677
|
//#endregion
|
|
584
678
|
//#region src/hook-collector.d.ts
|
|
585
679
|
declare namespace getHookCollector {
|
|
680
|
+
/** The api and visitor pair returned by {@link getHookCollector}. */
|
|
586
681
|
type ReturnType = {
|
|
587
682
|
api: {
|
|
588
683
|
getAllHooks(node: TSESTree.Program): HookSemanticNode[];
|
|
@@ -609,17 +704,29 @@ type JsxDetectionHint = bigint;
|
|
|
609
704
|
* Hints for JSX detection.
|
|
610
705
|
*/
|
|
611
706
|
declare const JsxDetectionHint: {
|
|
707
|
+
/** No hints set. */
|
|
612
708
|
readonly None: 0n;
|
|
709
|
+
/** Do not treat `null` values as JSX-like. */
|
|
613
710
|
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
711
|
+
/** Do not treat number values as JSX-like. */
|
|
614
712
|
readonly DoNotIncludeJsxWithNumberValue: bigint;
|
|
713
|
+
/** Do not treat bigint values as JSX-like. */
|
|
615
714
|
readonly DoNotIncludeJsxWithBigIntValue: bigint;
|
|
715
|
+
/** Do not treat string values as JSX-like. */
|
|
616
716
|
readonly DoNotIncludeJsxWithStringValue: bigint;
|
|
717
|
+
/** Do not treat boolean values as JSX-like. */
|
|
617
718
|
readonly DoNotIncludeJsxWithBooleanValue: bigint;
|
|
719
|
+
/** Do not treat undefined values as JSX-like. */
|
|
618
720
|
readonly DoNotIncludeJsxWithUndefinedValue: bigint;
|
|
721
|
+
/** Do not treat empty array values as JSX-like. */
|
|
619
722
|
readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
|
|
723
|
+
/** Do not treat `createElement` calls as JSX-like. */
|
|
620
724
|
readonly DoNotIncludeJsxWithCreateElementValue: bigint;
|
|
725
|
+
/** Require all array elements to be JSX-like for the array to be JSX-like. */
|
|
621
726
|
readonly RequireAllArrayElementsToBeJsx: bigint;
|
|
727
|
+
/** Require both sides of a logical expression to be JSX-like. */
|
|
622
728
|
readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
|
|
729
|
+
/** Require both branches of a conditional expression to be JSX-like. */
|
|
623
730
|
readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
|
|
624
731
|
};
|
|
625
732
|
/**
|
|
@@ -631,9 +738,9 @@ declare const JsxDetectionHint: {
|
|
|
631
738
|
*/
|
|
632
739
|
declare const DEFAULT_JSX_DETECTION_HINT: JsxDetectionHint;
|
|
633
740
|
/**
|
|
634
|
-
*
|
|
741
|
+
* Check if the node represents JSX-like content based on heuristics.
|
|
635
742
|
*
|
|
636
|
-
* The detection
|
|
743
|
+
* The detection behavior is configurable through {@link JsxDetectionHint}
|
|
637
744
|
* bit-flags so that callers can opt individual value kinds in or out.
|
|
638
745
|
*
|
|
639
746
|
* Identifiers are resolved to their definitions via scope analysis;
|
|
@@ -641,8 +748,8 @@ declare const DEFAULT_JSX_DETECTION_HINT: JsxDetectionHint;
|
|
|
641
748
|
* treated as not JSX-like instead of recursing indefinitely.
|
|
642
749
|
*
|
|
643
750
|
* @param context The ESLint rule context (needed for variable resolution).
|
|
644
|
-
* @param node The AST node to
|
|
645
|
-
* @param hint Optional bit-flags to adjust detection
|
|
751
|
+
* @param node The AST node to analyze.
|
|
752
|
+
* @param hint Optional bit-flags to adjust detection behavior. Defaults to {@link DEFAULT_JSX_DETECTION_HINT}.
|
|
646
753
|
* @returns Whether the node is considered JSX-like.
|
|
647
754
|
*
|
|
648
755
|
* @example
|
|
@@ -662,9 +769,13 @@ declare function isJsxLike(context: RuleContext, node: TSESTree.Node | null, hin
|
|
|
662
769
|
* annotations found in the source file.
|
|
663
770
|
*/
|
|
664
771
|
interface JsxConfig {
|
|
772
|
+
/** The JSX emit mode. */
|
|
665
773
|
jsx?: ts.JsxEmit;
|
|
774
|
+
/** The JSX factory function (ex: `React.createElement`). */
|
|
666
775
|
jsxFactory?: string;
|
|
776
|
+
/** The JSX fragment factory (ex: `React.Fragment`). */
|
|
667
777
|
jsxFragmentFactory?: string;
|
|
778
|
+
/** The JSX import source (ex: `react`). */
|
|
668
779
|
jsxImportSource?: string;
|
|
669
780
|
}
|
|
670
781
|
/**
|
|
@@ -703,22 +814,48 @@ declare function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
|
|
|
703
814
|
declare function getJsxConfig(context: RuleContext): Required<JsxConfig>;
|
|
704
815
|
//#endregion
|
|
705
816
|
//#region src/type-is.d.ts
|
|
817
|
+
/**
|
|
818
|
+
* Check if the type is a boolean literal type.
|
|
819
|
+
* @param type The type to check.
|
|
820
|
+
* @returns `true` if the type is a boolean literal type.
|
|
821
|
+
*/
|
|
706
822
|
declare function isBooleanLiteralType<TType extends ts.Type>(type: TType): type is TType & {
|
|
707
823
|
intrinsicName: "false" | "true";
|
|
708
824
|
};
|
|
709
|
-
/**
|
|
825
|
+
/**
|
|
826
|
+
* Check if the type is the `false` literal type.
|
|
827
|
+
* @internal
|
|
828
|
+
*/
|
|
710
829
|
declare const isFalseLiteralType: (type: ts.Type) => boolean;
|
|
711
|
-
/**
|
|
830
|
+
/**
|
|
831
|
+
* Check if the type is the `true` literal type.
|
|
832
|
+
* @internal
|
|
833
|
+
*/
|
|
712
834
|
declare const isTrueLiteralType: (type: ts.Type) => boolean;
|
|
713
|
-
/**
|
|
835
|
+
/**
|
|
836
|
+
* Check if the type is an any-like type.
|
|
837
|
+
* @internal
|
|
838
|
+
*/
|
|
714
839
|
declare const isAnyType: (type: ts.Type) => boolean;
|
|
715
|
-
/**
|
|
840
|
+
/**
|
|
841
|
+
* Check if the type is a bigint-like type.
|
|
842
|
+
* @internal
|
|
843
|
+
*/
|
|
716
844
|
declare const isBigIntType: (type: ts.Type) => boolean;
|
|
717
|
-
/**
|
|
845
|
+
/**
|
|
846
|
+
* Check if the type is a boolean-like type.
|
|
847
|
+
* @internal
|
|
848
|
+
*/
|
|
718
849
|
declare const isBooleanType: (type: ts.Type) => boolean;
|
|
719
|
-
/**
|
|
850
|
+
/**
|
|
851
|
+
* Check if the type is an enum-like type.
|
|
852
|
+
* @internal
|
|
853
|
+
*/
|
|
720
854
|
declare const isEnumType: (type: ts.Type) => boolean;
|
|
721
|
-
/**
|
|
855
|
+
/**
|
|
856
|
+
* Check if the type is a falsy bigint literal type.
|
|
857
|
+
* @internal
|
|
858
|
+
*/
|
|
722
859
|
declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
723
860
|
freshType: ts.FreshableType;
|
|
724
861
|
regularType: ts.FreshableType;
|
|
@@ -755,21 +892,45 @@ declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
|
755
892
|
base10Value: "0";
|
|
756
893
|
};
|
|
757
894
|
};
|
|
758
|
-
/**
|
|
895
|
+
/**
|
|
896
|
+
* Check if the type is a falsy number literal type.
|
|
897
|
+
* @internal
|
|
898
|
+
*/
|
|
759
899
|
declare const isFalsyNumberType: (type: ts.Type) => boolean;
|
|
760
|
-
/**
|
|
900
|
+
/**
|
|
901
|
+
* Check if the type is a falsy string literal type.
|
|
902
|
+
* @internal
|
|
903
|
+
*/
|
|
761
904
|
declare const isFalsyStringType: (type: ts.Type) => boolean;
|
|
762
|
-
/**
|
|
905
|
+
/**
|
|
906
|
+
* Check if the type is the never type.
|
|
907
|
+
* @internal
|
|
908
|
+
*/
|
|
763
909
|
declare const isNeverType: (type: ts.Type) => boolean;
|
|
764
|
-
/**
|
|
910
|
+
/**
|
|
911
|
+
* Check if the type is a nullish type (null, undefined, or void).
|
|
912
|
+
* @internal
|
|
913
|
+
*/
|
|
765
914
|
declare const isNullishType: (type: ts.Type) => boolean;
|
|
766
|
-
/**
|
|
915
|
+
/**
|
|
916
|
+
* Check if the type is a number-like type.
|
|
917
|
+
* @internal
|
|
918
|
+
*/
|
|
767
919
|
declare const isNumberType: (type: ts.Type) => boolean;
|
|
768
|
-
/**
|
|
920
|
+
/**
|
|
921
|
+
* Check if the type is an object type.
|
|
922
|
+
* @internal
|
|
923
|
+
*/
|
|
769
924
|
declare const isObjectType: (type: ts.Type) => boolean;
|
|
770
|
-
/**
|
|
925
|
+
/**
|
|
926
|
+
* Check if the type is a string-like type.
|
|
927
|
+
* @internal
|
|
928
|
+
*/
|
|
771
929
|
declare const isStringType: (type: ts.Type) => boolean;
|
|
772
|
-
/**
|
|
930
|
+
/**
|
|
931
|
+
* Check if the type is a truthy bigint literal type.
|
|
932
|
+
* @internal
|
|
933
|
+
*/
|
|
773
934
|
declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
774
935
|
freshType: ts.FreshableType;
|
|
775
936
|
regularType: ts.FreshableType;
|
|
@@ -803,16 +964,25 @@ declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
|
803
964
|
isIndexType: () => this is ts.IndexType;
|
|
804
965
|
value: ts.PseudoBigInt;
|
|
805
966
|
};
|
|
806
|
-
/**
|
|
967
|
+
/**
|
|
968
|
+
* Check if the type is a truthy number literal type.
|
|
969
|
+
* @internal
|
|
970
|
+
*/
|
|
807
971
|
declare const isTruthyNumberType: (type: ts.Type) => boolean;
|
|
808
|
-
/**
|
|
972
|
+
/**
|
|
973
|
+
* Check if the type is a truthy string literal type.
|
|
974
|
+
* @internal
|
|
975
|
+
*/
|
|
809
976
|
declare const isTruthyStringType: (type: ts.Type) => boolean;
|
|
810
|
-
/**
|
|
977
|
+
/**
|
|
978
|
+
* Check if the type is the unknown type.
|
|
979
|
+
* @internal
|
|
980
|
+
*/
|
|
811
981
|
declare const isUnknownType: (type: ts.Type) => boolean;
|
|
812
982
|
//#endregion
|
|
813
983
|
//#region src/type-name.d.ts
|
|
814
984
|
/**
|
|
815
|
-
*
|
|
985
|
+
* Get the fully qualified name of a symbol, handling cases that `ts.TypeChecker.getFullyQualifiedName` does not handle (ex: `export as namespace preact`).
|
|
816
986
|
* @param checker The TypeScript type checker.
|
|
817
987
|
* @param symbol The symbol to get fully qualified name for.
|
|
818
988
|
* @returns The fully qualified name of the symbol.
|
|
@@ -820,14 +990,15 @@ declare const isUnknownType: (type: ts.Type) => boolean;
|
|
|
820
990
|
declare function getFullyQualifiedNameEx(checker: ts.TypeChecker, symbol: ts.Symbol): string;
|
|
821
991
|
//#endregion
|
|
822
992
|
//#region src/type-variant.d.ts
|
|
993
|
+
/** Represents the variant of a type for boolean expression analysis. */
|
|
823
994
|
type TypeVariant = "any" | "bigint" | "boolean" | "enum" | "never" | "nullish" | "number" | "object" | "string" | "unknown" | "falsy bigint" | "falsy boolean" | "falsy number" | "falsy string" | "truthy bigint" | "truthy boolean" | "truthy number" | "truthy string";
|
|
824
995
|
/**
|
|
825
|
-
* Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements.
|
|
826
996
|
* Get the variants of an array of types.
|
|
827
997
|
* @param types The types to get the variants of.
|
|
828
998
|
* @returns The variants of the types.
|
|
999
|
+
* @remarks Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements.
|
|
829
1000
|
* @internal
|
|
830
1001
|
*/
|
|
831
1002
|
declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
|
|
832
1003
|
//#endregion
|
|
833
|
-
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, FunctionComponentSemanticNode, FunctionDisplayNameAssignment, FunctionID, FunctionInitPath, FunctionKind, FunctionSemanticNode, HookCall, HookSemanticNode, JsxConfig, JsxDetectionHint, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, TypeVariant, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanLiteralType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFunctionComponentDefinition, isFunctionComponentName, isFunctionComponentNameLoose, isFunctionComponentWrapperCall, isFunctionComponentWrapperCallback, isFunctionEmpty, isFunctionHasCallInInitPath, isFunctionHasDirective, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHookCall, isHookDefinition, isHookId, isHookName, isHookTag, isJsxLike, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isStringType, isThisSetStateCall, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUse, isUseActionState, isUseActionStateCall, isUseCall, isUseCallback, isUseCallbackCall, isUseContext, isUseContextCall, isUseDebugValue, isUseDebugValueCall, isUseDeferredValue, isUseDeferredValueCall, isUseEffect, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatus, isUseFormStatusCall, isUseId, isUseIdCall, isUseImperativeHandle, isUseImperativeHandleCall, isUseInsertionEffect, isUseInsertionEffectCall, isUseLayoutEffect, isUseLayoutEffectCall, isUseMemo, isUseMemoCall, isUseOptimistic, isUseOptimisticCall, isUseReducer, isUseReducerCall, isUseRef, isUseRefCall, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|
|
1004
|
+
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentDetectionHint, FunctionComponentFlag, FunctionComponentSemanticNode, FunctionDisplayNameAssignment, FunctionID, FunctionInitPath, FunctionKind, FunctionSemanticNode, HookCall, HookSemanticNode, JsxConfig, JsxDetectionHint, REACT_BUILTIN_HOOK_NAMES, SEL_FUNCTION_DISPLAY_NAME_ASSIGNMENT, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, TypeVariant, getClassComponentCollector, getClassId, getFullyQualifiedNameEx, getFunctionComponentCollector, getFunctionComponentFlagFromInitPath, getFunctionComponentId, getFunctionDirectives, getFunctionId, getFunctionInitPath, getHookCollector, getJsxConfig, getJsxConfigFromAnnotation, getJsxConfigFromCompilerOptions, getTypeVariants, isAPI, isAPICall, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanLiteralType, isBooleanType, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDidCatch, isComponentDidMount, isComponentDidUpdate, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUpdate, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFunctionComponentDefinition, isFunctionComponentName, isFunctionComponentNameLoose, isFunctionComponentWrapperCall, isFunctionComponentWrapperCallback, isFunctionEmpty, isFunctionHasCallInInitPath, isFunctionHasDirective, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHookCall, isHookDefinition, isHookId, isHookName, isHookTag, isJsxLike, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isStringType, isThisSetStateCall, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUse, isUseActionState, isUseActionStateCall, isUseCall, isUseCallback, isUseCallbackCall, isUseContext, isUseContextCall, isUseDebugValue, isUseDebugValueCall, isUseDeferredValue, isUseDeferredValueCall, isUseEffect, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatus, isUseFormStatusCall, isUseId, isUseIdCall, isUseImperativeHandle, isUseImperativeHandleCall, isUseInsertionEffect, isUseInsertionEffectCall, isUseLayoutEffect, isUseLayoutEffectCall, isUseMemo, isUseMemoCall, isUseOptimistic, isUseOptimisticCall, isUseReducer, isUseReducerCall, isUseRef, isUseRefCall, isUseRefLikeCall, isUseState, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStore, isUseSyncExternalStoreCall, isUseTransition, isUseTransitionCall };
|