.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @typescript-eslint / experimental-utils / _ts3.4 / dist / ts-eslint / SourceCode.d.ts
1 import { ParserServices, TSESTree } from '../ts-estree';\r
2 import { Scope } from './Scope';\r
3 declare class TokenStore {\r
4     /**\r
5      * Checks whether any comments exist or not between the given 2 nodes.\r
6      * @param left The node to check.\r
7      * @param right The node to check.\r
8      * @returns `true` if one or more comments exist.\r
9      */\r
10     commentsExistBetween(left: TSESTree.Node | TSESTree.Token, right: TSESTree.Node | TSESTree.Token): boolean;\r
11     /**\r
12      * Gets all comment tokens directly after the given node or token.\r
13      * @param nodeOrToken The AST node or token to check for adjacent comment tokens.\r
14      * @returns An array of comments in occurrence order.\r
15      */\r
16     getCommentsAfter(nodeOrToken: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];\r
17     /**\r
18      * Gets all comment tokens directly before the given node or token.\r
19      * @param nodeOrToken The AST node or token to check for adjacent comment tokens.\r
20      * @returns An array of comments in occurrence order.\r
21      */\r
22     getCommentsBefore(nodeOrToken: TSESTree.Node | TSESTree.Token): TSESTree.Comment[];\r
23     /**\r
24      * Gets all comment tokens inside the given node.\r
25      * @param node The AST node to get the comments for.\r
26      * @returns An array of comments in occurrence order.\r
27      */\r
28     getCommentsInside(node: TSESTree.Node): TSESTree.Comment[];\r
29     /**\r
30      * Gets the first token of the given node.\r
31      * @param node The AST node.\r
32      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
33      * @returns An object representing the token.\r
34      */\r
35     getFirstToken<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
36     /**\r
37      * Gets the first token between two non-overlapping nodes.\r
38      * @param left Node before the desired token range.\r
39      * @param right Node after the desired token range.\r
40      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
41      * @returns An object representing the token.\r
42      */\r
43     getFirstTokenBetween<T extends SourceCode.CursorWithSkipOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
44     /**\r
45      * Gets the first `count` tokens of the given node.\r
46      * @param node The AST node.\r
47      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
48      * @returns Tokens.\r
49      */\r
50     getFirstTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
51     /**\r
52      * Gets the first `count` tokens between two non-overlapping nodes.\r
53      * @param left Node before the desired token range.\r
54      * @param right Node after the desired token range.\r
55      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
56      * @returns Tokens between left and right.\r
57      */\r
58     getFirstTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
59     /**\r
60      * Gets the last token of the given node.\r
61      * @param node The AST node.\r
62      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
63      * @returns An object representing the token.\r
64      */\r
65     getLastToken<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
66     /**\r
67      * Gets the last token between two non-overlapping nodes.\r
68      * @param left Node before the desired token range.\r
69      * @param right Node after the desired token range.\r
70      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
71      * @returns An object representing the token.\r
72      */\r
73     getLastTokenBetween<T extends SourceCode.CursorWithSkipOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
74     /**\r
75      * Gets the last `count` tokens of the given node.\r
76      * @param node The AST node.\r
77      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
78      * @returns Tokens.\r
79      */\r
80     getLastTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
81     /**\r
82      * Gets the last `count` tokens between two non-overlapping nodes.\r
83      * @param left Node before the desired token range.\r
84      * @param right Node after the desired token range.\r
85      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
86      * @returns Tokens between left and right.\r
87      */\r
88     getLastTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
89     /**\r
90      * Gets the token that follows a given node or token.\r
91      * @param node The AST node or token.\r
92      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
93      * @returns An object representing the token.\r
94      */\r
95     getTokenAfter<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
96     /**\r
97      * Gets the token that precedes a given node or token.\r
98      * @param node The AST node or token.\r
99      * @param options The option object\r
100      * @returns An object representing the token.\r
101      */\r
102     getTokenBefore<T extends SourceCode.CursorWithSkipOptions>(node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
103     /**\r
104      * Gets the token starting at the specified index.\r
105      * @param offset Index of the start of the token's range.\r
106      * @param option The option object. If this is a number then it's `options.skip`. If this is a function then it's `options.filter`.\r
107      * @returns The token starting at index, or null if no such token.\r
108      */\r
109     getTokenByRangeStart<T extends {\r
110         includeComments?: boolean;\r
111     }>(offset: number, options?: T): SourceCode.ReturnTypeFromOptions<T> | null;\r
112     /**\r
113      * Gets all tokens that are related to the given node.\r
114      * @param node The AST node.\r
115      * @param beforeCount The number of tokens before the node to retrieve.\r
116      * @param afterCount The number of tokens after the node to retrieve.\r
117      * @returns Array of objects representing tokens.\r
118      */\r
119     getTokens(node: TSESTree.Node, beforeCount?: number, afterCount?: number): TSESTree.Token[];\r
120     /**\r
121      * Gets all tokens that are related to the given node.\r
122      * @param node The AST node.\r
123      * @param options The option object. If this is a function then it's `options.filter`.\r
124      * @returns Array of objects representing tokens.\r
125      */\r
126     getTokens<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node, options: T): SourceCode.ReturnTypeFromOptions<T>[];\r
127     /**\r
128      * Gets the `count` tokens that follows a given node or token.\r
129      * @param node The AST node.\r
130      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
131      * @returns Tokens.\r
132      */\r
133     getTokensAfter<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
134     /**\r
135      * Gets the `count` tokens that precedes a given node or token.\r
136      * @param node The AST node.\r
137      * @param options The option object. If this is a number then it's `options.count`. If this is a function then it's `options.filter`.\r
138      * @returns Tokens.\r
139      */\r
140     getTokensBefore<T extends SourceCode.CursorWithCountOptions>(node: TSESTree.Node | TSESTree.Token | TSESTree.Comment, options?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
141     /**\r
142      * Gets all of the tokens between two non-overlapping nodes.\r
143      * @param left Node before the desired token range.\r
144      * @param right Node after the desired token range.\r
145      * @param options The option object. If this is a function then it's `options.filter`.\r
146      * @returns Tokens between left and right.\r
147      */\r
148     getTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, padding?: T): SourceCode.ReturnTypeFromOptions<T>[];\r
149     /**\r
150      * Gets all of the tokens between two non-overlapping nodes.\r
151      * @param left Node before the desired token range.\r
152      * @param right Node after the desired token range.\r
153      * @param padding Number of extra tokens on either side of center.\r
154      * @returns Tokens between left and right.\r
155      */\r
156     getTokensBetween<T extends SourceCode.CursorWithCountOptions>(left: TSESTree.Node | TSESTree.Token | TSESTree.Comment, right: TSESTree.Node | TSESTree.Token | TSESTree.Comment, padding?: number): SourceCode.ReturnTypeFromOptions<T>[];\r
157 }\r
158 declare class SourceCodeBase extends TokenStore {\r
159     /**\r
160      * Represents parsed source code.\r
161      * @param text The source code text.\r
162      * @param ast The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.\r
163      */\r
164     constructor(text: string, ast: SourceCode.Program);\r
165     /**\r
166      * Represents parsed source code.\r
167      * @param config The config object.\r
168      */\r
169     constructor(config: SourceCode.SourceCodeConfig);\r
170     /**\r
171      * The parsed AST for the source code.\r
172      */\r
173     ast: SourceCode.Program;\r
174     /**\r
175      * Retrieves an array containing all comments in the source code.\r
176      * @returns An array of comment nodes.\r
177      */\r
178     getAllComments(): TSESTree.Comment[];\r
179     /**\r
180      * Gets all comments for the given node.\r
181      * @param node The AST node to get the comments for.\r
182      * @returns An object containing a leading and trailing array of comments indexed by their position.\r
183      */\r
184     getComments(node: TSESTree.Node): {\r
185         leading: TSESTree.Comment[];\r
186         trailing: TSESTree.Comment[];\r
187     };\r
188     /**\r
189      * Converts a (line, column) pair into a range index.\r
190      * @param loc A line/column location\r
191      * @returns The range index of the location in the file.\r
192      */\r
193     getIndexFromLoc(location: TSESTree.LineAndColumnData): number;\r
194     /**\r
195      * Gets the entire source text split into an array of lines.\r
196      * @returns The source text as an array of lines.\r
197      */\r
198     getLines(): string[];\r
199     /**\r
200      * Converts a source text index into a (line, column) pair.\r
201      * @param index The index of a character in a file\r
202      * @returns A {line, column} location object with a 0-indexed column\r
203      */\r
204     getLocFromIndex(index: number): TSESTree.LineAndColumnData;\r
205     /**\r
206      * Gets the deepest node containing a range index.\r
207      * @param index Range index of the desired node.\r
208      * @returns The node if found or `null` if not found.\r
209      */\r
210     getNodeByRangeIndex(index: number): TSESTree.Node | null;\r
211     /**\r
212      * Gets the source code for the given node.\r
213      * @param node The AST node to get the text for.\r
214      * @param beforeCount The number of characters before the node to retrieve.\r
215      * @param afterCount The number of characters after the node to retrieve.\r
216      * @returns The text representing the AST node.\r
217      */\r
218     getText(node?: TSESTree.Node, beforeCount?: number, afterCount?: number): string;\r
219     /**\r
220      * The flag to indicate that the source code has Unicode BOM.\r
221      */\r
222     hasBOM: boolean;\r
223     /**\r
224      * Determines if two nodes or tokens have at least one whitespace character\r
225      * between them. Order does not matter. Returns false if the given nodes or\r
226      * tokens overlap.\r
227      * This was added in v6.7.0.\r
228      * @since 6.7.0\r
229      * @param first The first node or token to check between.\r
230      * @param second The second node or token to check between.\r
231      * @returns True if there is a whitespace character between any of the tokens found between the two given nodes or tokens.\r
232      */\r
233     isSpaceBetween?(first: TSESTree.Token | TSESTree.Comment | TSESTree.Node, second: TSESTree.Token | TSESTree.Comment | TSESTree.Node): boolean;\r
234     /**\r
235      * Determines if two nodes or tokens have at least one whitespace character\r
236      * between them. Order does not matter. Returns false if the given nodes or\r
237      * tokens overlap.\r
238      * For backward compatibility, this method returns true if there are\r
239      * `JSXText` tokens that contain whitespace between the two.\r
240      * @param first The first node or token to check between.\r
241      * @param second The second node or token to check between.\r
242      * @returns {boolean} True if there is a whitespace character between\r
243      * any of the tokens found between the two given nodes or tokens.\r
244      * @deprecated in favor of isSpaceBetween\r
245      */\r
246     isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean;\r
247     /**\r
248      * The source code split into lines according to ECMA-262 specification.\r
249      * This is done to avoid each rule needing to do so separately.\r
250      */\r
251     lines: string[];\r
252     /**\r
253      * The indexes in `text` that each line starts\r
254      */\r
255     lineStartIndices: number[];\r
256     /**\r
257      * The parser services of this source code.\r
258      */\r
259     parserServices: ParserServices;\r
260     /**\r
261      * The scope of this source code.\r
262      */\r
263     scopeManager: Scope.ScopeManager | null;\r
264     /**\r
265      * The original text source code. BOM was stripped from this text.\r
266      */\r
267     text: string;\r
268     /**\r
269      * All of the tokens and comments in the AST.\r
270      */\r
271     tokensAndComments: (TSESTree.Comment | TSESTree.Token)[];\r
272     /**\r
273      * The visitor keys to traverse AST.\r
274      */\r
275     visitorKeys: SourceCode.VisitorKeys;\r
276     /**\r
277      * Split the source code into multiple lines based on the line delimiters.\r
278      * @param text Source code as a string.\r
279      * @returns Array of source code lines.\r
280      */\r
281     static splitLines(text: string): string[];\r
282 }\r
283 declare namespace SourceCode {\r
284     interface Program extends TSESTree.Program {\r
285         comments: TSESTree.Comment[];\r
286         tokens: TSESTree.Token[];\r
287     }\r
288     interface SourceCodeConfig {\r
289         /**\r
290          * The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.\r
291          */\r
292         ast: Program;\r
293         /**\r
294          * The parser services.\r
295          */\r
296         parserServices: ParserServices | null;\r
297         /**\r
298          * The scope of this source code.\r
299          */\r
300         scopeManager: Scope.ScopeManager | null;\r
301         /**\r
302          * The source code text.\r
303          */\r
304         text: string;\r
305         /**\r
306          * The visitor keys to traverse AST.\r
307          */\r
308         visitorKeys: VisitorKeys | null;\r
309     }\r
310     interface VisitorKeys {\r
311         [nodeType: string]: string[];\r
312     }\r
313     type FilterPredicate = (tokenOrComment: TSESTree.Token | TSESTree.Comment) => boolean;\r
314     type ReturnTypeFromOptions<T> = T extends {\r
315         includeComments: true;\r
316     } ? TSESTree.Token : Exclude<TSESTree.Token, TSESTree.Comment>;\r
317     type CursorWithSkipOptions = number | FilterPredicate | {\r
318         /**\r
319          * The predicate function to choose tokens.\r
320          */\r
321         filter?: FilterPredicate;\r
322         /**\r
323          * The flag to iterate comments as well.\r
324          */\r
325         includeComments?: boolean;\r
326         /**\r
327          * The count of tokens the cursor skips.\r
328          */\r
329         skip?: number;\r
330     };\r
331     type CursorWithCountOptions = number | FilterPredicate | {\r
332         /**\r
333          * The predicate function to choose tokens.\r
334          */\r
335         filter?: FilterPredicate;\r
336         /**\r
337          * The flag to iterate comments as well.\r
338          */\r
339         includeComments?: boolean;\r
340         /**\r
341          * The maximum count of tokens the cursor iterates.\r
342          */\r
343         count?: number;\r
344     };\r
345 }\r
346 declare const SourceCode_base: typeof SourceCodeBase;\r
347 declare class SourceCode extends SourceCode_base {\r
348 }\r
349 export { SourceCode };\r
350 //# sourceMappingURL=SourceCode.d.ts.map\r