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