UNPKG

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