UNPKG

51.4 kBTypeScriptView Raw
1// Type definitions for eslint 8.40
2// Project: https://eslint.org
3// Definitions by: Pierre-Marie Dartus <https://github.com/pmdartus>
4// Jed Fox <https://github.com/j-f1>
5// Saad Quadri <https://github.com/saadq>
6// Jason Kwok <https://github.com/JasonHK>
7// Brad Zacher <https://github.com/bradzacher>
8// JounQin <https://github.com/JounQin>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
11/// <reference path="helpers.d.ts" />
12
13import * as ESTree from "estree";
14import { JSONSchema4 } from "json-schema";
15
16export namespace AST {
17 type TokenType =
18 | "Boolean"
19 | "Null"
20 | "Identifier"
21 | "Keyword"
22 | "Punctuator"
23 | "JSXIdentifier"
24 | "JSXText"
25 | "Numeric"
26 | "String"
27 | "RegularExpression";
28
29 interface Token {
30 type: TokenType;
31 value: string;
32 range: Range;
33 loc: SourceLocation;
34 }
35
36 interface SourceLocation {
37 start: ESTree.Position;
38 end: ESTree.Position;
39 }
40
41 type Range = [number, number];
42
43 interface Program extends ESTree.Program {
44 comments: ESTree.Comment[];
45 tokens: Token[];
46 loc: SourceLocation;
47 range: Range;
48 }
49}
50
51export namespace Scope {
52 interface ScopeManager {
53 scopes: Scope[];
54 globalScope: Scope | null;
55
56 acquire(node: ESTree.Node, inner?: boolean): Scope | null;
57
58 getDeclaredVariables(node: ESTree.Node): Variable[];
59 }
60
61 interface Scope {
62 type:
63 | "block"
64 | "catch"
65 | "class"
66 | "for"
67 | "function"
68 | "function-expression-name"
69 | "global"
70 | "module"
71 | "switch"
72 | "with"
73 | "TDZ";
74 isStrict: boolean;
75 upper: Scope | null;
76 childScopes: Scope[];
77 variableScope: Scope;
78 block: ESTree.Node;
79 variables: Variable[];
80 set: Map<string, Variable>;
81 references: Reference[];
82 through: Reference[];
83 functionExpressionScope: boolean;
84 }
85
86 interface Variable {
87 name: string;
88 scope: Scope;
89 identifiers: ESTree.Identifier[];
90 references: Reference[];
91 defs: Definition[];
92 }
93
94 interface Reference {
95 identifier: ESTree.Identifier;
96 from: Scope;
97 resolved: Variable | null;
98 writeExpr: ESTree.Node | null;
99 init: boolean;
100
101 isWrite(): boolean;
102
103 isRead(): boolean;
104
105 isWriteOnly(): boolean;
106
107 isReadOnly(): boolean;
108
109 isReadWrite(): boolean;
110 }
111
112 type DefinitionType =
113 | { type: "CatchClause"; node: ESTree.CatchClause; parent: null }
114 | { type: "ClassName"; node: ESTree.ClassDeclaration | ESTree.ClassExpression; parent: null }
115 | { type: "FunctionName"; node: ESTree.FunctionDeclaration | ESTree.FunctionExpression; parent: null }
116 | { type: "ImplicitGlobalVariable"; node: ESTree.Program; parent: null }
117 | {
118 type: "ImportBinding";
119 node: ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier;
120 parent: ESTree.ImportDeclaration;
121 }
122 | {
123 type: "Parameter";
124 node: ESTree.FunctionDeclaration | ESTree.FunctionExpression | ESTree.ArrowFunctionExpression;
125 parent: null;
126 }
127 | { type: "TDZ"; node: any; parent: null }
128 | { type: "Variable"; node: ESTree.VariableDeclarator; parent: ESTree.VariableDeclaration };
129
130 type Definition = DefinitionType & { name: ESTree.Identifier };
131}
132
133//#region SourceCode
134
135export class SourceCode {
136 text: string;
137 ast: AST.Program;
138 lines: string[];
139 hasBOM: boolean;
140 parserServices: SourceCode.ParserServices;
141 scopeManager: Scope.ScopeManager;
142 visitorKeys: SourceCode.VisitorKeys;
143
144 constructor(text: string, ast: AST.Program);
145 constructor(config: SourceCode.Config);
146
147 static splitLines(text: string): string[];
148
149 getText(node?: ESTree.Node, beforeCount?: number, afterCount?: number): string;
150
151 getLines(): string[];
152
153 getAllComments(): ESTree.Comment[];
154
155 getComments(node: ESTree.Node): { leading: ESTree.Comment[]; trailing: ESTree.Comment[] };
156
157 getJSDocComment(node: ESTree.Node): ESTree.Comment | null;
158
159 getNodeByRangeIndex(index: number): ESTree.Node | null;
160
161 isSpaceBetweenTokens(first: AST.Token, second: AST.Token): boolean;
162
163 getLocFromIndex(index: number): ESTree.Position;
164
165 getIndexFromLoc(location: ESTree.Position): number;
166
167 // Inherited methods from TokenStore
168 // ---------------------------------
169
170 getTokenByRangeStart(offset: number, options?: { includeComments: false }): AST.Token | null;
171 getTokenByRangeStart(offset: number, options: { includeComments: boolean }): AST.Token | ESTree.Comment | null;
172
173 getFirstToken: SourceCode.UnaryNodeCursorWithSkipOptions;
174
175 getFirstTokens: SourceCode.UnaryNodeCursorWithCountOptions;
176
177 getLastToken: SourceCode.UnaryNodeCursorWithSkipOptions;
178
179 getLastTokens: SourceCode.UnaryNodeCursorWithCountOptions;
180
181 getTokenBefore: SourceCode.UnaryCursorWithSkipOptions;
182
183 getTokensBefore: SourceCode.UnaryCursorWithCountOptions;
184
185 getTokenAfter: SourceCode.UnaryCursorWithSkipOptions;
186
187 getTokensAfter: SourceCode.UnaryCursorWithCountOptions;
188
189 getFirstTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
190
191 getFirstTokensBetween: SourceCode.BinaryCursorWithCountOptions;
192
193 getLastTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
194
195 getLastTokensBetween: SourceCode.BinaryCursorWithCountOptions;
196
197 getTokensBetween: SourceCode.BinaryCursorWithCountOptions;
198
199 getTokens: ((node: ESTree.Node, beforeCount?: number, afterCount?: number) => AST.Token[]) &
200 SourceCode.UnaryNodeCursorWithCountOptions;
201
202 commentsExistBetween(
203 left: ESTree.Node | AST.Token | ESTree.Comment,
204 right: ESTree.Node | AST.Token | ESTree.Comment,
205 ): boolean;
206
207 getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
208
209 getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
210
211 getCommentsInside(node: ESTree.Node): ESTree.Comment[];
212
213 getScope(node: ESTree.Node): Scope.Scope;
214}
215
216export namespace SourceCode {
217 interface Config {
218 text: string;
219 ast: AST.Program;
220 parserServices?: ParserServices | undefined;
221 scopeManager?: Scope.ScopeManager | undefined;
222 visitorKeys?: VisitorKeys | undefined;
223 }
224
225 type ParserServices = any;
226
227 interface VisitorKeys {
228 [nodeType: string]: string[];
229 }
230
231 interface UnaryNodeCursorWithSkipOptions {
232 <T extends AST.Token>(
233 node: ESTree.Node,
234 options:
235 | ((token: AST.Token) => token is T)
236 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
237 ): T | null;
238 <T extends AST.Token | ESTree.Comment>(
239 node: ESTree.Node,
240 options: {
241 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
242 includeComments: boolean;
243 skip?: number | undefined;
244 },
245 ): T | null;
246 (
247 node: ESTree.Node,
248 options?:
249 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
250 | ((token: AST.Token) => boolean)
251 | number,
252 ): AST.Token | null;
253 (
254 node: ESTree.Node,
255 options: {
256 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
257 includeComments: boolean;
258 skip?: number | undefined;
259 },
260 ): AST.Token | ESTree.Comment | null;
261 }
262
263 interface UnaryNodeCursorWithCountOptions {
264 <T extends AST.Token>(
265 node: ESTree.Node,
266 options:
267 | ((token: AST.Token) => token is T)
268 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
269 ): T[];
270 <T extends AST.Token | ESTree.Comment>(
271 node: ESTree.Node,
272 options: {
273 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
274 includeComments: boolean;
275 count?: number | undefined;
276 },
277 ): T[];
278 (
279 node: ESTree.Node,
280 options?:
281 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
282 | ((token: AST.Token) => boolean)
283 | number,
284 ): AST.Token[];
285 (
286 node: ESTree.Node,
287 options: {
288 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
289 includeComments: boolean;
290 count?: number | undefined;
291 },
292 ): Array<AST.Token | ESTree.Comment>;
293 }
294
295 interface UnaryCursorWithSkipOptions {
296 <T extends AST.Token>(
297 node: ESTree.Node | AST.Token | ESTree.Comment,
298 options:
299 | ((token: AST.Token) => token is T)
300 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
301 ): T | null;
302 <T extends AST.Token | ESTree.Comment>(
303 node: ESTree.Node | AST.Token | ESTree.Comment,
304 options: {
305 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
306 includeComments: boolean;
307 skip?: number | undefined;
308 },
309 ): T | null;
310 (
311 node: ESTree.Node | AST.Token | ESTree.Comment,
312 options?:
313 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
314 | ((token: AST.Token) => boolean)
315 | number,
316 ): AST.Token | null;
317 (
318 node: ESTree.Node | AST.Token | ESTree.Comment,
319 options: {
320 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
321 includeComments: boolean;
322 skip?: number | undefined;
323 },
324 ): AST.Token | ESTree.Comment | null;
325 }
326
327 interface UnaryCursorWithCountOptions {
328 <T extends AST.Token>(
329 node: ESTree.Node | AST.Token | ESTree.Comment,
330 options:
331 | ((token: AST.Token) => token is T)
332 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
333 ): T[];
334 <T extends AST.Token | ESTree.Comment>(
335 node: ESTree.Node | AST.Token | ESTree.Comment,
336 options: {
337 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
338 includeComments: boolean;
339 count?: number | undefined;
340 },
341 ): T[];
342 (
343 node: ESTree.Node | AST.Token | ESTree.Comment,
344 options?:
345 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
346 | ((token: AST.Token) => boolean)
347 | number,
348 ): AST.Token[];
349 (
350 node: ESTree.Node | AST.Token | ESTree.Comment,
351 options: {
352 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
353 includeComments: boolean;
354 count?: number | undefined;
355 },
356 ): Array<AST.Token | ESTree.Comment>;
357 }
358
359 interface BinaryCursorWithSkipOptions {
360 <T extends AST.Token>(
361 left: ESTree.Node | AST.Token | ESTree.Comment,
362 right: ESTree.Node | AST.Token | ESTree.Comment,
363 options:
364 | ((token: AST.Token) => token is T)
365 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
366 ): T | null;
367 <T extends AST.Token | ESTree.Comment>(
368 left: ESTree.Node | AST.Token | ESTree.Comment,
369 right: ESTree.Node | AST.Token | ESTree.Comment,
370 options: {
371 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
372 includeComments: boolean;
373 skip?: number | undefined;
374 },
375 ): T | null;
376 (
377 left: ESTree.Node | AST.Token | ESTree.Comment,
378 right: ESTree.Node | AST.Token | ESTree.Comment,
379 options?:
380 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
381 | ((token: AST.Token) => boolean)
382 | number,
383 ): AST.Token | null;
384 (
385 left: ESTree.Node | AST.Token | ESTree.Comment,
386 right: ESTree.Node | AST.Token | ESTree.Comment,
387 options: {
388 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
389 includeComments: boolean;
390 skip?: number | undefined;
391 },
392 ): AST.Token | ESTree.Comment | null;
393 }
394
395 interface BinaryCursorWithCountOptions {
396 <T extends AST.Token>(
397 left: ESTree.Node | AST.Token | ESTree.Comment,
398 right: ESTree.Node | AST.Token | ESTree.Comment,
399 options:
400 | ((token: AST.Token) => token is T)
401 | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
402 ): T[];
403 <T extends AST.Token | ESTree.Comment>(
404 left: ESTree.Node | AST.Token | ESTree.Comment,
405 right: ESTree.Node | AST.Token | ESTree.Comment,
406 options: {
407 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
408 includeComments: boolean;
409 count?: number | undefined;
410 },
411 ): T[];
412 (
413 left: ESTree.Node | AST.Token | ESTree.Comment,
414 right: ESTree.Node | AST.Token | ESTree.Comment,
415 options?:
416 | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
417 | ((token: AST.Token) => boolean)
418 | number,
419 ): AST.Token[];
420 (
421 left: ESTree.Node | AST.Token | ESTree.Comment,
422 right: ESTree.Node | AST.Token | ESTree.Comment,
423 options: {
424 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
425 includeComments: boolean;
426 count?: number | undefined;
427 },
428 ): Array<AST.Token | ESTree.Comment>;
429 }
430}
431
432//#endregion
433
434export namespace Rule {
435 interface RuleModule {
436 create(context: RuleContext): RuleListener;
437 meta?: RuleMetaData | undefined;
438 }
439
440 type NodeTypes = ESTree.Node["type"];
441 interface NodeListener {
442 ArrayExpression?: ((node: ESTree.ArrayExpression & NodeParentExtension) => void) | undefined;
443 "ArrayExpression:exit"?: ((node: ESTree.ArrayExpression & NodeParentExtension) => void) | undefined;
444 ArrayPattern?: ((node: ESTree.ArrayPattern & NodeParentExtension) => void) | undefined;
445 "ArrayPattern:exit"?: ((node: ESTree.ArrayPattern & NodeParentExtension) => void) | undefined;
446 ArrowFunctionExpression?: ((node: ESTree.ArrowFunctionExpression & NodeParentExtension) => void) | undefined;
447 "ArrowFunctionExpression:exit"?: ((node: ESTree.ArrowFunctionExpression & NodeParentExtension) => void) | undefined;
448 AssignmentExpression?: ((node: ESTree.AssignmentExpression & NodeParentExtension) => void) | undefined;
449 "AssignmentExpression:exit"?: ((node: ESTree.AssignmentExpression & NodeParentExtension) => void) | undefined;
450 AssignmentPattern?: ((node: ESTree.AssignmentPattern & NodeParentExtension) => void) | undefined;
451 "AssignmentPattern:exit"?: ((node: ESTree.AssignmentPattern & NodeParentExtension) => void) | undefined;
452 AwaitExpression?: ((node: ESTree.AwaitExpression & NodeParentExtension) => void) | undefined;
453 "AwaitExpression:exit"?: ((node: ESTree.AwaitExpression & NodeParentExtension) => void) | undefined;
454 BinaryExpression?: ((node: ESTree.BinaryExpression & NodeParentExtension) => void) | undefined;
455 "BinaryExpression:exit"?: ((node: ESTree.BinaryExpression & NodeParentExtension) => void) | undefined;
456 BlockStatement?: ((node: ESTree.BlockStatement & NodeParentExtension) => void) | undefined;
457 "BlockStatement:exit"?: ((node: ESTree.BlockStatement & NodeParentExtension) => void) | undefined;
458 BreakStatement?: ((node: ESTree.BreakStatement & NodeParentExtension) => void) | undefined;
459 "BreakStatement:exit"?: ((node: ESTree.BreakStatement & NodeParentExtension) => void) | undefined;
460 CallExpression?: ((node: ESTree.CallExpression & NodeParentExtension) => void) | undefined;
461 "CallExpression:exit"?: ((node: ESTree.CallExpression & NodeParentExtension) => void) | undefined;
462 CatchClause?: ((node: ESTree.CatchClause & NodeParentExtension) => void) | undefined;
463 "CatchClause:exit"?: ((node: ESTree.CatchClause & NodeParentExtension) => void) | undefined;
464 ChainExpression?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
465 "ChainExpression:exit"?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
466 ClassBody?: ((node: ESTree.ClassBody & NodeParentExtension) => void) | undefined;
467 "ClassBody:exit"?: ((node: ESTree.ClassBody & NodeParentExtension) => void) | undefined;
468 ClassDeclaration?: ((node: ESTree.ClassDeclaration & NodeParentExtension) => void) | undefined;
469 "ClassDeclaration:exit"?: ((node: ESTree.ClassDeclaration & NodeParentExtension) => void) | undefined;
470 ClassExpression?: ((node: ESTree.ClassExpression & NodeParentExtension) => void) | undefined;
471 "ClassExpression:exit"?: ((node: ESTree.ClassExpression & NodeParentExtension) => void) | undefined;
472 ConditionalExpression?: ((node: ESTree.ConditionalExpression & NodeParentExtension) => void) | undefined;
473 "ConditionalExpression:exit"?: ((node: ESTree.ConditionalExpression & NodeParentExtension) => void) | undefined;
474 ContinueStatement?: ((node: ESTree.ContinueStatement & NodeParentExtension) => void) | undefined;
475 "ContinueStatement:exit"?: ((node: ESTree.ContinueStatement & NodeParentExtension) => void) | undefined;
476 DebuggerStatement?: ((node: ESTree.DebuggerStatement & NodeParentExtension) => void) | undefined;
477 "DebuggerStatement:exit"?: ((node: ESTree.DebuggerStatement & NodeParentExtension) => void) | undefined;
478 DoWhileStatement?: ((node: ESTree.DoWhileStatement & NodeParentExtension) => void) | undefined;
479 "DoWhileStatement:exit"?: ((node: ESTree.DoWhileStatement & NodeParentExtension) => void) | undefined;
480 EmptyStatement?: ((node: ESTree.EmptyStatement & NodeParentExtension) => void) | undefined;
481 "EmptyStatement:exit"?: ((node: ESTree.EmptyStatement & NodeParentExtension) => void) | undefined;
482 ExportAllDeclaration?: ((node: ESTree.ExportAllDeclaration & NodeParentExtension) => void) | undefined;
483 "ExportAllDeclaration:exit"?: ((node: ESTree.ExportAllDeclaration & NodeParentExtension) => void) | undefined;
484 ExportDefaultDeclaration?: ((node: ESTree.ExportDefaultDeclaration & NodeParentExtension) => void) | undefined;
485 "ExportDefaultDeclaration:exit"?: ((node: ESTree.ExportDefaultDeclaration & NodeParentExtension) => void) | undefined;
486 ExportNamedDeclaration?: ((node: ESTree.ExportNamedDeclaration & NodeParentExtension) => void) | undefined;
487 "ExportNamedDeclaration:exit"?: ((node: ESTree.ExportNamedDeclaration & NodeParentExtension) => void) | undefined;
488 ExportSpecifier?: ((node: ESTree.ExportSpecifier & NodeParentExtension) => void) | undefined;
489 "ExportSpecifier:exit"?: ((node: ESTree.ExportSpecifier & NodeParentExtension) => void) | undefined;
490 ExpressionStatement?: ((node: ESTree.ExpressionStatement & NodeParentExtension) => void) | undefined;
491 "ExpressionStatement:exit"?: ((node: ESTree.ExpressionStatement & NodeParentExtension) => void) | undefined;
492 ForInStatement?: ((node: ESTree.ForInStatement & NodeParentExtension) => void) | undefined;
493 "ForInStatement:exit"?: ((node: ESTree.ForInStatement & NodeParentExtension) => void) | undefined;
494 ForOfStatement?: ((node: ESTree.ForOfStatement & NodeParentExtension) => void) | undefined;
495 "ForOfStatement:exit"?: ((node: ESTree.ForOfStatement & NodeParentExtension) => void) | undefined;
496 ForStatement?: ((node: ESTree.ForStatement & NodeParentExtension) => void) | undefined;
497 "ForStatement:exit"?: ((node: ESTree.ForStatement & NodeParentExtension) => void) | undefined;
498 FunctionDeclaration?: ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void) | undefined;
499 "FunctionDeclaration:exit"?: ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void) | undefined;
500 FunctionExpression?: ((node: ESTree.FunctionExpression & NodeParentExtension) => void) | undefined;
501 "FunctionExpression:exit"?: ((node: ESTree.FunctionExpression & NodeParentExtension) => void) | undefined;
502 Identifier?: ((node: ESTree.Identifier & NodeParentExtension) => void) | undefined;
503 "Identifier:exit"?: ((node: ESTree.Identifier & NodeParentExtension) => void) | undefined;
504 IfStatement?: ((node: ESTree.IfStatement & NodeParentExtension) => void) | undefined;
505 "IfStatement:exit"?: ((node: ESTree.IfStatement & NodeParentExtension) => void) | undefined;
506 ImportDeclaration?: ((node: ESTree.ImportDeclaration & NodeParentExtension) => void) | undefined;
507 "ImportDeclaration:exit"?: ((node: ESTree.ImportDeclaration & NodeParentExtension) => void) | undefined;
508 ImportDefaultSpecifier?: ((node: ESTree.ImportDefaultSpecifier & NodeParentExtension) => void) | undefined;
509 "ImportDefaultSpecifier:exit"?: ((node: ESTree.ImportDefaultSpecifier & NodeParentExtension) => void) | undefined;
510 ImportExpression?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
511 "ImportExpression:exit"?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
512 ImportNamespaceSpecifier?: ((node: ESTree.ImportNamespaceSpecifier & NodeParentExtension) => void) | undefined;
513 "ImportNamespaceSpecifier:exit"?: ((node: ESTree.ImportNamespaceSpecifier & NodeParentExtension) => void) | undefined;
514 ImportSpecifier?: ((node: ESTree.ImportSpecifier & NodeParentExtension) => void) | undefined;
515 "ImportSpecifier:exit"?: ((node: ESTree.ImportSpecifier & NodeParentExtension) => void) | undefined;
516 LabeledStatement?: ((node: ESTree.LabeledStatement & NodeParentExtension) => void) | undefined;
517 "LabeledStatement:exit"?: ((node: ESTree.LabeledStatement & NodeParentExtension) => void) | undefined;
518 Literal?: ((node: ESTree.Literal & NodeParentExtension) => void) | undefined;
519 "Literal:exit"?: ((node: ESTree.Literal & NodeParentExtension) => void) | undefined;
520 LogicalExpression?: ((node: ESTree.LogicalExpression & NodeParentExtension) => void) | undefined;
521 "LogicalExpression:exit"?: ((node: ESTree.LogicalExpression & NodeParentExtension) => void) | undefined;
522 MemberExpression?: ((node: ESTree.MemberExpression & NodeParentExtension) => void) | undefined;
523 "MemberExpression:exit"?: ((node: ESTree.MemberExpression & NodeParentExtension) => void) | undefined;
524 MetaProperty?: ((node: ESTree.MetaProperty & NodeParentExtension) => void) | undefined;
525 "MetaProperty:exit"?: ((node: ESTree.MetaProperty & NodeParentExtension) => void) | undefined;
526 MethodDefinition?: ((node: ESTree.MethodDefinition & NodeParentExtension) => void) | undefined;
527 "MethodDefinition:exit"?: ((node: ESTree.MethodDefinition & NodeParentExtension) => void) | undefined;
528 NewExpression?: ((node: ESTree.NewExpression & NodeParentExtension) => void) | undefined;
529 "NewExpression:exit"?: ((node: ESTree.NewExpression & NodeParentExtension) => void) | undefined;
530 ObjectExpression?: ((node: ESTree.ObjectExpression & NodeParentExtension) => void) | undefined;
531 "ObjectExpression:exit"?: ((node: ESTree.ObjectExpression & NodeParentExtension) => void) | undefined;
532 ObjectPattern?: ((node: ESTree.ObjectPattern & NodeParentExtension) => void) | undefined;
533 "ObjectPattern:exit"?: ((node: ESTree.ObjectPattern & NodeParentExtension) => void) | undefined;
534 PrivateIdentifier?: ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void) | undefined;
535 "PrivateIdentifier:exit"?: ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void) | undefined;
536 Program?: ((node: ESTree.Program) => void) | undefined;
537 "Program:exit"?: ((node: ESTree.Program) => void) | undefined;
538 Property?: ((node: ESTree.Property & NodeParentExtension) => void) | undefined;
539 "Property:exit"?: ((node: ESTree.Property & NodeParentExtension) => void) | undefined;
540 PropertyDefinition?: ((node: ESTree.PropertyDefinition & NodeParentExtension) => void) | undefined;
541 "PropertyDefinition:exit"?: ((node: ESTree.PropertyDefinition & NodeParentExtension) => void) | undefined;
542 RestElement?: ((node: ESTree.RestElement & NodeParentExtension) => void) | undefined;
543 "RestElement:exit"?: ((node: ESTree.RestElement & NodeParentExtension) => void) | undefined;
544 ReturnStatement?: ((node: ESTree.ReturnStatement & NodeParentExtension) => void) | undefined;
545 "ReturnStatement:exit"?: ((node: ESTree.ReturnStatement & NodeParentExtension) => void) | undefined;
546 SequenceExpression?: ((node: ESTree.SequenceExpression & NodeParentExtension) => void) | undefined;
547 "SequenceExpression:exit"?: ((node: ESTree.SequenceExpression & NodeParentExtension) => void) | undefined;
548 SpreadElement?: ((node: ESTree.SpreadElement & NodeParentExtension) => void) | undefined;
549 "SpreadElement:exit"?: ((node: ESTree.SpreadElement & NodeParentExtension) => void) | undefined;
550 StaticBlock?: ((node: ESTree.StaticBlock & NodeParentExtension) => void) | undefined;
551 "StaticBlock:exit"?: ((node: ESTree.StaticBlock & NodeParentExtension) => void) | undefined;
552 Super?: ((node: ESTree.Super & NodeParentExtension) => void) | undefined;
553 "Super:exit"?: ((node: ESTree.Super & NodeParentExtension) => void) | undefined;
554 SwitchCase?: ((node: ESTree.SwitchCase & NodeParentExtension) => void) | undefined;
555 "SwitchCase:exit"?: ((node: ESTree.SwitchCase & NodeParentExtension) => void) | undefined;
556 SwitchStatement?: ((node: ESTree.SwitchStatement & NodeParentExtension) => void) | undefined;
557 "SwitchStatement:exit"?: ((node: ESTree.SwitchStatement & NodeParentExtension) => void) | undefined;
558 TaggedTemplateExpression?: ((node: ESTree.TaggedTemplateExpression & NodeParentExtension) => void) | undefined;
559 "TaggedTemplateExpression:exit"?: ((node: ESTree.TaggedTemplateExpression & NodeParentExtension) => void) | undefined;
560 TemplateElement?: ((node: ESTree.TemplateElement & NodeParentExtension) => void) | undefined;
561 "TemplateElement:exit"?: ((node: ESTree.TemplateElement & NodeParentExtension) => void) | undefined;
562 TemplateLiteral?: ((node: ESTree.TemplateLiteral & NodeParentExtension) => void) | undefined;
563 "TemplateLiteral:exit"?: ((node: ESTree.TemplateLiteral & NodeParentExtension) => void) | undefined;
564 ThisExpression?: ((node: ESTree.ThisExpression & NodeParentExtension) => void) | undefined;
565 "ThisExpression:exit"?: ((node: ESTree.ThisExpression & NodeParentExtension) => void) | undefined;
566 ThrowStatement?: ((node: ESTree.ThrowStatement & NodeParentExtension) => void) | undefined;
567 "ThrowStatement:exit"?: ((node: ESTree.ThrowStatement & NodeParentExtension) => void) | undefined;
568 TryStatement?: ((node: ESTree.TryStatement & NodeParentExtension) => void) | undefined;
569 "TryStatement:exit"?: ((node: ESTree.TryStatement & NodeParentExtension) => void) | undefined;
570 UnaryExpression?: ((node: ESTree.UnaryExpression & NodeParentExtension) => void) | undefined;
571 "UnaryExpression:exit"?: ((node: ESTree.UnaryExpression & NodeParentExtension) => void) | undefined;
572 UpdateExpression?: ((node: ESTree.UpdateExpression & NodeParentExtension) => void) | undefined;
573 "UpdateExpression:exit"?: ((node: ESTree.UpdateExpression & NodeParentExtension) => void) | undefined;
574 VariableDeclaration?: ((node: ESTree.VariableDeclaration & NodeParentExtension) => void) | undefined;
575 "VariableDeclaration:exit"?: ((node: ESTree.VariableDeclaration & NodeParentExtension) => void) | undefined;
576 VariableDeclarator?: ((node: ESTree.VariableDeclarator & NodeParentExtension) => void) | undefined;
577 "VariableDeclarator:exit"?: ((node: ESTree.VariableDeclarator & NodeParentExtension) => void) | undefined;
578 WhileStatement?: ((node: ESTree.WhileStatement & NodeParentExtension) => void) | undefined;
579 "WhileStatement:exit"?: ((node: ESTree.WhileStatement & NodeParentExtension) => void) | undefined;
580 WithStatement?: ((node: ESTree.WithStatement & NodeParentExtension) => void) | undefined;
581 "WithStatement:exit"?: ((node: ESTree.WithStatement & NodeParentExtension) => void) | undefined;
582 YieldExpression?: ((node: ESTree.YieldExpression & NodeParentExtension) => void) | undefined;
583 "YieldExpression:exit"?: ((node: ESTree.YieldExpression & NodeParentExtension) => void) | undefined;
584 }
585
586 interface NodeParentExtension {
587 parent: Node;
588 }
589 type Node = ESTree.Node & NodeParentExtension;
590
591 interface RuleListener extends NodeListener {
592 onCodePathStart?(codePath: CodePath, node: Node): void;
593
594 onCodePathEnd?(codePath: CodePath, node: Node): void;
595
596 onCodePathSegmentStart?(segment: CodePathSegment, node: Node): void;
597
598 onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void;
599
600 onCodePathSegmentLoop?(fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node): void;
601
602 [key: string]:
603 | ((codePath: CodePath, node: Node) => void)
604 | ((segment: CodePathSegment, node: Node) => void)
605 | ((fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node) => void)
606 | ((node: Node) => void)
607 | NodeListener[keyof NodeListener]
608 | undefined;
609 }
610
611 interface CodePath {
612 id: string;
613 initialSegment: CodePathSegment;
614 finalSegments: CodePathSegment[];
615 returnedSegments: CodePathSegment[];
616 thrownSegments: CodePathSegment[];
617 currentSegments: CodePathSegment[];
618 upper: CodePath | null;
619 childCodePaths: CodePath[];
620 }
621
622 interface CodePathSegment {
623 id: string;
624 nextSegments: CodePathSegment[];
625 prevSegments: CodePathSegment[];
626 reachable: boolean;
627 }
628
629 interface RuleMetaData {
630 docs?: {
631 /** Provides a short description of the rule. */
632 description?: string | undefined;
633 /**
634 * TODO: remove this field in next major release of @types/eslint.
635 * @deprecated no longer used
636 */
637 category?: string | undefined;
638 /** Whether the rule is enabled in the plugin's `recommended` configuration. */
639 recommended?: boolean | undefined;
640 /** Specifies the URL at which the full documentation can be accessed (enabling code editors to provide a helpful link on highlighted rule violations). */
641 url?: string | undefined;
642 /**
643 * TODO: remove this field in next major release of @types/eslint.
644 * @deprecated use `meta.hasSuggestions` instead
645 */
646 suggestion?: boolean | undefined;
647 } | undefined;
648 /** Violation and suggestion messages. */
649 messages?: { [messageId: string]: string } | undefined;
650 /**
651 * Specifies if the `--fix` option on the command line automatically fixes problems reported by the rule.
652 * Mandatory for fixable rules.
653 */
654 fixable?: "code" | "whitespace" | undefined;
655 /**
656 * Specifies the [options](https://eslint.org/docs/latest/developer-guide/working-with-rules#options-schemas)
657 * so ESLint can prevent invalid [rule configurations](https://eslint.org/docs/latest/user-guide/configuring/rules#configuring-rules).
658 */
659 schema?: JSONSchema4 | JSONSchema4[] | undefined;
660
661 /** Indicates whether the rule has been deprecated. Omit if not deprecated. */
662 deprecated?: boolean | undefined;
663 /** The name of the rule(s) this rule was replaced by, if it was deprecated. */
664 replacedBy?: readonly string[];
665
666 /**
667 * Indicates the type of rule:
668 * - `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve.
669 * - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn’t changed.
670 * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses,
671 * all the parts of the program that determine how the code looks rather than how it executes.
672 * These rules work on parts of the code that aren’t specified in the AST.
673 */
674 type?: "problem" | "suggestion" | "layout" | undefined;
675 /**
676 * Specifies whether the rule can return suggestions (defaults to `false` if omitted).
677 * Mandatory for rules that provide suggestions.
678 */
679 hasSuggestions?: boolean | undefined;
680 }
681
682 interface RuleContext {
683 id: string;
684 options: any[];
685 settings: { [name: string]: any };
686 parserPath: string;
687 parserOptions: Linter.ParserOptions;
688 parserServices: SourceCode.ParserServices;
689 cwd: string;
690 filename: string;
691 physicalFilename: string;
692 sourceCode: SourceCode;
693
694 getAncestors(): ESTree.Node[];
695
696 getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
697
698 /** @deprecated Use property `filename` directly instead */
699 getFilename(): string;
700
701 /** @deprecated Use property `physicalFilename` directly instead */
702 getPhysicalFilename(): string;
703
704 /** @deprecated Use property `cwd` directly instead */
705 getCwd(): string;
706
707 getScope(): Scope.Scope;
708
709 /** @deprecated Use property `sourceCode` directly instead */
710 getSourceCode(): SourceCode;
711
712 markVariableAsUsed(name: string): boolean;
713
714 report(descriptor: ReportDescriptor): void;
715 }
716
717 type ReportFixer = (fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[];
718
719 interface ReportDescriptorOptionsBase {
720 data?: { [key: string]: string };
721
722 fix?: null | ReportFixer;
723 }
724
725 interface SuggestionReportOptions {
726 data?: { [key: string]: string };
727
728 fix: ReportFixer;
729 }
730
731 type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
732 type SuggestionReportDescriptor = SuggestionDescriptorMessage & SuggestionReportOptions;
733
734 interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
735 suggest?: SuggestionReportDescriptor[] | null | undefined;
736 }
737
738 type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
739 type ReportDescriptorMessage = { message: string } | { messageId: string };
740 type ReportDescriptorLocation =
741 | { node: ESTree.Node }
742 | { loc: AST.SourceLocation | { line: number; column: number } };
743
744 interface RuleFixer {
745 insertTextAfter(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
746
747 insertTextAfterRange(range: AST.Range, text: string): Fix;
748
749 insertTextBefore(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
750
751 insertTextBeforeRange(range: AST.Range, text: string): Fix;
752
753 remove(nodeOrToken: ESTree.Node | AST.Token): Fix;
754
755 removeRange(range: AST.Range): Fix;
756
757 replaceText(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
758
759 replaceTextRange(range: AST.Range, text: string): Fix;
760 }
761
762 interface Fix {
763 range: AST.Range;
764 text: string;
765 }
766}
767
768//#region Linter
769
770export class Linter {
771 static version: string;
772
773 version: string;
774
775 constructor(options?: { cwd?: string | undefined });
776
777 verify(code: SourceCode | string, config: Linter.Config, filename?: string): Linter.LintMessage[];
778 verify(code: SourceCode | string, config: Linter.Config, options: Linter.LintOptions): Linter.LintMessage[];
779
780 verifyAndFix(code: string, config: Linter.Config, filename?: string): Linter.FixReport;
781 verifyAndFix(code: string, config: Linter.Config, options: Linter.FixOptions): Linter.FixReport;
782
783 getSourceCode(): SourceCode;
784
785 defineRule(name: string, rule: Rule.RuleModule): void;
786
787 defineRules(rules: { [name: string]: Rule.RuleModule }): void;
788
789 getRules(): Map<string, Rule.RuleModule>;
790
791 defineParser(name: string, parser: Linter.ParserModule): void;
792}
793
794export namespace Linter {
795 type Severity = 0 | 1 | 2;
796 type StringSeverity = "off" | "warn" | "error";
797
798 type RuleLevel = Severity | StringSeverity;
799 type RuleLevelAndOptions<Options extends any[] = any[]> = Prepend<Partial<Options>, RuleLevel>;
800
801 type RuleEntry<Options extends any[] = any[]> = RuleLevel | RuleLevelAndOptions<Options>;
802
803 interface RulesRecord {
804 [rule: string]: RuleEntry;
805 }
806
807 interface HasRules<Rules extends RulesRecord = RulesRecord> {
808 rules?: Partial<Rules> | undefined;
809 }
810
811 interface BaseConfig<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules> extends HasRules<Rules> {
812 $schema?: string | undefined;
813 env?: { [name: string]: boolean } | undefined;
814 extends?: string | string[] | undefined;
815 globals?: { [name: string]: boolean | "off" | "readonly" | "readable" | "writable" | "writeable" } | undefined;
816 noInlineConfig?: boolean | undefined;
817 overrides?: Array<ConfigOverride<OverrideRules>> | undefined;
818 parser?: string | undefined;
819 parserOptions?: ParserOptions | undefined;
820 plugins?: string[] | undefined;
821 processor?: string | undefined;
822 reportUnusedDisableDirectives?: boolean | undefined;
823 settings?: { [name: string]: any } | undefined;
824 }
825
826 interface ConfigOverride<Rules extends RulesRecord = RulesRecord> extends BaseConfig<Rules> {
827 excludedFiles?: string | string[] | undefined;
828 files: string | string[];
829 }
830
831 // https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js
832 interface Config<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules> extends BaseConfig<Rules, OverrideRules> {
833 ignorePatterns?: string | string[] | undefined;
834 root?: boolean | undefined;
835 }
836
837 interface ParserOptions {
838 ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | "latest" | undefined;
839 sourceType?: "script" | "module" | undefined;
840 ecmaFeatures?: {
841 globalReturn?: boolean | undefined;
842 impliedStrict?: boolean | undefined;
843 jsx?: boolean | undefined;
844 experimentalObjectRestSpread?: boolean | undefined;
845 [key: string]: any;
846 } | undefined;
847 [key: string]: any;
848 }
849
850 interface LintOptions {
851 filename?: string | undefined;
852 preprocess?: ((code: string) => string[]) | undefined;
853 postprocess?: ((problemLists: LintMessage[][]) => LintMessage[]) | undefined;
854 filterCodeBlock?: boolean | undefined;
855 disableFixes?: boolean | undefined;
856 allowInlineConfig?: boolean | undefined;
857 reportUnusedDisableDirectives?: boolean | undefined;
858 }
859
860 interface LintSuggestion {
861 desc: string;
862 fix: Rule.Fix;
863 messageId?: string | undefined;
864 }
865
866 interface LintMessage {
867 column: number;
868 line: number;
869 endColumn?: number | undefined;
870 endLine?: number | undefined;
871 ruleId: string | null;
872 message: string;
873 messageId?: string | undefined;
874 nodeType?: string | undefined;
875 fatal?: true | undefined;
876 severity: Severity;
877 fix?: Rule.Fix | undefined;
878 /** @deprecated Use `linter.getSourceCode()` */
879 source?: string | null | undefined;
880 suggestions?: LintSuggestion[] | undefined;
881 }
882
883 interface LintSuppression {
884 kind: string;
885 justification: string;
886 }
887
888 interface SuppressedLintMessage extends LintMessage {
889 suppressions: LintSuppression[];
890 }
891
892 interface FixOptions extends LintOptions {
893 fix?: boolean | undefined;
894 }
895
896 interface FixReport {
897 fixed: boolean;
898 output: string;
899 messages: LintMessage[];
900 }
901
902 type ParserModule =
903 | {
904 parse(text: string, options?: any): AST.Program;
905 }
906 | {
907 parseForESLint(text: string, options?: any): ESLintParseResult;
908 };
909
910 interface ESLintParseResult {
911 ast: AST.Program;
912 parserServices?: SourceCode.ParserServices | undefined;
913 scopeManager?: Scope.ScopeManager | undefined;
914 visitorKeys?: SourceCode.VisitorKeys | undefined;
915 }
916
917 interface ProcessorFile {
918 text: string;
919 filename: string;
920 }
921
922 // https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
923 interface Processor<T extends string | ProcessorFile = string | ProcessorFile> {
924 supportsAutofix?: boolean | undefined;
925 preprocess?(text: string, filename: string): T[];
926 postprocess?(messages: LintMessage[][], filename: string): LintMessage[];
927 }
928 interface FlatConfig {
929 /**
930 * An array of glob patterns indicating the files that the configuration
931 * object should apply to. If not specified, the configuration object applies
932 * to all files
933 */
934 files?: string | string[];
935 /**
936 * An array of glob patterns indicating the files that the configuration
937 * object should not apply to. If not specified, the configuration object
938 * applies to all files matched by files
939 */
940 ignores?: string | string[];
941 /**
942 * An object containing settings related to how JavaScript is configured for
943 * linting.
944 */
945 languageOptions?: {
946 /**
947 * The version of ECMAScript to support. May be any year (i.e., 2022) or
948 * version (i.e., 5). Set to "latest" for the most recent supported version.
949 * @default "latest"
950 */
951 ecmaVersion?: ParserOptions["ecmaVersion"],
952 /**
953 * The type of JavaScript source code. Possible values are "script" for
954 * traditional script files, "module" for ECMAScript modules (ESM), and
955 * "commonjs" for CommonJS files. (default: "module" for .js and .mjs
956 * files; "commonjs" for .cjs files)
957 */
958 sourceType?: "script" | "module" | "commonjs",
959 /**
960 * An object specifying additional objects that should be added to the
961 * global scope during linting.
962 */
963 globals?: ESLint.Environment["globals"],
964 /**
965 * An object containing a parse() or parseForESLint() method.
966 * If not configured, the default ESLint parser (Espree) will be used.
967 */
968 parser?: ParserModule,
969 /**
970 * An object specifying additional options that are passed directly to the
971 * parser() method on the parser. The available options are parser-dependent
972 */
973 parserOptions?: ESLint.Environment["parserOptions"],
974 };
975 /**
976 * An object containing settings related to the linting process
977 */
978 linterOptions?: {
979 /**
980 * A Boolean value indicating if inline configuration is allowed.
981 */
982 noInlineConfig?: boolean,
983 /**
984 * A Boolean value indicating if unused disable directives should be
985 * tracked and reported.
986 */
987 reportUnusedDisableDirectives?: boolean,
988 };
989 /**
990 * Either an object containing preprocess() and postprocess() methods or a
991 * string indicating the name of a processor inside of a plugin
992 * (i.e., "pluginName/processorName").
993 */
994 processor?: string | Processor;
995 /**
996 * An object containing a name-value mapping of plugin names to plugin objects.
997 * When files is specified, these plugins are only available to the matching files.
998 */
999 plugins?: Record<string, ESLint.Plugin>;
1000 /**
1001 * An object containing the configured rules. When files or ignores are specified,
1002 * these rule configurations are only available to the matching files.
1003 */
1004 rules?: RulesRecord;
1005 /**
1006 * An object containing name-value pairs of information that should be
1007 * available to all rules.
1008 */
1009 settings?: Record<string, unknown>;
1010 }
1011}
1012
1013//#endregion
1014
1015//#region ESLint
1016
1017export class ESLint {
1018 static version: string;
1019
1020 static outputFixes(results: ESLint.LintResult[]): Promise<void>;
1021
1022 static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
1023
1024 constructor(options?: ESLint.Options);
1025
1026 lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
1027
1028 lintText(code: string, options?: { filePath?: string | undefined; warnIgnored?: boolean | undefined }): Promise<ESLint.LintResult[]>;
1029
1030 getRulesMetaForResults(results: ESLint.LintResult[]): ESLint.LintResultData['rulesMeta'];
1031
1032 calculateConfigForFile(filePath: string): Promise<any>;
1033
1034 isPathIgnored(filePath: string): Promise<boolean>;
1035
1036 loadFormatter(nameOrPath?: string): Promise<ESLint.Formatter>;
1037}
1038
1039export namespace ESLint {
1040 type ConfigData<Rules extends Linter.RulesRecord = Linter.RulesRecord> = Omit<Linter.Config<Rules>, "$schema">;
1041
1042 interface Environment {
1043 globals?: { [name: string]: boolean; } | undefined;
1044 parserOptions?: Linter.ParserOptions | undefined;
1045 }
1046
1047 interface Plugin {
1048 configs?: Record<string, ConfigData> | undefined;
1049 environments?: Record<string, Environment> | undefined;
1050 processors?: Record<string, Linter.Processor> | undefined;
1051 rules?: Record<string, ((...args: any[]) => any) | Rule.RuleModule> | undefined;
1052 }
1053
1054 interface Options {
1055 // File enumeration
1056 cwd?: string | undefined;
1057 errorOnUnmatchedPattern?: boolean | undefined;
1058 extensions?: string[] | undefined;
1059 globInputPaths?: boolean | undefined;
1060 ignore?: boolean | undefined;
1061 ignorePath?: string | undefined;
1062
1063 // Linting
1064 allowInlineConfig?: boolean | undefined;
1065 baseConfig?: Linter.Config | undefined;
1066 overrideConfig?: Linter.Config | undefined;
1067 overrideConfigFile?: string | undefined;
1068 plugins?: Record<string, Plugin> | undefined;
1069 reportUnusedDisableDirectives?: Linter.StringSeverity | undefined;
1070 resolvePluginsRelativeTo?: string | undefined;
1071 rulePaths?: string[] | undefined;
1072 useEslintrc?: boolean | undefined;
1073
1074 // Autofix
1075 fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
1076 fixTypes?: Array<Rule.RuleMetaData["type"]> | undefined;
1077
1078 // Cache-related
1079 cache?: boolean | undefined;
1080 cacheLocation?: string | undefined;
1081 cacheStrategy?: "content" | "metadata" | undefined;
1082 }
1083
1084 interface LintResult {
1085 filePath: string;
1086 messages: Linter.LintMessage[];
1087 suppressedMessages: Linter.SuppressedLintMessage[];
1088 errorCount: number;
1089 fatalErrorCount: number;
1090 warningCount: number;
1091 fixableErrorCount: number;
1092 fixableWarningCount: number;
1093 output?: string | undefined;
1094 source?: string | undefined;
1095 usedDeprecatedRules: DeprecatedRuleUse[];
1096 }
1097
1098 interface LintResultData {
1099 cwd: string;
1100 rulesMeta: {
1101 [ruleId: string]: Rule.RuleMetaData;
1102 };
1103 }
1104
1105 interface DeprecatedRuleUse {
1106 ruleId: string;
1107 replacedBy: string[];
1108 }
1109
1110 interface Formatter {
1111 format(results: LintResult[], data?: LintResultData): string | Promise<string>;
1112 }
1113
1114 // Docs reference the type by this name
1115 type EditInfo = Rule.Fix;
1116}
1117
1118//#endregion
1119
1120//#region RuleTester
1121
1122export class RuleTester {
1123 constructor(config?: any);
1124
1125 run(
1126 name: string,
1127 rule: Rule.RuleModule,
1128 tests: {
1129 valid?: Array<string | RuleTester.ValidTestCase> | undefined;
1130 invalid?: RuleTester.InvalidTestCase[] | undefined;
1131 },
1132 ): void;
1133
1134 static only(
1135 item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
1136 ): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
1137}
1138
1139export namespace RuleTester {
1140 interface ValidTestCase {
1141 name?: string;
1142 code: string;
1143 options?: any;
1144 filename?: string | undefined;
1145 only?: boolean;
1146 parserOptions?: Linter.ParserOptions | undefined;
1147 settings?: { [name: string]: any } | undefined;
1148 parser?: string | undefined;
1149 globals?: { [name: string]: boolean } | undefined;
1150 }
1151
1152 interface SuggestionOutput {
1153 messageId?: string | undefined;
1154 desc?: string | undefined;
1155 data?: Record<string, unknown> | undefined;
1156 output: string;
1157 }
1158
1159 interface InvalidTestCase extends ValidTestCase {
1160 errors: number | Array<TestCaseError | string>;
1161 output?: string | null | undefined;
1162 }
1163
1164 interface TestCaseError {
1165 message?: string | RegExp | undefined;
1166 messageId?: string | undefined;
1167 type?: string | undefined;
1168 data?: any;
1169 line?: number | undefined;
1170 column?: number | undefined;
1171 endLine?: number | undefined;
1172 endColumn?: number | undefined;
1173 suggestions?: SuggestionOutput[] | undefined;
1174 }
1175}
1176
1177//#endregion
1178
\No newline at end of file