UNPKG

63.3 kBTypeScriptView Raw
1import * as ESTree from "estree";
2import { JSONSchema4 } from "json-schema";
3import { LegacyESLint } from "./use-at-your-own-risk";
4
5export namespace AST {
6 type TokenType =
7 | "Boolean"
8 | "Null"
9 | "Identifier"
10 | "Keyword"
11 | "Punctuator"
12 | "JSXIdentifier"
13 | "JSXText"
14 | "Numeric"
15 | "String"
16 | "RegularExpression";
17
18 interface Token {
19 type: TokenType;
20 value: string;
21 range: Range;
22 loc: SourceLocation;
23 }
24
25 interface SourceLocation {
26 start: ESTree.Position;
27 end: ESTree.Position;
28 }
29
30 type Range = [number, number];
31
32 interface Program extends ESTree.Program {
33 comments: ESTree.Comment[];
34 tokens: Token[];
35 loc: SourceLocation;
36 range: Range;
37 }
38}
39
40export namespace Scope {
41 interface ScopeManager {
42 scopes: Scope[];
43 globalScope: Scope | null;
44
45 acquire(node: ESTree.Node, inner?: boolean): Scope | null;
46
47 getDeclaredVariables(node: ESTree.Node): Variable[];
48 }
49
50 interface Scope {
51 type:
52 | "block"
53 | "catch"
54 | "class"
55 | "for"
56 | "function"
57 | "function-expression-name"
58 | "global"
59 | "module"
60 | "switch"
61 | "with"
62 | "TDZ";
63 isStrict: boolean;
64 upper: Scope | null;
65 childScopes: Scope[];
66 variableScope: Scope;
67 block: ESTree.Node;
68 variables: Variable[];
69 set: Map<string, Variable>;
70 references: Reference[];
71 through: Reference[];
72 functionExpressionScope: boolean;
73 }
74
75 interface Variable {
76 name: string;
77 scope: Scope;
78 identifiers: ESTree.Identifier[];
79 references: Reference[];
80 defs: Definition[];
81 }
82
83 interface Reference {
84 identifier: ESTree.Identifier;
85 from: Scope;
86 resolved: Variable | null;
87 writeExpr: ESTree.Node | null;
88 init: boolean;
89
90 isWrite(): boolean;
91
92 isRead(): boolean;
93
94 isWriteOnly(): boolean;
95
96 isReadOnly(): boolean;
97
98 isReadWrite(): boolean;
99 }
100
101 type DefinitionType =
102 | { type: "CatchClause"; node: ESTree.CatchClause; parent: null }
103 | { type: "ClassName"; node: ESTree.ClassDeclaration | ESTree.ClassExpression; parent: null }
104 | { type: "FunctionName"; node: ESTree.FunctionDeclaration | ESTree.FunctionExpression; parent: null }
105 | { type: "ImplicitGlobalVariable"; node: ESTree.Program; parent: null }
106 | {
107 type: "ImportBinding";
108 node: ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier;
109 parent: ESTree.ImportDeclaration;
110 }
111 | {
112 type: "Parameter";
113 node: ESTree.FunctionDeclaration | ESTree.FunctionExpression | ESTree.ArrowFunctionExpression;
114 parent: null;
115 }
116 | { type: "TDZ"; node: any; parent: null }
117 | { type: "Variable"; node: ESTree.VariableDeclarator; parent: ESTree.VariableDeclaration };
118
119 type Definition = DefinitionType & { name: ESTree.Identifier };
120}
121
122// #region SourceCode
123
124export class SourceCode {
125 text: string;
126 ast: AST.Program;
127 lines: string[];
128 hasBOM: boolean;
129 parserServices: SourceCode.ParserServices;
130 scopeManager: Scope.ScopeManager;
131 visitorKeys: SourceCode.VisitorKeys;
132
133 constructor(text: string, ast: AST.Program);
134 constructor(config: SourceCode.Config);
135
136 static splitLines(text: string): string[];
137
138 getText(node?: ESTree.Node, beforeCount?: number, afterCount?: number): string;
139
140 getLines(): string[];
141
142 getAllComments(): ESTree.Comment[];
143
144 getAncestors(node: ESTree.Node): ESTree.Node[];
145
146 getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
147
148 getJSDocComment(node: ESTree.Node): ESTree.Comment | null;
149
150 getNodeByRangeIndex(index: number): ESTree.Node | null;
151
152 isSpaceBetweenTokens(first: AST.Token, second: AST.Token): boolean;
153
154 getLocFromIndex(index: number): ESTree.Position;
155
156 getIndexFromLoc(location: ESTree.Position): number;
157
158 // Inherited methods from TokenStore
159 // ---------------------------------
160
161 getTokenByRangeStart(offset: number, options?: { includeComments: false }): AST.Token | null;
162 getTokenByRangeStart(offset: number, options: { includeComments: boolean }): AST.Token | ESTree.Comment | null;
163
164 getFirstToken: SourceCode.UnaryNodeCursorWithSkipOptions;
165
166 getFirstTokens: SourceCode.UnaryNodeCursorWithCountOptions;
167
168 getLastToken: SourceCode.UnaryNodeCursorWithSkipOptions;
169
170 getLastTokens: SourceCode.UnaryNodeCursorWithCountOptions;
171
172 getTokenBefore: SourceCode.UnaryCursorWithSkipOptions;
173
174 getTokensBefore: SourceCode.UnaryCursorWithCountOptions;
175
176 getTokenAfter: SourceCode.UnaryCursorWithSkipOptions;
177
178 getTokensAfter: SourceCode.UnaryCursorWithCountOptions;
179
180 getFirstTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
181
182 getFirstTokensBetween: SourceCode.BinaryCursorWithCountOptions;
183
184 getLastTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
185
186 getLastTokensBetween: SourceCode.BinaryCursorWithCountOptions;
187
188 getTokensBetween: SourceCode.BinaryCursorWithCountOptions;
189
190 getTokens:
191 & ((node: ESTree.Node, beforeCount?: number, afterCount?: number) => AST.Token[])
192 & SourceCode.UnaryNodeCursorWithCountOptions;
193
194 commentsExistBetween(
195 left: ESTree.Node | AST.Token | ESTree.Comment,
196 right: ESTree.Node | AST.Token | ESTree.Comment,
197 ): boolean;
198
199 getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
200
201 getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
202
203 getCommentsInside(node: ESTree.Node): ESTree.Comment[];
204
205 getScope(node: ESTree.Node): Scope.Scope;
206
207 isSpaceBetween(
208 first: ESTree.Node | AST.Token,
209 second: ESTree.Node | AST.Token,
210 ): boolean;
211
212 markVariableAsUsed(name: string, refNode?: ESTree.Node): boolean;
213}
214
215export namespace SourceCode {
216 interface Config {
217 text: string;
218 ast: AST.Program;
219 parserServices?: ParserServices | undefined;
220 scopeManager?: Scope.ScopeManager | undefined;
221 visitorKeys?: VisitorKeys | undefined;
222 }
223
224 type ParserServices = any;
225
226 interface VisitorKeys {
227 [nodeType: string]: string[];
228 }
229
230 interface UnaryNodeCursorWithSkipOptions {
231 <T extends AST.Token>(
232 node: ESTree.Node,
233 options:
234 | ((token: AST.Token) => token is T)
235 | {
236 filter: (token: AST.Token) => token is T;
237 includeComments?: false | undefined;
238 skip?: number | undefined;
239 },
240 ): T | null;
241 <T extends AST.Token | ESTree.Comment>(
242 node: ESTree.Node,
243 options: {
244 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
245 includeComments: boolean;
246 skip?: number | undefined;
247 },
248 ): T | null;
249 (
250 node: ESTree.Node,
251 options?:
252 | {
253 filter?: ((token: AST.Token) => boolean) | undefined;
254 includeComments?: false | undefined;
255 skip?: number | undefined;
256 }
257 | ((token: AST.Token) => boolean)
258 | number,
259 ): AST.Token | null;
260 (
261 node: ESTree.Node,
262 options: {
263 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
264 includeComments: boolean;
265 skip?: number | undefined;
266 },
267 ): AST.Token | ESTree.Comment | null;
268 }
269
270 interface UnaryNodeCursorWithCountOptions {
271 <T extends AST.Token>(
272 node: ESTree.Node,
273 options:
274 | ((token: AST.Token) => token is T)
275 | {
276 filter: (token: AST.Token) => token is T;
277 includeComments?: false | undefined;
278 count?: number | undefined;
279 },
280 ): T[];
281 <T extends AST.Token | ESTree.Comment>(
282 node: ESTree.Node,
283 options: {
284 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
285 includeComments: boolean;
286 count?: number | undefined;
287 },
288 ): T[];
289 (
290 node: ESTree.Node,
291 options?:
292 | {
293 filter?: ((token: AST.Token) => boolean) | undefined;
294 includeComments?: false | undefined;
295 count?: number | undefined;
296 }
297 | ((token: AST.Token) => boolean)
298 | number,
299 ): AST.Token[];
300 (
301 node: ESTree.Node,
302 options: {
303 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
304 includeComments: boolean;
305 count?: number | undefined;
306 },
307 ): Array<AST.Token | ESTree.Comment>;
308 }
309
310 interface UnaryCursorWithSkipOptions {
311 <T extends AST.Token>(
312 node: ESTree.Node | AST.Token | ESTree.Comment,
313 options:
314 | ((token: AST.Token) => token is T)
315 | {
316 filter: (token: AST.Token) => token is T;
317 includeComments?: false | undefined;
318 skip?: number | undefined;
319 },
320 ): T | null;
321 <T extends AST.Token | ESTree.Comment>(
322 node: ESTree.Node | AST.Token | ESTree.Comment,
323 options: {
324 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
325 includeComments: boolean;
326 skip?: number | undefined;
327 },
328 ): T | null;
329 (
330 node: ESTree.Node | AST.Token | ESTree.Comment,
331 options?:
332 | {
333 filter?: ((token: AST.Token) => boolean) | undefined;
334 includeComments?: false | undefined;
335 skip?: number | undefined;
336 }
337 | ((token: AST.Token) => boolean)
338 | number,
339 ): AST.Token | null;
340 (
341 node: ESTree.Node | AST.Token | ESTree.Comment,
342 options: {
343 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
344 includeComments: boolean;
345 skip?: number | undefined;
346 },
347 ): AST.Token | ESTree.Comment | null;
348 }
349
350 interface UnaryCursorWithCountOptions {
351 <T extends AST.Token>(
352 node: ESTree.Node | AST.Token | ESTree.Comment,
353 options:
354 | ((token: AST.Token) => token is T)
355 | {
356 filter: (token: AST.Token) => token is T;
357 includeComments?: false | undefined;
358 count?: number | undefined;
359 },
360 ): T[];
361 <T extends AST.Token | ESTree.Comment>(
362 node: ESTree.Node | AST.Token | ESTree.Comment,
363 options: {
364 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
365 includeComments: boolean;
366 count?: number | undefined;
367 },
368 ): T[];
369 (
370 node: ESTree.Node | AST.Token | ESTree.Comment,
371 options?:
372 | {
373 filter?: ((token: AST.Token) => boolean) | undefined;
374 includeComments?: false | undefined;
375 count?: number | undefined;
376 }
377 | ((token: AST.Token) => boolean)
378 | number,
379 ): AST.Token[];
380 (
381 node: ESTree.Node | AST.Token | ESTree.Comment,
382 options: {
383 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
384 includeComments: boolean;
385 count?: number | undefined;
386 },
387 ): Array<AST.Token | ESTree.Comment>;
388 }
389
390 interface BinaryCursorWithSkipOptions {
391 <T extends AST.Token>(
392 left: ESTree.Node | AST.Token | ESTree.Comment,
393 right: ESTree.Node | AST.Token | ESTree.Comment,
394 options:
395 | ((token: AST.Token) => token is T)
396 | {
397 filter: (token: AST.Token) => token is T;
398 includeComments?: false | undefined;
399 skip?: number | undefined;
400 },
401 ): T | null;
402 <T extends AST.Token | ESTree.Comment>(
403 left: ESTree.Node | AST.Token | ESTree.Comment,
404 right: ESTree.Node | AST.Token | ESTree.Comment,
405 options: {
406 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
407 includeComments: boolean;
408 skip?: number | undefined;
409 },
410 ): T | null;
411 (
412 left: ESTree.Node | AST.Token | ESTree.Comment,
413 right: ESTree.Node | AST.Token | ESTree.Comment,
414 options?:
415 | {
416 filter?: ((token: AST.Token) => boolean) | undefined;
417 includeComments?: false | undefined;
418 skip?: number | undefined;
419 }
420 | ((token: AST.Token) => boolean)
421 | number,
422 ): AST.Token | null;
423 (
424 left: ESTree.Node | AST.Token | ESTree.Comment,
425 right: ESTree.Node | AST.Token | ESTree.Comment,
426 options: {
427 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
428 includeComments: boolean;
429 skip?: number | undefined;
430 },
431 ): AST.Token | ESTree.Comment | null;
432 }
433
434 interface BinaryCursorWithCountOptions {
435 <T extends AST.Token>(
436 left: ESTree.Node | AST.Token | ESTree.Comment,
437 right: ESTree.Node | AST.Token | ESTree.Comment,
438 options:
439 | ((token: AST.Token) => token is T)
440 | {
441 filter: (token: AST.Token) => token is T;
442 includeComments?: false | undefined;
443 count?: number | undefined;
444 },
445 ): T[];
446 <T extends AST.Token | ESTree.Comment>(
447 left: ESTree.Node | AST.Token | ESTree.Comment,
448 right: ESTree.Node | AST.Token | ESTree.Comment,
449 options: {
450 filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
451 includeComments: boolean;
452 count?: number | undefined;
453 },
454 ): T[];
455 (
456 left: ESTree.Node | AST.Token | ESTree.Comment,
457 right: ESTree.Node | AST.Token | ESTree.Comment,
458 options?:
459 | {
460 filter?: ((token: AST.Token) => boolean) | undefined;
461 includeComments?: false | undefined;
462 count?: number | undefined;
463 }
464 | ((token: AST.Token) => boolean)
465 | number,
466 ): AST.Token[];
467 (
468 left: ESTree.Node | AST.Token | ESTree.Comment,
469 right: ESTree.Node | AST.Token | ESTree.Comment,
470 options: {
471 filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
472 includeComments: boolean;
473 count?: number | undefined;
474 },
475 ): Array<AST.Token | ESTree.Comment>;
476 }
477}
478
479// #endregion
480
481export namespace Rule {
482 interface RuleModule {
483 create(context: RuleContext): RuleListener;
484 meta?: RuleMetaData | undefined;
485 }
486
487 type NodeTypes = ESTree.Node["type"];
488 interface NodeListener {
489 ArrayExpression?: ((node: ESTree.ArrayExpression & NodeParentExtension) => void) | undefined;
490 "ArrayExpression:exit"?: ((node: ESTree.ArrayExpression & NodeParentExtension) => void) | undefined;
491 ArrayPattern?: ((node: ESTree.ArrayPattern & NodeParentExtension) => void) | undefined;
492 "ArrayPattern:exit"?: ((node: ESTree.ArrayPattern & NodeParentExtension) => void) | undefined;
493 ArrowFunctionExpression?: ((node: ESTree.ArrowFunctionExpression & NodeParentExtension) => void) | undefined;
494 "ArrowFunctionExpression:exit"?:
495 | ((node: ESTree.ArrowFunctionExpression & NodeParentExtension) => void)
496 | undefined;
497 AssignmentExpression?: ((node: ESTree.AssignmentExpression & NodeParentExtension) => void) | undefined;
498 "AssignmentExpression:exit"?: ((node: ESTree.AssignmentExpression & NodeParentExtension) => void) | undefined;
499 AssignmentPattern?: ((node: ESTree.AssignmentPattern & NodeParentExtension) => void) | undefined;
500 "AssignmentPattern:exit"?: ((node: ESTree.AssignmentPattern & NodeParentExtension) => void) | undefined;
501 AwaitExpression?: ((node: ESTree.AwaitExpression & NodeParentExtension) => void) | undefined;
502 "AwaitExpression:exit"?: ((node: ESTree.AwaitExpression & NodeParentExtension) => void) | undefined;
503 BinaryExpression?: ((node: ESTree.BinaryExpression & NodeParentExtension) => void) | undefined;
504 "BinaryExpression:exit"?: ((node: ESTree.BinaryExpression & NodeParentExtension) => void) | undefined;
505 BlockStatement?: ((node: ESTree.BlockStatement & NodeParentExtension) => void) | undefined;
506 "BlockStatement:exit"?: ((node: ESTree.BlockStatement & NodeParentExtension) => void) | undefined;
507 BreakStatement?: ((node: ESTree.BreakStatement & NodeParentExtension) => void) | undefined;
508 "BreakStatement:exit"?: ((node: ESTree.BreakStatement & NodeParentExtension) => void) | undefined;
509 CallExpression?: ((node: ESTree.CallExpression & NodeParentExtension) => void) | undefined;
510 "CallExpression:exit"?: ((node: ESTree.CallExpression & NodeParentExtension) => void) | undefined;
511 CatchClause?: ((node: ESTree.CatchClause & NodeParentExtension) => void) | undefined;
512 "CatchClause:exit"?: ((node: ESTree.CatchClause & NodeParentExtension) => void) | undefined;
513 ChainExpression?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
514 "ChainExpression:exit"?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
515 ClassBody?: ((node: ESTree.ClassBody & NodeParentExtension) => void) | undefined;
516 "ClassBody:exit"?: ((node: ESTree.ClassBody & NodeParentExtension) => void) | undefined;
517 ClassDeclaration?: ((node: ESTree.ClassDeclaration & NodeParentExtension) => void) | undefined;
518 "ClassDeclaration:exit"?: ((node: ESTree.ClassDeclaration & NodeParentExtension) => void) | undefined;
519 ClassExpression?: ((node: ESTree.ClassExpression & NodeParentExtension) => void) | undefined;
520 "ClassExpression:exit"?: ((node: ESTree.ClassExpression & NodeParentExtension) => void) | undefined;
521 ConditionalExpression?: ((node: ESTree.ConditionalExpression & NodeParentExtension) => void) | undefined;
522 "ConditionalExpression:exit"?: ((node: ESTree.ConditionalExpression & NodeParentExtension) => void) | undefined;
523 ContinueStatement?: ((node: ESTree.ContinueStatement & NodeParentExtension) => void) | undefined;
524 "ContinueStatement:exit"?: ((node: ESTree.ContinueStatement & NodeParentExtension) => void) | undefined;
525 DebuggerStatement?: ((node: ESTree.DebuggerStatement & NodeParentExtension) => void) | undefined;
526 "DebuggerStatement:exit"?: ((node: ESTree.DebuggerStatement & NodeParentExtension) => void) | undefined;
527 DoWhileStatement?: ((node: ESTree.DoWhileStatement & NodeParentExtension) => void) | undefined;
528 "DoWhileStatement:exit"?: ((node: ESTree.DoWhileStatement & NodeParentExtension) => void) | undefined;
529 EmptyStatement?: ((node: ESTree.EmptyStatement & NodeParentExtension) => void) | undefined;
530 "EmptyStatement:exit"?: ((node: ESTree.EmptyStatement & NodeParentExtension) => void) | undefined;
531 ExportAllDeclaration?: ((node: ESTree.ExportAllDeclaration & NodeParentExtension) => void) | undefined;
532 "ExportAllDeclaration:exit"?: ((node: ESTree.ExportAllDeclaration & NodeParentExtension) => void) | undefined;
533 ExportDefaultDeclaration?: ((node: ESTree.ExportDefaultDeclaration & NodeParentExtension) => void) | undefined;
534 "ExportDefaultDeclaration:exit"?:
535 | ((node: ESTree.ExportDefaultDeclaration & NodeParentExtension) => void)
536 | undefined;
537 ExportNamedDeclaration?: ((node: ESTree.ExportNamedDeclaration & NodeParentExtension) => void) | undefined;
538 "ExportNamedDeclaration:exit"?:
539 | ((node: ESTree.ExportNamedDeclaration & NodeParentExtension) => void)
540 | undefined;
541 ExportSpecifier?: ((node: ESTree.ExportSpecifier & NodeParentExtension) => void) | undefined;
542 "ExportSpecifier:exit"?: ((node: ESTree.ExportSpecifier & NodeParentExtension) => void) | undefined;
543 ExpressionStatement?: ((node: ESTree.ExpressionStatement & NodeParentExtension) => void) | undefined;
544 "ExpressionStatement:exit"?: ((node: ESTree.ExpressionStatement & NodeParentExtension) => void) | undefined;
545 ForInStatement?: ((node: ESTree.ForInStatement & NodeParentExtension) => void) | undefined;
546 "ForInStatement:exit"?: ((node: ESTree.ForInStatement & NodeParentExtension) => void) | undefined;
547 ForOfStatement?: ((node: ESTree.ForOfStatement & NodeParentExtension) => void) | undefined;
548 "ForOfStatement:exit"?: ((node: ESTree.ForOfStatement & NodeParentExtension) => void) | undefined;
549 ForStatement?: ((node: ESTree.ForStatement & NodeParentExtension) => void) | undefined;
550 "ForStatement:exit"?: ((node: ESTree.ForStatement & NodeParentExtension) => void) | undefined;
551 FunctionDeclaration?: ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void) | undefined;
552 "FunctionDeclaration:exit"?: ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void) | undefined;
553 FunctionExpression?: ((node: ESTree.FunctionExpression & NodeParentExtension) => void) | undefined;
554 "FunctionExpression:exit"?: ((node: ESTree.FunctionExpression & NodeParentExtension) => void) | undefined;
555 Identifier?: ((node: ESTree.Identifier & NodeParentExtension) => void) | undefined;
556 "Identifier:exit"?: ((node: ESTree.Identifier & NodeParentExtension) => void) | undefined;
557 IfStatement?: ((node: ESTree.IfStatement & NodeParentExtension) => void) | undefined;
558 "IfStatement:exit"?: ((node: ESTree.IfStatement & NodeParentExtension) => void) | undefined;
559 ImportDeclaration?: ((node: ESTree.ImportDeclaration & NodeParentExtension) => void) | undefined;
560 "ImportDeclaration:exit"?: ((node: ESTree.ImportDeclaration & NodeParentExtension) => void) | undefined;
561 ImportDefaultSpecifier?: ((node: ESTree.ImportDefaultSpecifier & NodeParentExtension) => void) | undefined;
562 "ImportDefaultSpecifier:exit"?:
563 | ((node: ESTree.ImportDefaultSpecifier & NodeParentExtension) => void)
564 | undefined;
565 ImportExpression?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
566 "ImportExpression:exit"?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
567 ImportNamespaceSpecifier?: ((node: ESTree.ImportNamespaceSpecifier & NodeParentExtension) => void) | undefined;
568 "ImportNamespaceSpecifier:exit"?:
569 | ((node: ESTree.ImportNamespaceSpecifier & NodeParentExtension) => void)
570 | undefined;
571 ImportSpecifier?: ((node: ESTree.ImportSpecifier & NodeParentExtension) => void) | undefined;
572 "ImportSpecifier:exit"?: ((node: ESTree.ImportSpecifier & NodeParentExtension) => void) | undefined;
573 LabeledStatement?: ((node: ESTree.LabeledStatement & NodeParentExtension) => void) | undefined;
574 "LabeledStatement:exit"?: ((node: ESTree.LabeledStatement & NodeParentExtension) => void) | undefined;
575 Literal?: ((node: ESTree.Literal & NodeParentExtension) => void) | undefined;
576 "Literal:exit"?: ((node: ESTree.Literal & NodeParentExtension) => void) | undefined;
577 LogicalExpression?: ((node: ESTree.LogicalExpression & NodeParentExtension) => void) | undefined;
578 "LogicalExpression:exit"?: ((node: ESTree.LogicalExpression & NodeParentExtension) => void) | undefined;
579 MemberExpression?: ((node: ESTree.MemberExpression & NodeParentExtension) => void) | undefined;
580 "MemberExpression:exit"?: ((node: ESTree.MemberExpression & NodeParentExtension) => void) | undefined;
581 MetaProperty?: ((node: ESTree.MetaProperty & NodeParentExtension) => void) | undefined;
582 "MetaProperty:exit"?: ((node: ESTree.MetaProperty & NodeParentExtension) => void) | undefined;
583 MethodDefinition?: ((node: ESTree.MethodDefinition & NodeParentExtension) => void) | undefined;
584 "MethodDefinition:exit"?: ((node: ESTree.MethodDefinition & NodeParentExtension) => void) | undefined;
585 NewExpression?: ((node: ESTree.NewExpression & NodeParentExtension) => void) | undefined;
586 "NewExpression:exit"?: ((node: ESTree.NewExpression & NodeParentExtension) => void) | undefined;
587 ObjectExpression?: ((node: ESTree.ObjectExpression & NodeParentExtension) => void) | undefined;
588 "ObjectExpression:exit"?: ((node: ESTree.ObjectExpression & NodeParentExtension) => void) | undefined;
589 ObjectPattern?: ((node: ESTree.ObjectPattern & NodeParentExtension) => void) | undefined;
590 "ObjectPattern:exit"?: ((node: ESTree.ObjectPattern & NodeParentExtension) => void) | undefined;
591 PrivateIdentifier?: ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void) | undefined;
592 "PrivateIdentifier:exit"?: ((node: ESTree.PrivateIdentifier & NodeParentExtension) => void) | undefined;
593 Program?: ((node: ESTree.Program) => void) | undefined;
594 "Program:exit"?: ((node: ESTree.Program) => void) | undefined;
595 Property?: ((node: ESTree.Property & NodeParentExtension) => void) | undefined;
596 "Property:exit"?: ((node: ESTree.Property & NodeParentExtension) => void) | undefined;
597 PropertyDefinition?: ((node: ESTree.PropertyDefinition & NodeParentExtension) => void) | undefined;
598 "PropertyDefinition:exit"?: ((node: ESTree.PropertyDefinition & NodeParentExtension) => void) | undefined;
599 RestElement?: ((node: ESTree.RestElement & NodeParentExtension) => void) | undefined;
600 "RestElement:exit"?: ((node: ESTree.RestElement & NodeParentExtension) => void) | undefined;
601 ReturnStatement?: ((node: ESTree.ReturnStatement & NodeParentExtension) => void) | undefined;
602 "ReturnStatement:exit"?: ((node: ESTree.ReturnStatement & NodeParentExtension) => void) | undefined;
603 SequenceExpression?: ((node: ESTree.SequenceExpression & NodeParentExtension) => void) | undefined;
604 "SequenceExpression:exit"?: ((node: ESTree.SequenceExpression & NodeParentExtension) => void) | undefined;
605 SpreadElement?: ((node: ESTree.SpreadElement & NodeParentExtension) => void) | undefined;
606 "SpreadElement:exit"?: ((node: ESTree.SpreadElement & NodeParentExtension) => void) | undefined;
607 StaticBlock?: ((node: ESTree.StaticBlock & NodeParentExtension) => void) | undefined;
608 "StaticBlock:exit"?: ((node: ESTree.StaticBlock & NodeParentExtension) => void) | undefined;
609 Super?: ((node: ESTree.Super & NodeParentExtension) => void) | undefined;
610 "Super:exit"?: ((node: ESTree.Super & NodeParentExtension) => void) | undefined;
611 SwitchCase?: ((node: ESTree.SwitchCase & NodeParentExtension) => void) | undefined;
612 "SwitchCase:exit"?: ((node: ESTree.SwitchCase & NodeParentExtension) => void) | undefined;
613 SwitchStatement?: ((node: ESTree.SwitchStatement & NodeParentExtension) => void) | undefined;
614 "SwitchStatement:exit"?: ((node: ESTree.SwitchStatement & NodeParentExtension) => void) | undefined;
615 TaggedTemplateExpression?: ((node: ESTree.TaggedTemplateExpression & NodeParentExtension) => void) | undefined;
616 "TaggedTemplateExpression:exit"?:
617 | ((node: ESTree.TaggedTemplateExpression & NodeParentExtension) => void)
618 | undefined;
619 TemplateElement?: ((node: ESTree.TemplateElement & NodeParentExtension) => void) | undefined;
620 "TemplateElement:exit"?: ((node: ESTree.TemplateElement & NodeParentExtension) => void) | undefined;
621 TemplateLiteral?: ((node: ESTree.TemplateLiteral & NodeParentExtension) => void) | undefined;
622 "TemplateLiteral:exit"?: ((node: ESTree.TemplateLiteral & NodeParentExtension) => void) | undefined;
623 ThisExpression?: ((node: ESTree.ThisExpression & NodeParentExtension) => void) | undefined;
624 "ThisExpression:exit"?: ((node: ESTree.ThisExpression & NodeParentExtension) => void) | undefined;
625 ThrowStatement?: ((node: ESTree.ThrowStatement & NodeParentExtension) => void) | undefined;
626 "ThrowStatement:exit"?: ((node: ESTree.ThrowStatement & NodeParentExtension) => void) | undefined;
627 TryStatement?: ((node: ESTree.TryStatement & NodeParentExtension) => void) | undefined;
628 "TryStatement:exit"?: ((node: ESTree.TryStatement & NodeParentExtension) => void) | undefined;
629 UnaryExpression?: ((node: ESTree.UnaryExpression & NodeParentExtension) => void) | undefined;
630 "UnaryExpression:exit"?: ((node: ESTree.UnaryExpression & NodeParentExtension) => void) | undefined;
631 UpdateExpression?: ((node: ESTree.UpdateExpression & NodeParentExtension) => void) | undefined;
632 "UpdateExpression:exit"?: ((node: ESTree.UpdateExpression & NodeParentExtension) => void) | undefined;
633 VariableDeclaration?: ((node: ESTree.VariableDeclaration & NodeParentExtension) => void) | undefined;
634 "VariableDeclaration:exit"?: ((node: ESTree.VariableDeclaration & NodeParentExtension) => void) | undefined;
635 VariableDeclarator?: ((node: ESTree.VariableDeclarator & NodeParentExtension) => void) | undefined;
636 "VariableDeclarator:exit"?: ((node: ESTree.VariableDeclarator & NodeParentExtension) => void) | undefined;
637 WhileStatement?: ((node: ESTree.WhileStatement & NodeParentExtension) => void) | undefined;
638 "WhileStatement:exit"?: ((node: ESTree.WhileStatement & NodeParentExtension) => void) | undefined;
639 WithStatement?: ((node: ESTree.WithStatement & NodeParentExtension) => void) | undefined;
640 "WithStatement:exit"?: ((node: ESTree.WithStatement & NodeParentExtension) => void) | undefined;
641 YieldExpression?: ((node: ESTree.YieldExpression & NodeParentExtension) => void) | undefined;
642 "YieldExpression:exit"?: ((node: ESTree.YieldExpression & NodeParentExtension) => void) | undefined;
643 }
644
645 interface NodeParentExtension {
646 parent: Node;
647 }
648 type Node = ESTree.Node & NodeParentExtension;
649
650 interface RuleListener extends NodeListener {
651 onCodePathStart?(codePath: CodePath, node: Node): void;
652
653 onCodePathEnd?(codePath: CodePath, node: Node): void;
654
655 onCodePathSegmentStart?(segment: CodePathSegment, node: Node): void;
656
657 onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void;
658
659 onCodePathSegmentLoop?(fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node): void;
660
661 [key: string]:
662 | ((codePath: CodePath, node: Node) => void)
663 | ((segment: CodePathSegment, node: Node) => void)
664 | ((fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node) => void)
665 | ((node: Node) => void)
666 | NodeListener[keyof NodeListener]
667 | undefined;
668 }
669
670 type CodePathOrigin = "program" | "function" | "class-field-initializer" | "class-static-block";
671
672 interface CodePath {
673 id: string;
674 origin: CodePathOrigin;
675 initialSegment: CodePathSegment;
676 finalSegments: CodePathSegment[];
677 returnedSegments: CodePathSegment[];
678 thrownSegments: CodePathSegment[];
679 upper: CodePath | null;
680 childCodePaths: CodePath[];
681 }
682
683 interface CodePathSegment {
684 id: string;
685 nextSegments: CodePathSegment[];
686 prevSegments: CodePathSegment[];
687 reachable: boolean;
688 }
689
690 interface RuleMetaData {
691 /** Properties often used for documentation generation and tooling. */
692 docs?: {
693 /** Provides a short description of the rule. Commonly used when generating lists of rules. */
694 description?: string | undefined;
695 /** Historically used by some plugins that divide rules into categories in their documentation. */
696 category?: string | undefined;
697 /** Historically used by some plugins to indicate a rule belongs in their `recommended` configuration. */
698 recommended?: boolean | undefined;
699 /** Specifies the URL at which the full documentation can be accessed. Code editors often use this to provide a helpful link on highlighted rule violations. */
700 url?: string | undefined;
701 } | undefined;
702 /** Violation and suggestion messages. */
703 messages?: { [messageId: string]: string } | undefined;
704 /**
705 * Specifies if the `--fix` option on the command line automatically fixes problems reported by the rule.
706 * Mandatory for fixable rules.
707 */
708 fixable?: "code" | "whitespace" | undefined;
709 /**
710 * Specifies the [options](https://eslint.org/docs/latest/extend/custom-rules#options-schemas)
711 * so ESLint can prevent invalid [rule configurations](https://eslint.org/docs/latest/use/configure/rules#configuring-rules).
712 * Mandatory for rules with options.
713 */
714 schema?: JSONSchema4 | JSONSchema4[] | false | undefined;
715
716 /** Indicates whether the rule has been deprecated. Omit if not deprecated. */
717 deprecated?: boolean | undefined;
718 /** The name of the rule(s) this rule was replaced by, if it was deprecated. */
719 replacedBy?: readonly string[];
720
721 /**
722 * Indicates the type of rule:
723 * - `"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.
724 * - `"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.
725 * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses,
726 * all the parts of the program that determine how the code looks rather than how it executes.
727 * These rules work on parts of the code that aren’t specified in the AST.
728 */
729 type?: "problem" | "suggestion" | "layout" | undefined;
730 /**
731 * Specifies whether the rule can return suggestions (defaults to `false` if omitted).
732 * Mandatory for rules that provide suggestions.
733 */
734 hasSuggestions?: boolean | undefined;
735 }
736
737 interface RuleContext {
738 id: string;
739 options: any[];
740 settings: { [name: string]: any };
741 parserPath: string | undefined;
742 languageOptions: Linter.LanguageOptions;
743 parserOptions: Linter.ParserOptions;
744 cwd: string;
745 filename: string;
746 physicalFilename: string;
747 sourceCode: SourceCode;
748
749 getAncestors(): ESTree.Node[];
750
751 getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
752
753 /** @deprecated Use property `filename` directly instead */
754 getFilename(): string;
755
756 /** @deprecated Use property `physicalFilename` directly instead */
757 getPhysicalFilename(): string;
758
759 /** @deprecated Use property `cwd` directly instead */
760 getCwd(): string;
761
762 getScope(): Scope.Scope;
763
764 /** @deprecated Use property `sourceCode` directly instead */
765 getSourceCode(): SourceCode;
766
767 markVariableAsUsed(name: string): boolean;
768
769 report(descriptor: ReportDescriptor): void;
770 }
771
772 type ReportFixer = (fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[];
773
774 interface ReportDescriptorOptionsBase {
775 data?: { [key: string]: string };
776
777 fix?: null | ReportFixer;
778 }
779
780 interface SuggestionReportOptions {
781 data?: { [key: string]: string };
782
783 fix: ReportFixer;
784 }
785
786 type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
787 type SuggestionReportDescriptor = SuggestionDescriptorMessage & SuggestionReportOptions;
788
789 interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
790 suggest?: SuggestionReportDescriptor[] | null | undefined;
791 }
792
793 type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
794 type ReportDescriptorMessage = { message: string } | { messageId: string };
795 type ReportDescriptorLocation =
796 | { node: ESTree.Node }
797 | { loc: AST.SourceLocation | { line: number; column: number } };
798
799 interface RuleFixer {
800 insertTextAfter(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
801
802 insertTextAfterRange(range: AST.Range, text: string): Fix;
803
804 insertTextBefore(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
805
806 insertTextBeforeRange(range: AST.Range, text: string): Fix;
807
808 remove(nodeOrToken: ESTree.Node | AST.Token): Fix;
809
810 removeRange(range: AST.Range): Fix;
811
812 replaceText(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
813
814 replaceTextRange(range: AST.Range, text: string): Fix;
815 }
816
817 interface Fix {
818 range: AST.Range;
819 text: string;
820 }
821}
822
823// #region Linter
824
825export class Linter {
826 static readonly version: string;
827
828 version: string;
829
830 constructor(options?: { cwd?: string | undefined; configType?: "flat" | "eslintrc" });
831
832 verify(
833 code: SourceCode | string,
834 config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
835 filename?: string,
836 ): Linter.LintMessage[];
837 verify(
838 code: SourceCode | string,
839 config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
840 options: Linter.LintOptions,
841 ): Linter.LintMessage[];
842
843 verifyAndFix(
844 code: string,
845 config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
846 filename?: string,
847 ): Linter.FixReport;
848 verifyAndFix(
849 code: string,
850 config: Linter.LegacyConfig | Linter.Config | Linter.Config[],
851 options: Linter.FixOptions,
852 ): Linter.FixReport;
853
854 getSourceCode(): SourceCode;
855
856 defineRule(name: string, rule: Rule.RuleModule): void;
857
858 defineRules(rules: { [name: string]: Rule.RuleModule }): void;
859
860 getRules(): Map<string, Rule.RuleModule>;
861
862 defineParser(name: string, parser: Linter.Parser): void;
863
864 getTimes(): Linter.Stats["times"];
865
866 getFixPassCount(): Linter.Stats["fixPasses"];
867}
868
869export namespace Linter {
870 /**
871 * The numeric severity level for a rule.
872 *
873 * - `0` means off.
874 * - `1` means warn.
875 * - `2` means error.
876 *
877 * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
878 */
879 type Severity = 0 | 1 | 2;
880
881 /**
882 * The human readable severity level for a rule.
883 *
884 * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
885 */
886 type StringSeverity = "off" | "warn" | "error";
887
888 /**
889 * The numeric or human readable severity level for a rule.
890 *
891 * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities)
892 */
893 type RuleSeverity = Severity | StringSeverity;
894
895 /**
896 * An array containing the rule severity level, followed by the rule options.
897 *
898 * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
899 */
900 type RuleSeverityAndOptions<Options extends any[] = any[]> = [RuleSeverity, ...Partial<Options>];
901
902 /**
903 * The severity level for the rule or an array containing the rule severity level, followed by the rule options.
904 *
905 * @see [Rules](https://eslint.org/docs/latest/use/configure/rules)
906 */
907 type RuleEntry<Options extends any[] = any[]> = RuleSeverity | RuleSeverityAndOptions<Options>;
908
909 /**
910 * The rules config object is a key/value map of rule names and their severity and options.
911 */
912 interface RulesRecord {
913 [rule: string]: RuleEntry;
914 }
915
916 /**
917 * A configuration object that may have a `rules` block.
918 */
919 interface HasRules<Rules extends RulesRecord = RulesRecord> {
920 rules?: Partial<Rules> | undefined;
921 }
922
923 /**
924 * The ECMAScript version of the code being linted.
925 */
926 type EcmaVersion =
927 | 3
928 | 5
929 | 6
930 | 7
931 | 8
932 | 9
933 | 10
934 | 11
935 | 12
936 | 13
937 | 14
938 | 15
939 | 16
940 | 2015
941 | 2016
942 | 2017
943 | 2018
944 | 2019
945 | 2020
946 | 2021
947 | 2022
948 | 2023
949 | 2024
950 | 2025
951 | "latest";
952
953 /**
954 * The type of JavaScript source code.
955 */
956 type SourceType = "script" | "module" | "commonjs";
957
958 /**
959 * ESLint legacy configuration.
960 *
961 * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
962 */
963 interface BaseConfig<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules>
964 extends HasRules<Rules>
965 {
966 $schema?: string | undefined;
967
968 /**
969 * An environment provides predefined global variables.
970 *
971 * @see [Environments](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-environments)
972 */
973 env?: { [name: string]: boolean } | undefined;
974
975 /**
976 * Extending configuration files.
977 *
978 * @see [Extends](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#extending-configuration-files)
979 */
980 extends?: string | string[] | undefined;
981
982 /**
983 * Specifying globals.
984 *
985 * @see [Globals](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-globals)
986 */
987 globals?: Linter.Globals | undefined;
988
989 /**
990 * Disable processing of inline comments.
991 *
992 * @see [Disabling Inline Comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#disabling-inline-comments)
993 */
994 noInlineConfig?: boolean | undefined;
995
996 /**
997 * Overrides can be used to use a differing configuration for matching sub-directories and files.
998 *
999 * @see [How do overrides work](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#how-do-overrides-work)
1000 */
1001 overrides?: Array<ConfigOverride<OverrideRules>> | undefined;
1002
1003 /**
1004 * Parser.
1005 *
1006 * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers)
1007 * @see [Specifying Parser](https://eslint.org/docs/latest/use/configure/parser-deprecated)
1008 */
1009 parser?: string | undefined;
1010
1011 /**
1012 * Parser options.
1013 *
1014 * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers)
1015 * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options)
1016 */
1017 parserOptions?: ParserOptions | undefined;
1018
1019 /**
1020 * Which third-party plugins define additional rules, environments, configs, etc. for ESLint to use.
1021 *
1022 * @see [Configuring Plugins](https://eslint.org/docs/latest/use/configure/plugins-deprecated#configure-plugins)
1023 */
1024 plugins?: string[] | undefined;
1025
1026 /**
1027 * Specifying processor.
1028 *
1029 * @see [processor](https://eslint.org/docs/latest/use/configure/plugins-deprecated#specify-a-processor)
1030 */
1031 processor?: string | undefined;
1032
1033 /**
1034 * Report unused eslint-disable comments as warning.
1035 *
1036 * @see [Report unused eslint-disable comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#report-unused-eslint-disable-comments)
1037 */
1038 reportUnusedDisableDirectives?: boolean | undefined;
1039
1040 /**
1041 * Settings.
1042 *
1043 * @see [Settings](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#adding-shared-settings)
1044 */
1045 settings?: { [name: string]: any } | undefined;
1046 }
1047
1048 /**
1049 * The overwrites that apply more differing configuration to specific files or directories.
1050 */
1051 interface ConfigOverride<Rules extends RulesRecord = RulesRecord> extends BaseConfig<Rules> {
1052 /**
1053 * The glob patterns for excluded files.
1054 */
1055 excludedFiles?: string | string[] | undefined;
1056
1057 /**
1058 * The glob patterns for target files.
1059 */
1060 files: string | string[];
1061 }
1062
1063 /**
1064 * ESLint legacy configuration.
1065 *
1066 * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/)
1067 */
1068 // https://github.com/eslint/eslint/blob/v8.57.0/conf/config-schema.js
1069 interface LegacyConfig<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules>
1070 extends BaseConfig<Rules, OverrideRules>
1071 {
1072 /**
1073 * Tell ESLint to ignore specific files and directories.
1074 *
1075 * @see [Ignore Patterns](https://eslint.org/docs/latest/use/configure/ignore-deprecated#ignorepatterns-in-config-files)
1076 */
1077 ignorePatterns?: string | string[] | undefined;
1078
1079 /**
1080 * @see [Using Configuration Files](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#using-configuration-files)
1081 */
1082 root?: boolean | undefined;
1083 }
1084
1085 /**
1086 * Parser options.
1087 *
1088 * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options)
1089 */
1090 interface ParserOptions {
1091 /**
1092 * Accepts any valid ECMAScript version number or `'latest'`:
1093 *
1094 * - A version: es3, es5, es6, es7, es8, es9, es10, es11, es12, es13, es14, ..., or
1095 * - A year: es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, ..., or
1096 * - `'latest'`
1097 *
1098 * When it's a version or a year, the value must be a number - so do not include the `es` prefix.
1099 *
1100 * Specifies the version of ECMAScript syntax you want to use. This is used by the parser to determine how to perform scope analysis, and it affects the default
1101 *
1102 * @default 5
1103 */
1104 ecmaVersion?: EcmaVersion | undefined;
1105
1106 /**
1107 * The type of JavaScript source code. Possible values are "script" for
1108 * traditional script files, "module" for ECMAScript modules (ESM), and
1109 * "commonjs" for CommonJS files.
1110 *
1111 * @default 'script'
1112 *
1113 * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options
1114 */
1115 sourceType?: SourceType | undefined;
1116
1117 /**
1118 * An object indicating which additional language features you'd like to use.
1119 *
1120 * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options
1121 */
1122 ecmaFeatures?: {
1123 globalReturn?: boolean | undefined;
1124 impliedStrict?: boolean | undefined;
1125 jsx?: boolean | undefined;
1126 experimentalObjectRestSpread?: boolean | undefined;
1127 [key: string]: any;
1128 } | undefined;
1129 [key: string]: any;
1130 }
1131
1132 interface LintOptions {
1133 filename?: string | undefined;
1134 preprocess?: ((code: string) => string[]) | undefined;
1135 postprocess?: ((problemLists: LintMessage[][]) => LintMessage[]) | undefined;
1136 filterCodeBlock?: boolean | undefined;
1137 disableFixes?: boolean | undefined;
1138 allowInlineConfig?: boolean | undefined;
1139 reportUnusedDisableDirectives?: boolean | undefined;
1140 }
1141
1142 interface LintSuggestion {
1143 desc: string;
1144 fix: Rule.Fix;
1145 messageId?: string | undefined;
1146 }
1147
1148 interface LintMessage {
1149 column: number;
1150 line: number;
1151 endColumn?: number | undefined;
1152 endLine?: number | undefined;
1153 ruleId: string | null;
1154 message: string;
1155 messageId?: string | undefined;
1156 nodeType?: string | undefined;
1157 fatal?: true | undefined;
1158 severity: Exclude<Severity, 0>;
1159 fix?: Rule.Fix | undefined;
1160 suggestions?: LintSuggestion[] | undefined;
1161 }
1162
1163 interface LintSuppression {
1164 kind: string;
1165 justification: string;
1166 }
1167
1168 interface SuppressedLintMessage extends LintMessage {
1169 suppressions: LintSuppression[];
1170 }
1171
1172 interface FixOptions extends LintOptions {
1173 fix?: boolean | undefined;
1174 }
1175
1176 interface FixReport {
1177 fixed: boolean;
1178 output: string;
1179 messages: LintMessage[];
1180 }
1181
1182 // Temporarily loosen type for just flat config files (see #68232)
1183 type NonESTreeParser =
1184 & Omit<ESTreeParser, "parseForESLint">
1185 & ({
1186 parse(text: string, options?: any): unknown;
1187 } | {
1188 parseForESLint(text: string, options?: any): Omit<ESLintParseResult, "ast" | "scopeManager"> & {
1189 ast: unknown;
1190 scopeManager?: unknown;
1191 };
1192 });
1193
1194 type ESTreeParser =
1195 & ESLint.ObjectMetaProperties
1196 & (
1197 | { parse(text: string, options?: any): AST.Program }
1198 | { parseForESLint(text: string, options?: any): ESLintParseResult }
1199 );
1200
1201 type Parser = NonESTreeParser | ESTreeParser;
1202
1203 interface ESLintParseResult {
1204 ast: AST.Program;
1205 parserServices?: SourceCode.ParserServices | undefined;
1206 scopeManager?: Scope.ScopeManager | undefined;
1207 visitorKeys?: SourceCode.VisitorKeys | undefined;
1208 }
1209
1210 interface ProcessorFile {
1211 text: string;
1212 filename: string;
1213 }
1214
1215 // https://eslint.org/docs/latest/extend/plugins#processors-in-plugins
1216 interface Processor<T extends string | ProcessorFile = string | ProcessorFile> extends ESLint.ObjectMetaProperties {
1217 supportsAutofix?: boolean | undefined;
1218 preprocess?(text: string, filename: string): T[];
1219 postprocess?(messages: LintMessage[][], filename: string): LintMessage[];
1220 }
1221
1222 interface Config<Rules extends RulesRecord = RulesRecord> {
1223 /**
1224 * An string to identify the configuration object. Used in error messages and
1225 * inspection tools.
1226 */
1227 name?: string;
1228
1229 /**
1230 * An array of glob patterns indicating the files that the configuration
1231 * object should apply to. If not specified, the configuration object applies
1232 * to all files
1233 */
1234 files?: Array<string | string[]>;
1235
1236 /**
1237 * An array of glob patterns indicating the files that the configuration
1238 * object should not apply to. If not specified, the configuration object
1239 * applies to all files matched by files
1240 */
1241 ignores?: string[];
1242
1243 /**
1244 * An object containing settings related to how JavaScript is configured for
1245 * linting.
1246 */
1247 languageOptions?: LanguageOptions;
1248
1249 /**
1250 * An object containing settings related to the linting process
1251 */
1252 linterOptions?: LinterOptions;
1253
1254 /**
1255 * Either an object containing preprocess() and postprocess() methods or a
1256 * string indicating the name of a processor inside of a plugin
1257 * (i.e., "pluginName/processorName").
1258 */
1259 processor?: string | Processor;
1260
1261 /**
1262 * An object containing a name-value mapping of plugin names to plugin objects.
1263 * When files is specified, these plugins are only available to the matching files.
1264 */
1265 plugins?: Record<string, ESLint.Plugin>;
1266
1267 /**
1268 * An object containing the configured rules. When files or ignores are specified,
1269 * these rule configurations are only available to the matching files.
1270 */
1271 rules?: Partial<Rules>;
1272
1273 /**
1274 * An object containing name-value pairs of information that should be
1275 * available to all rules.
1276 */
1277 settings?: Record<string, unknown>;
1278 }
1279
1280 /** @deprecated Use `Config` instead of `FlatConfig` */
1281 type FlatConfig = Config;
1282
1283 type GlobalConf = boolean | "off" | "readable" | "readonly" | "writable" | "writeable";
1284
1285 interface Globals {
1286 [name: string]: GlobalConf;
1287 }
1288
1289 interface LanguageOptions {
1290 /**
1291 * The version of ECMAScript to support. May be any year (i.e., 2022) or
1292 * version (i.e., 5). Set to "latest" for the most recent supported version.
1293 * @default "latest"
1294 */
1295 ecmaVersion?: EcmaVersion | undefined;
1296
1297 /**
1298 * The type of JavaScript source code. Possible values are "script" for
1299 * traditional script files, "module" for ECMAScript modules (ESM), and
1300 * "commonjs" for CommonJS files. (default: "module" for .js and .mjs
1301 * files; "commonjs" for .cjs files)
1302 */
1303 sourceType?: SourceType | undefined;
1304
1305 /**
1306 * An object specifying additional objects that should be added to the
1307 * global scope during linting.
1308 */
1309 globals?: Globals | undefined;
1310
1311 /**
1312 * An object containing a parse() or parseForESLint() method.
1313 * If not configured, the default ESLint parser (Espree) will be used.
1314 */
1315 parser?: Parser | undefined;
1316
1317 /**
1318 * An object specifying additional options that are passed directly to the
1319 * parser() method on the parser. The available options are parser-dependent
1320 */
1321 parserOptions?: Linter.ParserOptions | undefined;
1322 }
1323
1324 interface LinterOptions {
1325 /**
1326 * A boolean value indicating if inline configuration is allowed.
1327 */
1328 noInlineConfig?: boolean;
1329
1330 /**
1331 * A severity value indicating if and how unused disable directives should be
1332 * tracked and reported.
1333 */
1334 reportUnusedDisableDirectives?: Severity | StringSeverity | boolean;
1335 }
1336
1337 interface Stats {
1338 /**
1339 * The number of times ESLint has applied at least one fix after linting.
1340 */
1341 fixPasses: number;
1342
1343 /**
1344 * The times spent on (parsing, fixing, linting) a file, where the linting refers to the timing information for each rule.
1345 */
1346 times: { passes: TimePass[] };
1347 }
1348
1349 interface TimePass {
1350 parse: { total: number };
1351 rules?: Record<string, { total: number }>;
1352 fix: { total: number };
1353 total: number;
1354 }
1355}
1356
1357// #endregion
1358
1359// #region ESLint
1360
1361export class ESLint {
1362 static configType: "flat";
1363
1364 static readonly version: string;
1365
1366 static outputFixes(results: ESLint.LintResult[]): Promise<void>;
1367
1368 static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
1369
1370 constructor(options?: ESLint.Options);
1371
1372 lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
1373
1374 lintText(
1375 code: string,
1376 options?: { filePath?: string | undefined; warnIgnored?: boolean | undefined },
1377 ): Promise<ESLint.LintResult[]>;
1378
1379 getRulesMetaForResults(results: ESLint.LintResult[]): ESLint.LintResultData["rulesMeta"];
1380
1381 hasFlag(flag: string): boolean;
1382
1383 calculateConfigForFile(filePath: string): Promise<any>;
1384
1385 findConfigFile(): Promise<string | undefined>;
1386
1387 isPathIgnored(filePath: string): Promise<boolean>;
1388
1389 loadFormatter(nameOrPath?: string): Promise<ESLint.Formatter>;
1390}
1391
1392export namespace ESLint {
1393 type ConfigData<Rules extends Linter.RulesRecord = Linter.RulesRecord> = Omit<
1394 Linter.LegacyConfig<Rules>,
1395 "$schema"
1396 >;
1397
1398 interface Environment {
1399 globals?: Linter.Globals | undefined;
1400 parserOptions?: Linter.ParserOptions | undefined;
1401 }
1402
1403 interface ObjectMetaProperties {
1404 /** @deprecated Use `meta.name` instead. */
1405 name?: string | undefined;
1406
1407 /** @deprecated Use `meta.version` instead. */
1408 version?: string | undefined;
1409
1410 meta?: {
1411 name?: string | undefined;
1412 version?: string | undefined;
1413 };
1414 }
1415
1416 interface Plugin extends ObjectMetaProperties {
1417 configs?: Record<string, Linter.LegacyConfig | Linter.Config | Linter.Config[]> | undefined;
1418 environments?: Record<string, Environment> | undefined;
1419 processors?: Record<string, Linter.Processor> | undefined;
1420 rules?: Record<string, Rule.RuleModule> | undefined;
1421 }
1422
1423 type FixType = "directive" | "problem" | "suggestion" | "layout";
1424
1425 type CacheStrategy = "content" | "metadata";
1426
1427 interface Options {
1428 // File enumeration
1429 cwd?: string | undefined;
1430 errorOnUnmatchedPattern?: boolean | undefined;
1431 globInputPaths?: boolean | undefined;
1432 ignore?: boolean | undefined;
1433 ignorePatterns?: string[] | null | undefined;
1434 passOnNoPatterns?: boolean | undefined;
1435 warnIgnored?: boolean | undefined;
1436
1437 // Linting
1438 allowInlineConfig?: boolean | undefined;
1439 baseConfig?: Linter.Config | Linter.Config[] | null | undefined;
1440 overrideConfig?: Linter.Config | Linter.Config[] | null | undefined;
1441 overrideConfigFile?: string | boolean | undefined;
1442 plugins?: Record<string, Plugin> | null | undefined;
1443 ruleFilter?: ((arg: { ruleId: string; severity: Exclude<Linter.Severity, 0> }) => boolean) | undefined;
1444 stats?: boolean | undefined;
1445
1446 // Autofix
1447 fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
1448 fixTypes?: FixType[] | undefined;
1449
1450 // Cache-related
1451 cache?: boolean | undefined;
1452 cacheLocation?: string | undefined;
1453 cacheStrategy?: CacheStrategy | undefined;
1454
1455 // Other Options
1456 flags?: string[] | undefined;
1457 }
1458
1459 interface LegacyOptions {
1460 // File enumeration
1461 cwd?: string | undefined;
1462 errorOnUnmatchedPattern?: boolean | undefined;
1463 extensions?: string[] | undefined;
1464 globInputPaths?: boolean | undefined;
1465 ignore?: boolean | undefined;
1466 ignorePath?: string | undefined;
1467
1468 // Linting
1469 allowInlineConfig?: boolean | undefined;
1470 baseConfig?: Linter.LegacyConfig | undefined;
1471 overrideConfig?: Linter.LegacyConfig | undefined;
1472 overrideConfigFile?: string | undefined;
1473 plugins?: Record<string, Plugin> | undefined;
1474 reportUnusedDisableDirectives?: Linter.StringSeverity | undefined;
1475 resolvePluginsRelativeTo?: string | undefined;
1476 rulePaths?: string[] | undefined;
1477 useEslintrc?: boolean | undefined;
1478
1479 // Autofix
1480 fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
1481 fixTypes?: FixType[] | undefined;
1482
1483 // Cache-related
1484 cache?: boolean | undefined;
1485 cacheLocation?: string | undefined;
1486 cacheStrategy?: CacheStrategy | undefined;
1487
1488 // Other Options
1489 flags?: string[] | undefined;
1490 }
1491
1492 interface LintResult {
1493 filePath: string;
1494 messages: Linter.LintMessage[];
1495 suppressedMessages: Linter.SuppressedLintMessage[];
1496 errorCount: number;
1497 fatalErrorCount: number;
1498 warningCount: number;
1499 fixableErrorCount: number;
1500 fixableWarningCount: number;
1501 output?: string | undefined;
1502 source?: string | undefined;
1503 stats?: Linter.Stats | undefined;
1504 usedDeprecatedRules: DeprecatedRuleUse[];
1505 }
1506
1507 interface LintResultData {
1508 cwd: string;
1509 rulesMeta: {
1510 [ruleId: string]: Rule.RuleMetaData;
1511 };
1512 }
1513
1514 interface DeprecatedRuleUse {
1515 ruleId: string;
1516 replacedBy: string[];
1517 }
1518
1519 interface Formatter {
1520 format(results: LintResult[], data: LintResultData): string | Promise<string>;
1521 }
1522
1523 // Docs reference the types by those name
1524 type EditInfo = Rule.Fix;
1525 type LoadedFormatter = Formatter;
1526 type ResultsMeta = LintResultData;
1527}
1528
1529// #endregion
1530
1531export function loadESLint(options: { useFlatConfig: true }): Promise<typeof ESLint>;
1532export function loadESLint(options: { useFlatConfig: false }): Promise<typeof LegacyESLint>;
1533export function loadESLint(
1534 options?: { useFlatConfig?: boolean | undefined },
1535): Promise<typeof ESLint | typeof LegacyESLint>;
1536
1537// #region RuleTester
1538
1539export class RuleTester {
1540 static describe: ((...args: any) => any) | null;
1541 static it: ((...args: any) => any) | null;
1542 static itOnly: ((...args: any) => any) | null;
1543
1544 constructor(config?: Linter.Config);
1545
1546 run(
1547 name: string,
1548 rule: Rule.RuleModule,
1549 tests: {
1550 valid: Array<string | RuleTester.ValidTestCase>;
1551 invalid: RuleTester.InvalidTestCase[];
1552 },
1553 ): void;
1554
1555 static only(
1556 item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
1557 ): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
1558}
1559
1560export namespace RuleTester {
1561 interface ValidTestCase {
1562 name?: string;
1563 code: string;
1564 options?: any;
1565 filename?: string | undefined;
1566 only?: boolean;
1567 languageOptions?: Linter.LanguageOptions | undefined;
1568 settings?: { [name: string]: any } | undefined;
1569 }
1570
1571 interface SuggestionOutput {
1572 messageId?: string;
1573 desc?: string;
1574 data?: Record<string, unknown> | undefined;
1575 output: string;
1576 }
1577
1578 interface InvalidTestCase extends ValidTestCase {
1579 errors: number | Array<TestCaseError | string>;
1580 output?: string | null | undefined;
1581 }
1582
1583 interface TestCaseError {
1584 message?: string | RegExp;
1585 messageId?: string;
1586 type?: string | undefined;
1587 data?: any;
1588 line?: number | undefined;
1589 column?: number | undefined;
1590 endLine?: number | undefined;
1591 endColumn?: number | undefined;
1592 suggestions?: SuggestionOutput[] | undefined;
1593 }
1594}
1595
1596// #endregion
1597
\No newline at end of file