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