1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | import * as ESTree from "estree";
|
29 | import 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";
|
40 | import { JSONSchema4 } from "json-schema";
|
41 | import { LegacyESLint } from "./use-at-your-own-risk.js";
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 | declare module "@eslint/core" {
|
49 | interface RuleContext {
|
50 |
|
51 |
|
52 | getAncestors(): ESTree.Node[];
|
53 |
|
54 |
|
55 | getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
|
56 |
|
57 |
|
58 | getScope(): Scope.Scope;
|
59 |
|
60 |
|
61 | markVariableAsUsed(name: string): boolean;
|
62 | }
|
63 | }
|
64 |
|
65 | export 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 |
|
100 | export 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 |
|
183 |
|
184 | export 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 |
|
285 | export 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 |
|
551 | export 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:
|
775 | * so ESLint can prevent invalid [rule configurations](https:
|
776 | * Mandatory for rules with options.
|
777 | */
|
778 | schema?: JSONSchema4 | JSONSchema4[] | false | undefined;
|
779 |
|
780 |
|
781 | defaultOptions?: unknown[];
|
782 |
|
783 |
|
784 | deprecated?: boolean | undefined;
|
785 |
|
786 | replacedBy?: readonly string[];
|
787 |
|
788 | |
789 |
|
790 |
|
791 |
|
792 |
|
793 |
|
794 |
|
795 |
|
796 | type?: "problem" | "suggestion" | "layout" | undefined;
|
797 | |
798 |
|
799 |
|
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 |
|
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 |
|
863 |
|
864 | export 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 |
|
908 | export namespace Linter {
|
909 | |
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 | type Severity = 0 | 1 | 2;
|
919 |
|
920 | |
921 |
|
922 |
|
923 |
|
924 |
|
925 | type StringSeverity = "off" | "warn" | "error";
|
926 |
|
927 | |
928 |
|
929 |
|
930 |
|
931 |
|
932 | type RuleSeverity = Severity | StringSeverity;
|
933 |
|
934 | |
935 |
|
936 |
|
937 |
|
938 |
|
939 | type RuleSeverityAndOptions<Options extends any[] = any[]> = [RuleSeverity, ...Partial<Options>];
|
940 |
|
941 | |
942 |
|
943 |
|
944 |
|
945 |
|
946 | type RuleEntry<Options extends any[] = any[]> = RuleSeverity | RuleSeverityAndOptions<Options>;
|
947 |
|
948 | |
949 |
|
950 |
|
951 | interface RulesRecord {
|
952 | [rule: string]: RuleEntry;
|
953 | }
|
954 |
|
955 | |
956 |
|
957 |
|
958 | interface HasRules<Rules extends RulesRecord = RulesRecord> {
|
959 | rules?: Partial<Rules> | undefined;
|
960 | }
|
961 |
|
962 | |
963 |
|
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 |
|
994 |
|
995 | type SourceType = "script" | "module" | "commonjs";
|
996 |
|
997 | |
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 | interface BaseConfig<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules>
|
1003 | extends HasRules<Rules> {
|
1004 | $schema?: string | undefined;
|
1005 |
|
1006 | |
1007 |
|
1008 |
|
1009 |
|
1010 |
|
1011 | env?: { [name: string]: boolean } | undefined;
|
1012 |
|
1013 | |
1014 |
|
1015 |
|
1016 |
|
1017 |
|
1018 | extends?: string | string[] | undefined;
|
1019 |
|
1020 | |
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 | globals?: Linter.Globals | undefined;
|
1026 |
|
1027 | |
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 | noInlineConfig?: boolean | undefined;
|
1033 |
|
1034 | |
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 | overrides?: Array<ConfigOverride<OverrideRules>> | undefined;
|
1040 |
|
1041 | |
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | parser?: string | undefined;
|
1048 |
|
1049 | |
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 | parserOptions?: ParserOptions | undefined;
|
1056 |
|
1057 | |
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 | plugins?: string[] | undefined;
|
1063 |
|
1064 | |
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 | processor?: string | undefined;
|
1070 |
|
1071 | |
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 | reportUnusedDisableDirectives?: boolean | undefined;
|
1077 |
|
1078 | |
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 | settings?: { [name: string]: any } | undefined;
|
1084 | }
|
1085 |
|
1086 | |
1087 |
|
1088 |
|
1089 | interface ConfigOverride<Rules extends RulesRecord = RulesRecord> extends BaseConfig<Rules> {
|
1090 | |
1091 |
|
1092 |
|
1093 | excludedFiles?: string | string[] | undefined;
|
1094 |
|
1095 | |
1096 |
|
1097 |
|
1098 | files: string | string[];
|
1099 | }
|
1100 |
|
1101 | |
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 | interface LegacyConfig<Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules>
|
1108 | extends BaseConfig<Rules, OverrideRules> {
|
1109 | |
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 | ignorePatterns?: string | string[] | undefined;
|
1115 |
|
1116 | |
1117 |
|
1118 |
|
1119 | root?: boolean | undefined;
|
1120 | }
|
1121 |
|
1122 | |
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 | interface ParserOptions {
|
1128 | |
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 | ecmaVersion?: EcmaVersion | undefined;
|
1142 |
|
1143 | |
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 | sourceType?: SourceType | undefined;
|
1153 |
|
1154 | |
1155 |
|
1156 |
|
1157 |
|
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 |
|
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 |
|
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 |
|
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 |
|
1265 |
|
1266 |
|
1267 | name?: string;
|
1268 |
|
1269 | |
1270 |
|
1271 |
|
1272 |
|
1273 |
|
1274 | files?: Array<string | string[]>;
|
1275 |
|
1276 | |
1277 |
|
1278 |
|
1279 |
|
1280 |
|
1281 | ignores?: string[];
|
1282 |
|
1283 | |
1284 |
|
1285 |
|
1286 |
|
1287 |
|
1288 | language?: string;
|
1289 |
|
1290 | |
1291 |
|
1292 |
|
1293 |
|
1294 | languageOptions?: LanguageOptions;
|
1295 |
|
1296 | |
1297 |
|
1298 |
|
1299 | linterOptions?: LinterOptions;
|
1300 |
|
1301 | |
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 | processor?: string | Processor;
|
1307 |
|
1308 | |
1309 |
|
1310 |
|
1311 |
|
1312 | plugins?: Record<string, ESLint.Plugin>;
|
1313 |
|
1314 | |
1315 |
|
1316 |
|
1317 |
|
1318 | rules?: Partial<Rules>;
|
1319 |
|
1320 | |
1321 |
|
1322 |
|
1323 |
|
1324 | settings?: Record<string, unknown>;
|
1325 | }
|
1326 |
|
1327 |
|
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 |
|
1339 |
|
1340 |
|
1341 |
|
1342 | ecmaVersion?: EcmaVersion | undefined;
|
1343 |
|
1344 | |
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 | sourceType?: SourceType | undefined;
|
1351 |
|
1352 | |
1353 |
|
1354 |
|
1355 |
|
1356 | globals?: Globals | undefined;
|
1357 |
|
1358 | |
1359 |
|
1360 |
|
1361 |
|
1362 | parser?: Parser | undefined;
|
1363 |
|
1364 | |
1365 |
|
1366 |
|
1367 |
|
1368 | parserOptions?: Linter.ParserOptions | undefined;
|
1369 | }
|
1370 |
|
1371 | interface LinterOptions {
|
1372 | |
1373 |
|
1374 |
|
1375 | noInlineConfig?: boolean;
|
1376 |
|
1377 | |
1378 |
|
1379 |
|
1380 |
|
1381 | reportUnusedDisableDirectives?: Severity | StringSeverity | boolean;
|
1382 |
|
1383 | |
1384 |
|
1385 |
|
1386 |
|
1387 | reportUnusedInlineConfigs?: Severity | StringSeverity;
|
1388 | }
|
1389 |
|
1390 | interface Stats {
|
1391 | |
1392 |
|
1393 |
|
1394 | fixPasses: number;
|
1395 |
|
1396 | |
1397 |
|
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 |
|
1411 |
|
1412 |
|
1413 |
|
1414 | export class ESLint {
|
1415 | static configType: "flat";
|
1416 |
|
1417 | static readonly version: string;
|
1418 |
|
1419 | |
1420 |
|
1421 |
|
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 |
|
1451 | export 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 |
|
1464 | name?: string | undefined;
|
1465 |
|
1466 |
|
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 |
|
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 |
|
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 |
|
1507 | fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
|
1508 | fixTypes?: FixType[] | undefined;
|
1509 |
|
1510 |
|
1511 | cache?: boolean | undefined;
|
1512 | cacheLocation?: string | undefined;
|
1513 | cacheStrategy?: CacheStrategy | undefined;
|
1514 |
|
1515 |
|
1516 | flags?: string[] | undefined;
|
1517 | }
|
1518 |
|
1519 | interface LegacyOptions {
|
1520 |
|
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 |
|
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 |
|
1540 | fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
|
1541 | fixTypes?: FixType[] | undefined;
|
1542 |
|
1543 |
|
1544 | cache?: boolean | undefined;
|
1545 | cacheLocation?: string | undefined;
|
1546 | cacheStrategy?: CacheStrategy | undefined;
|
1547 |
|
1548 |
|
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 |
|
1571 |
|
1572 | maxWarnings: number;
|
1573 |
|
1574 | |
1575 |
|
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 |
|
1598 | interface LoadedFormatter {
|
1599 |
|
1600 | |
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 | format(results: LintResult[], resultsMeta?: ResultsMeta): string | Promise<string>;
|
1609 | }
|
1610 |
|
1611 |
|
1612 | type Formatter = LoadedFormatter;
|
1613 |
|
1614 | |
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 | type FormatterFunction =
|
1621 | (results: LintResult[], context: LintResultData) => string | Promise<string>;
|
1622 |
|
1623 |
|
1624 | type EditInfo = Rule.Fix;
|
1625 | }
|
1626 |
|
1627 |
|
1628 |
|
1629 | export function loadESLint(options: { useFlatConfig: true }): Promise<typeof ESLint>;
|
1630 | export function loadESLint(options: { useFlatConfig: false }): Promise<typeof LegacyESLint>;
|
1631 | export function loadESLint(
|
1632 | options?: { useFlatConfig?: boolean | undefined },
|
1633 | ): Promise<typeof ESLint | typeof LegacyESLint>;
|
1634 |
|
1635 |
|
1636 |
|
1637 | export 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 |
|
1658 | export 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 |
|
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 |
|
1698 |
|
\ | No newline at end of file |