@eslint-react/core 2.0.0-next.17 → 2.0.0-next.171
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 +534 -269
- package/dist/index.js +1161 -877
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
1
|
+
import { TSESTree } from "@typescript-eslint/types";
|
|
2
|
+
import * as AST from "@eslint-react/ast";
|
|
3
|
+
import { unit } from "@eslint-react/eff";
|
|
4
|
+
import { RuleContext } from "@eslint-react/kit";
|
|
5
|
+
import * as birecord0 from "birecord";
|
|
6
|
+
import { isFalseLiteralType, isTrueLiteralType } from "ts-api-utils";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
9
|
+
import { Scope } from "@typescript-eslint/scope-manager";
|
|
10
|
+
|
|
11
|
+
//#region src/component/component-children.d.ts
|
|
10
12
|
/**
|
|
11
13
|
* Determines whether inside `createElement`'s children.
|
|
12
14
|
* @param context The rule context
|
|
@@ -14,132 +16,139 @@ import * as VAR from '@eslint-react/var';
|
|
|
14
16
|
* @returns `true` if the node is inside createElement's children
|
|
15
17
|
*/
|
|
16
18
|
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
17
|
-
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/component/component-detection-hint.d.ts
|
|
18
21
|
type ComponentDetectionHint = bigint;
|
|
19
22
|
/**
|
|
20
23
|
* Hints for component collector
|
|
21
24
|
*/
|
|
22
25
|
declare const ComponentDetectionHint: {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Skip function component created by React.memo
|
|
28
|
+
*/
|
|
29
|
+
readonly SkipMemo: bigint;
|
|
30
|
+
/**
|
|
31
|
+
* Skip function component created by React.forwardRef
|
|
32
|
+
*/
|
|
33
|
+
readonly SkipForwardRef: bigint;
|
|
34
|
+
/**
|
|
35
|
+
* Skip function component defined as array map argument
|
|
36
|
+
*/
|
|
37
|
+
readonly SkipArrayMapArgument: bigint;
|
|
38
|
+
/**
|
|
39
|
+
* Skip function component defined on object method
|
|
40
|
+
*/
|
|
41
|
+
readonly SkipObjectMethod: bigint;
|
|
42
|
+
/**
|
|
43
|
+
* Skip function component defined on class method
|
|
44
|
+
*/
|
|
45
|
+
readonly SkipClassMethod: bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Skip function component defined on class property
|
|
48
|
+
*/
|
|
49
|
+
readonly SkipClassProperty: bigint;
|
|
50
|
+
readonly None: 0n;
|
|
51
|
+
readonly SkipUndefined: bigint;
|
|
52
|
+
readonly SkipNullLiteral: bigint;
|
|
53
|
+
readonly SkipBooleanLiteral: bigint;
|
|
54
|
+
readonly SkipStringLiteral: bigint;
|
|
55
|
+
readonly SkipNumberLiteral: bigint;
|
|
56
|
+
readonly SkipBigIntLiteral: bigint;
|
|
57
|
+
readonly SkipEmptyArray: bigint;
|
|
58
|
+
readonly SkipCreateElement: bigint;
|
|
59
|
+
readonly StrictArray: bigint;
|
|
60
|
+
readonly StrictLogical: bigint;
|
|
61
|
+
readonly StrictConditional: bigint;
|
|
59
62
|
};
|
|
60
63
|
/**
|
|
61
64
|
* Default component detection hint
|
|
62
65
|
*/
|
|
63
66
|
declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
64
|
-
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/component/component-phase.d.ts
|
|
65
69
|
type ComponentEffectPhaseKind = "cleanup" | "setup";
|
|
66
70
|
type ComponentLifecyclePhaseKind = "mount" | "unmount";
|
|
67
71
|
type ComponentPhaseKind = ComponentEffectPhaseKind | ComponentLifecyclePhaseKind;
|
|
68
|
-
declare const ComponentPhaseRelevance:
|
|
69
|
-
|
|
70
|
-
|
|
72
|
+
declare const ComponentPhaseRelevance: birecord0.BiRecord<{
|
|
73
|
+
readonly mount: "unmount";
|
|
74
|
+
readonly setup: "cleanup";
|
|
71
75
|
}>;
|
|
72
76
|
declare const isInversePhase: {
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
(a: ComponentPhaseKind): (b: ComponentPhaseKind) => boolean;
|
|
78
|
+
(a: ComponentPhaseKind, b: ComponentPhaseKind): boolean;
|
|
75
79
|
};
|
|
76
|
-
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/semantic/semantic-entry.d.ts
|
|
77
82
|
interface SemanticEntry {
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
node: TSESTree.Node;
|
|
84
|
+
phase: ComponentPhaseKind;
|
|
80
85
|
}
|
|
81
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/semantic/semantic-node.d.ts
|
|
82
88
|
interface SemanticNode {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
id: unit | TSESTree.Identifier | TSESTree.Identifier[];
|
|
90
|
+
key: string;
|
|
91
|
+
kind: string;
|
|
92
|
+
name: unit | string;
|
|
93
|
+
node: TSESTree.Node;
|
|
94
|
+
flag: bigint;
|
|
95
|
+
hint: bigint;
|
|
90
96
|
}
|
|
91
|
-
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/component/component-flag.d.ts
|
|
92
99
|
type ComponentFlag = bigint;
|
|
93
100
|
declare const ComponentFlag: {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
None: bigint;
|
|
102
|
+
PureComponent: bigint;
|
|
103
|
+
CreateElement: bigint;
|
|
104
|
+
Memo: bigint;
|
|
105
|
+
ForwardRef: bigint;
|
|
106
|
+
Async: bigint;
|
|
100
107
|
};
|
|
101
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/component/component-semantic-node.d.ts
|
|
102
110
|
interface FunctionComponent extends SemanticNode {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
+
id: unit | TSESTree.Identifier | TSESTree.Identifier[];
|
|
112
|
+
kind: "function";
|
|
113
|
+
node: AST.TSESTreeFunction;
|
|
114
|
+
flag: ComponentFlag;
|
|
115
|
+
hint: ComponentDetectionHint;
|
|
116
|
+
initPath: unit | AST.FunctionInitPath;
|
|
117
|
+
hookCalls: TSESTree.CallExpression[];
|
|
118
|
+
displayName: unit | TSESTree.Expression;
|
|
111
119
|
}
|
|
112
120
|
interface ClassComponent extends SemanticNode {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
121
|
+
id: unit | TSESTree.Identifier;
|
|
122
|
+
kind: "class";
|
|
123
|
+
node: AST.TSESTreeClass;
|
|
124
|
+
flag: ComponentFlag;
|
|
125
|
+
hint: ComponentDetectionHint;
|
|
126
|
+
methods: AST.TSESTreeMethodOrProperty[];
|
|
127
|
+
displayName: unit | TSESTree.Expression;
|
|
120
128
|
}
|
|
121
129
|
type Component = ClassComponent | FunctionComponent;
|
|
122
|
-
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/component/component-collector.d.ts
|
|
123
132
|
type FunctionEntry = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
133
|
+
key: string;
|
|
134
|
+
node: AST.TSESTreeFunction;
|
|
135
|
+
hookCalls: TSESTree.CallExpression[];
|
|
136
|
+
isComponent: boolean;
|
|
128
137
|
};
|
|
129
138
|
declare namespace useComponentCollector {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
};
|
|
141
|
-
listeners: ESLintUtils.RuleListener;
|
|
139
|
+
type Options = {
|
|
140
|
+
collectDisplayName?: boolean;
|
|
141
|
+
collectHookCalls?: boolean;
|
|
142
|
+
hint?: ComponentDetectionHint;
|
|
143
|
+
};
|
|
144
|
+
type ReturnType = {
|
|
145
|
+
ctx: {
|
|
146
|
+
getAllComponents: (node: TSESTree.Program) => Map<string, FunctionComponent>;
|
|
147
|
+
getCurrentEntries: () => FunctionEntry[];
|
|
148
|
+
getCurrentEntry: () => FunctionEntry | unit;
|
|
142
149
|
};
|
|
150
|
+
listeners: ESLintUtils.RuleListener;
|
|
151
|
+
};
|
|
143
152
|
}
|
|
144
153
|
/**
|
|
145
154
|
* Get a ctx and listeners for the rule to collect function components
|
|
@@ -148,21 +157,23 @@ declare namespace useComponentCollector {
|
|
|
148
157
|
* @returns The component collector
|
|
149
158
|
*/
|
|
150
159
|
declare function useComponentCollector(context: RuleContext, options?: useComponentCollector.Options): useComponentCollector.ReturnType;
|
|
151
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/component/component-collector-legacy.d.ts
|
|
152
162
|
declare namespace useComponentCollectorLegacy {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
};
|
|
157
|
-
listeners: ESLintUtils.RuleListener;
|
|
163
|
+
type ReturnType = {
|
|
164
|
+
ctx: {
|
|
165
|
+
getAllComponents: (node: TSESTree$1.Program) => Map<string, ClassComponent>;
|
|
158
166
|
};
|
|
167
|
+
listeners: ESLintUtils.RuleListener;
|
|
168
|
+
};
|
|
159
169
|
}
|
|
160
170
|
/**
|
|
161
171
|
* Get a ctx and listeners object for the rule to collect class components
|
|
162
172
|
* @returns The context and listeners for the rule
|
|
163
173
|
*/
|
|
164
174
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
165
|
-
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/component/component-definition.d.ts
|
|
166
177
|
/**
|
|
167
178
|
* Check whether given node is a function of a render method of a class component
|
|
168
179
|
* @example
|
|
@@ -176,12 +187,22 @@ declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.Retu
|
|
|
176
187
|
* @returns `true` if node is a render function, `false` if not
|
|
177
188
|
*/
|
|
178
189
|
declare function isFunctionOfRenderMethod(node: AST.TSESTreeFunction): boolean;
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Determines if a function node represents a valid React component definition
|
|
192
|
+
* @param context The rule context
|
|
193
|
+
* @param node The function node to check
|
|
194
|
+
* @param hint Component detection hints as bit flags
|
|
195
|
+
* @returns `true` if the node is a valid component definition, `false` otherwise
|
|
196
|
+
*/
|
|
197
|
+
declare function isComponentDefinition(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/component/component-id.d.ts
|
|
200
|
+
declare function getFunctionComponentId(context: RuleContext, node: AST.TSESTreeFunction): TSESTree.Identifier | TSESTree.Identifier[] | unit;
|
|
201
|
+
//#endregion
|
|
202
|
+
//#region src/component/component-init-path.d.ts
|
|
183
203
|
declare function getComponentFlagFromInitPath(initPath: FunctionComponent["initPath"]): bigint;
|
|
184
|
-
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/component/component-is.d.ts
|
|
185
206
|
/**
|
|
186
207
|
* Check if a node is a React class component
|
|
187
208
|
* @param node The AST node to check
|
|
@@ -194,58 +215,37 @@ declare function isClassComponent(node: TSESTree.Node): node is AST.TSESTreeClas
|
|
|
194
215
|
* @returns `true` if the node is a pure component, `false` otherwise
|
|
195
216
|
*/
|
|
196
217
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
197
|
-
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/component/component-kind.d.ts
|
|
198
220
|
type ComponentKind = "classComponent" | "functionComponent";
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
declare
|
|
202
|
-
declare
|
|
203
|
-
declare
|
|
204
|
-
declare
|
|
205
|
-
declare
|
|
206
|
-
declare
|
|
207
|
-
declare
|
|
208
|
-
declare
|
|
209
|
-
declare
|
|
210
|
-
declare
|
|
211
|
-
declare
|
|
212
|
-
declare
|
|
213
|
-
declare
|
|
214
|
-
declare
|
|
215
|
-
declare
|
|
216
|
-
declare
|
|
217
|
-
|
|
221
|
+
//#endregion
|
|
222
|
+
//#region src/component/component-method.d.ts
|
|
223
|
+
declare const isRender: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
224
|
+
declare const isComponentDidCatch: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
225
|
+
declare const isComponentDidMount: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
226
|
+
declare const isComponentDidUpdate: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
227
|
+
declare const isComponentWillMount: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
228
|
+
declare const isComponentWillReceiveProps: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
229
|
+
declare const isComponentWillUnmount: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
230
|
+
declare const isComponentWillUpdate: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
231
|
+
declare const isGetChildContext: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
232
|
+
declare const isGetInitialState: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
233
|
+
declare const isGetSnapshotBeforeUpdate: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
234
|
+
declare const isShouldComponentUpdate: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
235
|
+
declare const isUnsafeComponentWillMount: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
236
|
+
declare const isUnsafeComponentWillReceiveProps: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
237
|
+
declare const isUnsafeComponentWillUpdate: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
238
|
+
declare const isGetDefaultProps: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
239
|
+
declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
240
|
+
declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is AST.TSESTreeMethodOrProperty;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/component/component-name.d.ts
|
|
218
243
|
declare function isComponentName(name: string): boolean;
|
|
219
244
|
declare function isComponentNameLoose(name: string): boolean;
|
|
220
|
-
declare function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] |
|
|
245
|
+
declare function getComponentNameFromId(id: TSESTree.Identifier | TSESTree.Identifier[] | unit): string | undefined;
|
|
221
246
|
declare function hasNoneOrLooseComponentName(context: RuleContext, fn: AST.TSESTreeFunction): boolean;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
* Check whether given node is a render function of a class component
|
|
225
|
-
* @example
|
|
226
|
-
* ```tsx
|
|
227
|
-
* class Component extends React.Component {
|
|
228
|
-
* render() {
|
|
229
|
-
* return <div />;
|
|
230
|
-
* }
|
|
231
|
-
* }
|
|
232
|
-
* ```
|
|
233
|
-
* @param node The AST node to check
|
|
234
|
-
* @returns `true` if node is a render function, `false` if not
|
|
235
|
-
*/
|
|
236
|
-
declare function isRenderLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
|
|
237
|
-
/**
|
|
238
|
-
* Check whether given node is a function of a render function of a class component
|
|
239
|
-
* @example
|
|
240
|
-
* ```tsx
|
|
241
|
-
* class Component extends React.Component {
|
|
242
|
-
* render = () => <div />;
|
|
243
|
-
* ```
|
|
244
|
-
* @param node The AST node to check
|
|
245
|
-
* @returns `true` if node is a render function, `false` if not
|
|
246
|
-
*/
|
|
247
|
-
declare function isFunctionOfRender(node: AST.TSESTreeFunction): boolean;
|
|
248
|
-
|
|
247
|
+
//#endregion
|
|
248
|
+
//#region src/component/component-render-method.d.ts
|
|
249
249
|
/**
|
|
250
250
|
* Check whether given node is a render method of a class component
|
|
251
251
|
* @example
|
|
@@ -259,7 +259,8 @@ declare function isFunctionOfRender(node: AST.TSESTreeFunction): boolean;
|
|
|
259
259
|
* @returns `true` if node is a render function, `false` if not
|
|
260
260
|
*/
|
|
261
261
|
declare function isRenderMethodLike(node: TSESTree.Node): node is AST.TSESTreeMethodOrProperty;
|
|
262
|
-
|
|
262
|
+
//#endregion
|
|
263
|
+
//#region src/component/component-render-prop.d.ts
|
|
263
264
|
/**
|
|
264
265
|
* Unsafe check whether given node is a render function
|
|
265
266
|
* ```tsx
|
|
@@ -309,11 +310,13 @@ declare function isDirectValueOfRenderPropertyLoose(node: TSESTree.Node): boolea
|
|
|
309
310
|
* @returns `true` if component is declared inside a render prop, `false` if not
|
|
310
311
|
*/
|
|
311
312
|
declare function isDeclaredInRenderPropLoose(node: TSESTree.Node): boolean;
|
|
312
|
-
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/component/component-state.d.ts
|
|
313
315
|
type ComponentStateKind = "actionState" | "state";
|
|
314
316
|
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
315
317
|
declare function isAssignmentToThisState(node: TSESTree.AssignmentExpression): boolean;
|
|
316
|
-
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region src/component/component-wrapper.d.ts
|
|
317
320
|
/**
|
|
318
321
|
* Check if the node is a call expression for a component wrapper
|
|
319
322
|
* @param context The ESLint rule context
|
|
@@ -328,39 +331,73 @@ declare function isComponentWrapperCall(context: RuleContext, node: TSESTree.Nod
|
|
|
328
331
|
* @returns `true` if the node is a call expression for a component wrapper loosely
|
|
329
332
|
*/
|
|
330
333
|
declare function isComponentWrapperCallLoose(context: RuleContext, node: TSESTree.Node): boolean;
|
|
331
|
-
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/effect/effect-kind.d.ts
|
|
332
336
|
type EffectKind = "useEffect" | "useLayoutEffect" | "useInsertionEffect";
|
|
333
|
-
|
|
337
|
+
//#endregion
|
|
338
|
+
//#region src/hook/hook-semantic-node.d.ts
|
|
334
339
|
interface Hook extends SemanticNode {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
340
|
+
id: TSESTree.Identifier | unit;
|
|
341
|
+
node: AST.TSESTreeFunction;
|
|
342
|
+
name: string;
|
|
343
|
+
hookCalls: TSESTree.CallExpression[];
|
|
339
344
|
}
|
|
340
|
-
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/hook/hook-collector.d.ts
|
|
341
347
|
declare namespace useHookCollector {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
};
|
|
346
|
-
listeners: ESLintUtils.RuleListener;
|
|
348
|
+
type ReturnType = {
|
|
349
|
+
ctx: {
|
|
350
|
+
getAllHooks(node: TSESTree$1.Program): Map<string, Hook>;
|
|
347
351
|
};
|
|
352
|
+
listeners: ESLintUtils.RuleListener;
|
|
353
|
+
};
|
|
348
354
|
}
|
|
349
355
|
declare function useHookCollector(): useHookCollector.ReturnType;
|
|
350
|
-
|
|
356
|
+
//#endregion
|
|
357
|
+
//#region src/hook/hook-id.d.ts
|
|
351
358
|
declare function isReactHookId(id: TSESTree.Identifier | TSESTree.MemberExpression): boolean;
|
|
352
|
-
|
|
353
|
-
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/hook/hook-is.d.ts
|
|
361
|
+
/**
|
|
362
|
+
* Determines if a function node is a React Hook based on its name.
|
|
363
|
+
* @param node The function node to check
|
|
364
|
+
* @returns True if the function is a React Hook, false otherwise
|
|
365
|
+
*/
|
|
366
|
+
declare function isReactHook(node: AST.TSESTreeFunction | unit): boolean;
|
|
354
367
|
/**
|
|
355
368
|
* Check if the given node is a React Hook call by its name.
|
|
356
369
|
* @param node The node to check.
|
|
357
370
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
358
371
|
*/
|
|
359
|
-
declare function isReactHookCall(node: TSESTree.Node |
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
372
|
+
declare function isReactHookCall(node: TSESTree.Node | unit): boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Checks if a node is a call to a specific React hook, with React import validation.
|
|
375
|
+
* Returns a function that accepts a hook name to check against.
|
|
376
|
+
* @param context The rule context
|
|
377
|
+
* @param node The AST node to check
|
|
378
|
+
* @returns A function that takes a hook name and returns boolean
|
|
379
|
+
*/
|
|
380
|
+
declare function isReactHookCallWithName(context: RuleContext, node: TSESTree.Node | unit): (name: string) => boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Lightweight version of isReactHookCallWithName that doesn't check imports.
|
|
383
|
+
* @param node The AST node to check
|
|
384
|
+
* @returns A function that takes a hook name and returns boolean
|
|
385
|
+
*/
|
|
386
|
+
declare function isReactHookCallWithNameLoose(node: TSESTree.Node | unit): (name: string) => boolean;
|
|
387
|
+
/**
|
|
388
|
+
* Checks if a node is a call to a specific React hook or one of its aliases.
|
|
389
|
+
* @param context The rule context
|
|
390
|
+
* @param name The primary hook name to check
|
|
391
|
+
* @param alias Optional array of alias names to also accept
|
|
392
|
+
* @returns Function that checks if a node matches the hook name or aliases
|
|
393
|
+
*/
|
|
394
|
+
declare function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias?: unit | string[]): (node: TSESTree.CallExpression) => boolean;
|
|
395
|
+
/**
|
|
396
|
+
* Detects useEffect calls and variations (useLayoutEffect, etc.) using regex pattern.
|
|
397
|
+
* @param node The AST node to check
|
|
398
|
+
* @returns True if the node is a useEffect-like call
|
|
399
|
+
*/
|
|
400
|
+
declare function isUseEffectCallLoose(node: TSESTree.Node | unit): boolean;
|
|
364
401
|
declare const isUseCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
365
402
|
declare const isUseActionStateCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
366
403
|
declare const isUseCallbackCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
@@ -380,7 +417,8 @@ declare const isUseRefCall: (context: RuleContext, node: TSESTree.Node | undefin
|
|
|
380
417
|
declare const isUseStateCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
381
418
|
declare const isUseSyncExternalStoreCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
382
419
|
declare const isUseTransitionCall: (context: RuleContext, node: TSESTree.Node | undefined) => boolean;
|
|
383
|
-
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/hook/hook-name.d.ts
|
|
384
422
|
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"];
|
|
385
423
|
/**
|
|
386
424
|
* Catch all identifiers that begin with "use" followed by an uppercase Latin
|
|
@@ -389,17 +427,11 @@ declare const REACT_BUILTIN_HOOK_NAMES: readonly ["use", "useActionState", "useC
|
|
|
389
427
|
* @see https://github.com/facebook/react/blob/1d6c8168db1d82713202e842df3167787ffa00ed/packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts#L16
|
|
390
428
|
*/
|
|
391
429
|
declare function isReactHookName(name: string): boolean;
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
* @param attributes The attributes to search
|
|
398
|
-
* @param initialScope The initial scope to use for variable resolution
|
|
399
|
-
* @returns The JSX attribute node or undefined
|
|
400
|
-
*/
|
|
401
|
-
declare function getAttribute(context: RuleContext, name: string, attributes: (TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute)[], initialScope?: Scope): TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute | _;
|
|
402
|
-
|
|
430
|
+
//#endregion
|
|
431
|
+
//#region src/jsx/jsx-attribute.d.ts
|
|
432
|
+
declare function getAttribute(context: RuleContext, attributes: AST.TSESTreeJSXAttributeLike[], initialScope?: Scope): (name: string) => AST.TSESTreeJSXAttributeLike | undefined;
|
|
433
|
+
//#endregion
|
|
434
|
+
//#region src/jsx/jsx-attribute-name.d.ts
|
|
403
435
|
/**
|
|
404
436
|
* Get the stringified name of a JSX attribute
|
|
405
437
|
* @param context The ESLint rule context
|
|
@@ -407,112 +439,345 @@ declare function getAttribute(context: RuleContext, name: string, attributes: (T
|
|
|
407
439
|
* @returns The name of the attribute
|
|
408
440
|
*/
|
|
409
441
|
declare function getAttributeName(context: RuleContext, node: TSESTree$1.JSXAttribute): string;
|
|
410
|
-
|
|
442
|
+
//#endregion
|
|
443
|
+
//#region src/jsx/jsx-attribute-value.d.ts
|
|
411
444
|
/**
|
|
412
|
-
*
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
445
|
+
* Represents possible JSX attribute value types that can be resolved
|
|
446
|
+
*/
|
|
447
|
+
type AttributeValue = {
|
|
448
|
+
kind: "boolean";
|
|
449
|
+
toStatic(): true;
|
|
450
|
+
} | {
|
|
451
|
+
kind: "element";
|
|
452
|
+
node: TSESTree.JSXElement;
|
|
453
|
+
toStatic(): unknown;
|
|
454
|
+
} | {
|
|
455
|
+
kind: "literal";
|
|
456
|
+
node: TSESTree.Literal;
|
|
457
|
+
toStatic(): TSESTree.Literal["value"];
|
|
458
|
+
} | {
|
|
459
|
+
kind: "expression";
|
|
460
|
+
node: TSESTree.JSXExpressionContainer["expression"];
|
|
461
|
+
toStatic(): unknown;
|
|
462
|
+
} | {
|
|
463
|
+
kind: "spreadProps";
|
|
464
|
+
node: TSESTree.JSXSpreadAttribute["argument"];
|
|
465
|
+
toStatic(name?: string): unknown;
|
|
466
|
+
} | {
|
|
467
|
+
kind: "spreadChild";
|
|
468
|
+
node: TSESTree.JSXSpreadChild["expression"];
|
|
469
|
+
toStatic(): unknown;
|
|
470
|
+
};
|
|
471
|
+
declare function resolveAttributeValue(context: RuleContext, attribute: AST.TSESTreeJSXAttributeLike): {
|
|
472
|
+
readonly kind: "boolean";
|
|
473
|
+
readonly toStatic: () => true;
|
|
474
|
+
readonly node?: never;
|
|
475
|
+
} | {
|
|
476
|
+
readonly kind: "literal";
|
|
477
|
+
readonly node: TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
|
|
478
|
+
readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
|
|
479
|
+
} | {
|
|
480
|
+
readonly kind: "expression";
|
|
481
|
+
readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
|
|
482
|
+
readonly toStatic: () => unknown;
|
|
483
|
+
} | {
|
|
484
|
+
readonly kind: "element";
|
|
485
|
+
readonly node: TSESTree.JSXElement;
|
|
486
|
+
readonly toStatic: () => undefined;
|
|
487
|
+
} | {
|
|
488
|
+
readonly kind: "spreadChild";
|
|
489
|
+
readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
|
|
490
|
+
readonly toStatic: () => undefined;
|
|
491
|
+
} | {
|
|
492
|
+
readonly kind: "spreadProps";
|
|
493
|
+
readonly node: TSESTree.Expression;
|
|
494
|
+
readonly toStatic: (name?: string) => unknown;
|
|
495
|
+
};
|
|
496
|
+
//#endregion
|
|
497
|
+
//#region src/jsx/jsx-detection.d.ts
|
|
498
|
+
/**
|
|
499
|
+
* BitFlags for configuring JSX detection behavior
|
|
500
|
+
* Uses BigInt for bit operations to support many flags
|
|
417
501
|
*/
|
|
418
|
-
declare function getAttributeValue(context: RuleContext, node: TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute, name: string): Exclude<VAR.LazyValue, {
|
|
419
|
-
kind: "lazy";
|
|
420
|
-
}>;
|
|
421
|
-
|
|
422
502
|
type JSXDetectionHint = bigint;
|
|
503
|
+
/**
|
|
504
|
+
* Flags to control JSX detection behavior:
|
|
505
|
+
* - Skip* flags: Ignore specific node types when detecting JSX
|
|
506
|
+
* - Strict* flags: Enforce stricter rules for container types
|
|
507
|
+
*/
|
|
423
508
|
declare const JSXDetectionHint: {
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
509
|
+
readonly None: 0n;
|
|
510
|
+
readonly SkipUndefined: bigint;
|
|
511
|
+
readonly SkipNullLiteral: bigint;
|
|
512
|
+
readonly SkipBooleanLiteral: bigint;
|
|
513
|
+
readonly SkipStringLiteral: bigint;
|
|
514
|
+
readonly SkipNumberLiteral: bigint;
|
|
515
|
+
readonly SkipBigIntLiteral: bigint;
|
|
516
|
+
readonly SkipEmptyArray: bigint;
|
|
517
|
+
readonly SkipCreateElement: bigint;
|
|
518
|
+
readonly StrictArray: bigint;
|
|
519
|
+
readonly StrictLogical: bigint;
|
|
520
|
+
readonly StrictConditional: bigint;
|
|
436
521
|
};
|
|
522
|
+
/**
|
|
523
|
+
* Default JSX detection configuration
|
|
524
|
+
* Skips undefined and boolean literals (common in React)
|
|
525
|
+
*/
|
|
437
526
|
declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
438
|
-
|
|
439
527
|
/**
|
|
440
|
-
*
|
|
528
|
+
* Checks if a node is a `JSXText` or a `Literal` node
|
|
441
529
|
* @param node The AST node to check
|
|
442
530
|
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
443
531
|
*/
|
|
444
|
-
declare function isJsxText(node: TSESTree$1.Node | null |
|
|
532
|
+
declare function isJsxText(node: TSESTree$1.Node | null | unit): node is TSESTree$1.JSXText | TSESTree$1.Literal;
|
|
445
533
|
/**
|
|
446
|
-
*
|
|
447
|
-
*
|
|
534
|
+
* Determines if a node represents JSX-like content based on heuristics
|
|
535
|
+
* Supports configuration through hint flags to customize detection behavior
|
|
536
|
+
*
|
|
537
|
+
* @param code The source code with scope lookup capability
|
|
448
538
|
* @param code.getScope The function to get the scope of a node
|
|
449
|
-
* @param node The AST node to
|
|
450
|
-
* @param hint The
|
|
451
|
-
* @returns boolean
|
|
539
|
+
* @param node The AST node to analyze
|
|
540
|
+
* @param hint The configuration flags to adjust detection behavior
|
|
541
|
+
* @returns boolean Whether the node is considered JSX-like
|
|
452
542
|
*/
|
|
453
543
|
declare function isJsxLike(code: {
|
|
454
|
-
|
|
455
|
-
}, node: TSESTree$1.Node |
|
|
456
|
-
|
|
544
|
+
getScope: (node: TSESTree$1.Node) => Scope;
|
|
545
|
+
}, node: TSESTree$1.Node | unit | null, hint?: JSXDetectionHint): boolean;
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region src/jsx/jsx-element-is.d.ts
|
|
457
548
|
/**
|
|
458
|
-
*
|
|
459
|
-
*
|
|
460
|
-
*
|
|
461
|
-
* @
|
|
549
|
+
* Determines if a JSX element is a host element
|
|
550
|
+
* Host elements in React start with lowercase letters (e.g., div, span)
|
|
551
|
+
*
|
|
552
|
+
* @param context - ESLint rule context
|
|
553
|
+
* @param node - AST node to check
|
|
554
|
+
* @returns boolean indicating if the element is a host element
|
|
555
|
+
*/
|
|
556
|
+
declare function isHostElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Determines if a JSX element is a React Fragment
|
|
559
|
+
* Fragments can be imported from React and used like <Fragment> or <React.Fragment>
|
|
560
|
+
*
|
|
561
|
+
* @param context - ESLint rule context
|
|
562
|
+
* @param node - AST node to check
|
|
563
|
+
* @returns boolean indicating if the element is a Fragment with type narrowing
|
|
564
|
+
*/
|
|
565
|
+
declare function isFragmentElement(context: RuleContext, node: TSESTree.Node): node is TSESTree.JSXElement;
|
|
566
|
+
//#endregion
|
|
567
|
+
//#region src/jsx/jsx-element-type.d.ts
|
|
568
|
+
/**
|
|
569
|
+
* Extracts the element type name from a JSX element or fragment
|
|
570
|
+
* For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
|
|
571
|
+
* For JSX fragments, returns an empty string
|
|
572
|
+
*
|
|
573
|
+
* @param context - ESLint rule context
|
|
574
|
+
* @param node - JSX element or fragment node
|
|
575
|
+
* @returns String representation of the element type
|
|
462
576
|
*/
|
|
463
577
|
declare function getElementType(context: RuleContext, node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
464
|
-
|
|
578
|
+
//#endregion
|
|
579
|
+
//#region src/jsx/jsx-has.d.ts
|
|
580
|
+
/**
|
|
581
|
+
* Checks if a JSX element has a specific attribute
|
|
582
|
+
*
|
|
583
|
+
* @param context - ESLint rule context
|
|
584
|
+
* @param name - Name of the attribute to check for
|
|
585
|
+
* @param attributes - List of JSX attributes from opening element
|
|
586
|
+
* @param initialScope - Optional scope for resolving variables in spread attributes
|
|
587
|
+
* @returns boolean indicating whether the attribute exists
|
|
588
|
+
*/
|
|
465
589
|
declare function hasAttribute(context: RuleContext, name: string, attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
590
|
+
/**
|
|
591
|
+
* Checks if a JSX element has at least one of the specified attributes
|
|
592
|
+
*
|
|
593
|
+
* @param context - ESLint rule context
|
|
594
|
+
* @param names - Array of attribute names to check for
|
|
595
|
+
* @param attributes - List of JSX attributes from opening element
|
|
596
|
+
* @param initialScope - Optional scope for resolving variables in spread attributes
|
|
597
|
+
* @returns boolean indicating whether any of the attributes exist
|
|
598
|
+
*/
|
|
466
599
|
declare function hasAnyAttribute(context: RuleContext, names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
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
|
+
*/
|
|
467
609
|
declare function hasEveryAttribute(context: RuleContext, names: string[], attributes: TSESTree.JSXOpeningElement["attributes"], initialScope?: Scope): boolean;
|
|
468
|
-
|
|
610
|
+
//#endregion
|
|
611
|
+
//#region src/jsx/jsx-hierarchy.d.ts
|
|
469
612
|
/**
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
* @param
|
|
473
|
-
* @
|
|
613
|
+
* Traverses up the AST to find a parent JSX attribute node that matches a given test
|
|
614
|
+
*
|
|
615
|
+
* @param node - The starting AST node
|
|
616
|
+
* @param test - Optional predicate function to test if the attribute meets criteria
|
|
617
|
+
* Defaults to always returning true (matches any attribute)
|
|
618
|
+
* @returns The first matching JSX attribute node found when traversing upwards, or undefined
|
|
474
619
|
*/
|
|
475
|
-
declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute |
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
declare function isKeyedElement(context: RuleContext, node: TSESTree.Node, initialScope?: Scope): boolean;
|
|
479
|
-
declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | null | _, allowJSXFragment?: false): node is TSESTree.JSXElement;
|
|
480
|
-
declare function isFragmentElement(context: RuleContext, node: TSESTree.Node | null | _, allowJSXFragment?: true): node is TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
481
|
-
|
|
620
|
+
declare function findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | unit;
|
|
621
|
+
//#endregion
|
|
622
|
+
//#region src/jsx/jsx-stringify.d.ts
|
|
482
623
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
* @
|
|
624
|
+
* Incomplete but sufficient stringification of JSX nodes for common use cases
|
|
625
|
+
*
|
|
626
|
+
* @param node - JSX node from TypeScript ESTree
|
|
627
|
+
* @returns String representation of the JSX node
|
|
486
628
|
*/
|
|
487
|
-
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.
|
|
488
|
-
|
|
629
|
+
declare function stringifyJsx(node: TSESTree$1.JSXIdentifier | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXClosingElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXText): string;
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region src/type/type-is.d.ts
|
|
489
632
|
/** @internal */
|
|
490
|
-
declare
|
|
491
|
-
|
|
633
|
+
declare const isAnyType: (type: ts.Type) => boolean;
|
|
634
|
+
/** @internal */
|
|
635
|
+
declare const isBigIntType: (type: ts.Type) => boolean;
|
|
636
|
+
/** @internal */
|
|
637
|
+
declare const isBooleanType: (type: ts.Type) => boolean;
|
|
638
|
+
/** @internal */
|
|
639
|
+
declare const isEnumType: (type: ts.Type) => boolean;
|
|
640
|
+
/** @internal */
|
|
641
|
+
declare const isFalsyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
642
|
+
freshType: ts.FreshableType;
|
|
643
|
+
regularType: ts.FreshableType;
|
|
644
|
+
flags: ts.TypeFlags;
|
|
645
|
+
symbol: ts.Symbol;
|
|
646
|
+
pattern?: ts.DestructuringPattern;
|
|
647
|
+
aliasSymbol?: ts.Symbol;
|
|
648
|
+
aliasTypeArguments?: readonly ts.Type[];
|
|
649
|
+
getFlags: () => ts.TypeFlags;
|
|
650
|
+
getSymbol: () => ts.Symbol | undefined;
|
|
651
|
+
getProperties: () => ts.Symbol[];
|
|
652
|
+
getProperty: (propertyName: string) => ts.Symbol | undefined;
|
|
653
|
+
getApparentProperties: () => ts.Symbol[];
|
|
654
|
+
getCallSignatures: () => readonly ts.Signature[];
|
|
655
|
+
getConstructSignatures: () => readonly ts.Signature[];
|
|
656
|
+
getStringIndexType: () => ts.Type | undefined;
|
|
657
|
+
getNumberIndexType: () => ts.Type | undefined;
|
|
658
|
+
getBaseTypes: () => ts.BaseType[] | undefined;
|
|
659
|
+
getNonNullableType: () => ts.Type;
|
|
660
|
+
getConstraint: () => ts.Type | undefined;
|
|
661
|
+
getDefault: () => ts.Type | undefined;
|
|
662
|
+
isUnion: () => this is ts.UnionType;
|
|
663
|
+
isIntersection: () => this is ts.IntersectionType;
|
|
664
|
+
isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
|
|
665
|
+
isLiteral: () => this is ts.LiteralType;
|
|
666
|
+
isStringLiteral: () => this is ts.StringLiteralType;
|
|
667
|
+
isNumberLiteral: () => this is ts.NumberLiteralType;
|
|
668
|
+
isTypeParameter: () => this is ts.TypeParameter;
|
|
669
|
+
isClassOrInterface: () => this is ts.InterfaceType;
|
|
670
|
+
isClass: () => this is ts.InterfaceType;
|
|
671
|
+
isIndexType: () => this is ts.IndexType;
|
|
672
|
+
value: {
|
|
673
|
+
negative: boolean;
|
|
674
|
+
base10Value: "0";
|
|
675
|
+
};
|
|
676
|
+
};
|
|
677
|
+
/** @internal */
|
|
678
|
+
declare const isFalsyNumberType: (type: ts.Type) => boolean;
|
|
679
|
+
/** @internal */
|
|
680
|
+
declare const isFalsyStringType: (type: ts.Type) => boolean;
|
|
681
|
+
/** @internal */
|
|
682
|
+
declare const isNeverType: (type: ts.Type) => boolean;
|
|
683
|
+
/** @internal */
|
|
684
|
+
declare const isNullishType: (type: ts.Type) => boolean;
|
|
685
|
+
/** @internal */
|
|
686
|
+
declare const isNumberType: (type: ts.Type) => boolean;
|
|
687
|
+
/** @internal */
|
|
688
|
+
declare const isObjectType: (type: ts.Type) => boolean;
|
|
689
|
+
/** @internal */
|
|
690
|
+
declare const isStringType: (type: ts.Type) => boolean;
|
|
691
|
+
/** @internal */
|
|
692
|
+
declare const isTruthyBigIntType: (type: ts.Type) => type is ts.LiteralType & {
|
|
693
|
+
freshType: ts.FreshableType;
|
|
694
|
+
regularType: ts.FreshableType;
|
|
695
|
+
flags: ts.TypeFlags;
|
|
696
|
+
symbol: ts.Symbol;
|
|
697
|
+
pattern?: ts.DestructuringPattern;
|
|
698
|
+
aliasSymbol?: ts.Symbol;
|
|
699
|
+
aliasTypeArguments?: readonly ts.Type[];
|
|
700
|
+
getFlags: () => ts.TypeFlags;
|
|
701
|
+
getSymbol: () => ts.Symbol | undefined;
|
|
702
|
+
getProperties: () => ts.Symbol[];
|
|
703
|
+
getProperty: (propertyName: string) => ts.Symbol | undefined;
|
|
704
|
+
getApparentProperties: () => ts.Symbol[];
|
|
705
|
+
getCallSignatures: () => readonly ts.Signature[];
|
|
706
|
+
getConstructSignatures: () => readonly ts.Signature[];
|
|
707
|
+
getStringIndexType: () => ts.Type | undefined;
|
|
708
|
+
getNumberIndexType: () => ts.Type | undefined;
|
|
709
|
+
getBaseTypes: () => ts.BaseType[] | undefined;
|
|
710
|
+
getNonNullableType: () => ts.Type;
|
|
711
|
+
getConstraint: () => ts.Type | undefined;
|
|
712
|
+
getDefault: () => ts.Type | undefined;
|
|
713
|
+
isUnion: () => this is ts.UnionType;
|
|
714
|
+
isIntersection: () => this is ts.IntersectionType;
|
|
715
|
+
isUnionOrIntersection: () => this is ts.UnionOrIntersectionType;
|
|
716
|
+
isLiteral: () => this is ts.LiteralType;
|
|
717
|
+
isStringLiteral: () => this is ts.StringLiteralType;
|
|
718
|
+
isNumberLiteral: () => this is ts.NumberLiteralType;
|
|
719
|
+
isTypeParameter: () => this is ts.TypeParameter;
|
|
720
|
+
isClassOrInterface: () => this is ts.InterfaceType;
|
|
721
|
+
isClass: () => this is ts.InterfaceType;
|
|
722
|
+
isIndexType: () => this is ts.IndexType;
|
|
723
|
+
value: ts.PseudoBigInt;
|
|
724
|
+
};
|
|
725
|
+
/** @internal */
|
|
726
|
+
declare const isTruthyNumberType: (type: ts.Type) => boolean;
|
|
727
|
+
/** @internal */
|
|
728
|
+
declare const isTruthyStringType: (type: ts.Type) => boolean;
|
|
729
|
+
/** @internal */
|
|
730
|
+
declare const isUnknownType: (type: ts.Type) => boolean;
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/type/type-variant.d.ts
|
|
733
|
+
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";
|
|
734
|
+
/**
|
|
735
|
+
* Ported from https://github.com/typescript-eslint/typescript-eslint/blob/eb736bbfc22554694400e6a4f97051d845d32e0b/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts#L826 with some enhancements
|
|
736
|
+
* Get the variants of an array of types.
|
|
737
|
+
* @param types The types to get the variants of
|
|
738
|
+
* @returns The variants of the types
|
|
739
|
+
* @internal
|
|
740
|
+
*/
|
|
741
|
+
declare function getTypeVariants(types: ts.Type[]): Set<TypeVariant>;
|
|
742
|
+
//#endregion
|
|
743
|
+
//#region src/utils/get-instance-id.d.ts
|
|
744
|
+
/**
|
|
745
|
+
* Gets the identifier node of an instance based on AST node relationships.
|
|
746
|
+
* Used for tracking where hooks or components are being assigned in the code.
|
|
747
|
+
* @param node The current AST node to evaluate
|
|
748
|
+
* @param prev The previous AST node in the traversal (used for context)
|
|
749
|
+
* @internal
|
|
750
|
+
*/
|
|
751
|
+
declare function getInstanceId(node: TSESTree.Node, prev?: TSESTree.Node): TSESTree.JSXElement | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.BinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXFragment | 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.UnaryExpression | TSESTree.UpdateExpression | TSESTree.YieldExpression | TSESTree.PrivateIdentifier | undefined;
|
|
752
|
+
//#endregion
|
|
753
|
+
//#region src/utils/is-from-react.d.ts
|
|
492
754
|
/**
|
|
493
|
-
* Check if an identifier is initialized from react
|
|
755
|
+
* Check if an identifier name is initialized from react
|
|
494
756
|
* @param name The top-level identifier's name
|
|
495
757
|
* @param importSource The import source to check against
|
|
496
758
|
* @param initialScope Initial scope to search for the identifier
|
|
497
|
-
* @returns Whether the identifier is initialized from react
|
|
759
|
+
* @returns Whether the identifier name is initialized from react
|
|
760
|
+
* @internal
|
|
498
761
|
*/
|
|
499
762
|
declare function isInitializedFromReact(name: string, importSource: string, initialScope: Scope): boolean;
|
|
500
|
-
|
|
763
|
+
//#endregion
|
|
764
|
+
//#region src/utils/is-instance-id-equal.d.ts
|
|
501
765
|
/** @internal */
|
|
502
766
|
declare function isInstanceIdEqual(context: RuleContext, a: TSESTree.Node, b: TSESTree.Node): boolean;
|
|
503
|
-
|
|
767
|
+
//#endregion
|
|
768
|
+
//#region src/utils/is-react-api.d.ts
|
|
504
769
|
declare namespace isReactAPI {
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
770
|
+
type ReturnType = {
|
|
771
|
+
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
772
|
+
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
|
|
773
|
+
};
|
|
509
774
|
}
|
|
510
775
|
declare function isReactAPI(api: string): isReactAPI.ReturnType;
|
|
511
776
|
declare namespace isReactAPICall {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
777
|
+
type ReturnType = {
|
|
778
|
+
(context: RuleContext, node: unit | null | TSESTree.Node): node is TSESTree.CallExpression;
|
|
779
|
+
(context: RuleContext): (node: unit | null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
780
|
+
};
|
|
516
781
|
}
|
|
517
782
|
declare function isReactAPICall(api: string): isReactAPICall.ReturnType;
|
|
518
783
|
declare const isCaptureOwnerStack: isReactAPI.ReturnType;
|
|
@@ -541,5 +806,5 @@ declare const isCreateRefCall: isReactAPICall.ReturnType;
|
|
|
541
806
|
declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
542
807
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
543
808
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
544
|
-
|
|
545
|
-
export {
|
|
809
|
+
//#endregion
|
|
810
|
+
export { AttributeValue, ClassComponent, Component, ComponentDetectionHint, ComponentEffectPhaseKind, ComponentFlag, ComponentKind, ComponentLifecyclePhaseKind, ComponentPhaseKind, ComponentPhaseRelevance, ComponentStateKind, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, EffectKind, FunctionComponent, Hook, JSXDetectionHint, REACT_BUILTIN_HOOK_NAMES, SemanticEntry, SemanticNode, TypeVariant, findParentAttribute, getAttribute, getAttributeName, getComponentFlagFromInitPath, getComponentNameFromId, getElementType, getFunctionComponentId, getInstanceId, getTypeVariants, hasAnyAttribute, hasAttribute, hasEveryAttribute, hasNoneOrLooseComponentName, isAnyType, isAssignmentToThisState, isBigIntType, isBooleanType, 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, isEnumType, isFalseLiteralType, isFalsyBigIntType, isFalsyNumberType, isFalsyStringType, isForwardRef, isForwardRefCall, isFragmentElement, isFunctionOfRenderMethod, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHostElement, isInitializedFromReact, isInstanceIdEqual, isInversePhase, isJsxLike, isJsxText, isLazy, isLazyCall, isMemo, isMemoCall, isNeverType, isNullishType, isNumberType, isObjectType, isPureComponent, isReactAPI, isReactAPICall, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookId, isReactHookName, isRender, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isShouldComponentUpdate, isStringType, isThisSetState, isTrueLiteralType, isTruthyBigIntType, isTruthyNumberType, isTruthyStringType, isUnknownType, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, resolveAttributeValue, stringifyJsx, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|