UNPKG

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