[e29cc2e] | 1 | // Type definitions for eslint 8.2
|
---|
[6a3a178] | 2 | // Project: https://eslint.org
|
---|
| 3 | // Definitions by: Pierre-Marie Dartus <https://github.com/pmdartus>
|
---|
| 4 | // Jed Fox <https://github.com/j-f1>
|
---|
| 5 | // Saad Quadri <https://github.com/saadq>
|
---|
| 6 | // Jason Kwok <https://github.com/JasonHK>
|
---|
| 7 | // Brad Zacher <https://github.com/bradzacher>
|
---|
| 8 | // JounQin <https://github.com/JounQin>
|
---|
| 9 | // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
---|
| 10 |
|
---|
| 11 | /// <reference path="helpers.d.ts" />
|
---|
| 12 |
|
---|
| 13 | import { JSONSchema4 } from "json-schema";
|
---|
| 14 | import * as ESTree from "estree";
|
---|
| 15 |
|
---|
| 16 | export namespace AST {
|
---|
| 17 | type TokenType =
|
---|
| 18 | | "Boolean"
|
---|
| 19 | | "Null"
|
---|
| 20 | | "Identifier"
|
---|
| 21 | | "Keyword"
|
---|
| 22 | | "Punctuator"
|
---|
| 23 | | "JSXIdentifier"
|
---|
| 24 | | "JSXText"
|
---|
| 25 | | "Numeric"
|
---|
| 26 | | "String"
|
---|
| 27 | | "RegularExpression";
|
---|
| 28 |
|
---|
| 29 | interface Token {
|
---|
| 30 | type: TokenType;
|
---|
| 31 | value: string;
|
---|
| 32 | range: Range;
|
---|
| 33 | loc: SourceLocation;
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | interface SourceLocation {
|
---|
| 37 | start: ESTree.Position;
|
---|
| 38 | end: ESTree.Position;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | type Range = [number, number];
|
---|
| 42 |
|
---|
| 43 | interface Program extends ESTree.Program {
|
---|
| 44 | comments: ESTree.Comment[];
|
---|
| 45 | tokens: Token[];
|
---|
| 46 | loc: SourceLocation;
|
---|
| 47 | range: Range;
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | export namespace Scope {
|
---|
| 52 | interface ScopeManager {
|
---|
| 53 | scopes: Scope[];
|
---|
| 54 | globalScope: Scope | null;
|
---|
| 55 |
|
---|
| 56 | acquire(node: ESTree.Node, inner?: boolean): Scope | null;
|
---|
| 57 |
|
---|
| 58 | getDeclaredVariables(node: ESTree.Node): Variable[];
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | interface Scope {
|
---|
| 62 | type:
|
---|
| 63 | | "block"
|
---|
| 64 | | "catch"
|
---|
| 65 | | "class"
|
---|
| 66 | | "for"
|
---|
| 67 | | "function"
|
---|
| 68 | | "function-expression-name"
|
---|
| 69 | | "global"
|
---|
| 70 | | "module"
|
---|
| 71 | | "switch"
|
---|
| 72 | | "with"
|
---|
| 73 | | "TDZ";
|
---|
| 74 | isStrict: boolean;
|
---|
| 75 | upper: Scope | null;
|
---|
| 76 | childScopes: Scope[];
|
---|
| 77 | variableScope: Scope;
|
---|
| 78 | block: ESTree.Node;
|
---|
| 79 | variables: Variable[];
|
---|
| 80 | set: Map<string, Variable>;
|
---|
| 81 | references: Reference[];
|
---|
| 82 | through: Reference[];
|
---|
| 83 | functionExpressionScope: boolean;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | interface Variable {
|
---|
| 87 | name: string;
|
---|
| 88 | identifiers: ESTree.Identifier[];
|
---|
| 89 | references: Reference[];
|
---|
| 90 | defs: Definition[];
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | interface Reference {
|
---|
| 94 | identifier: ESTree.Identifier;
|
---|
| 95 | from: Scope;
|
---|
| 96 | resolved: Variable | null;
|
---|
| 97 | writeExpr: ESTree.Node | null;
|
---|
| 98 | init: boolean;
|
---|
| 99 |
|
---|
| 100 | isWrite(): boolean;
|
---|
| 101 |
|
---|
| 102 | isRead(): boolean;
|
---|
| 103 |
|
---|
| 104 | isWriteOnly(): boolean;
|
---|
| 105 |
|
---|
| 106 | isReadOnly(): boolean;
|
---|
| 107 |
|
---|
| 108 | isReadWrite(): boolean;
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | type DefinitionType =
|
---|
| 112 | | { type: "CatchClause"; node: ESTree.CatchClause; parent: null }
|
---|
| 113 | | { type: "ClassName"; node: ESTree.ClassDeclaration | ESTree.ClassExpression; parent: null }
|
---|
| 114 | | { type: "FunctionName"; node: ESTree.FunctionDeclaration | ESTree.FunctionExpression; parent: null }
|
---|
| 115 | | { type: "ImplicitGlobalVariable"; node: ESTree.Program; parent: null }
|
---|
| 116 | | {
|
---|
| 117 | type: "ImportBinding";
|
---|
| 118 | node: ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier;
|
---|
| 119 | parent: ESTree.ImportDeclaration;
|
---|
| 120 | }
|
---|
| 121 | | {
|
---|
| 122 | type: "Parameter";
|
---|
| 123 | node: ESTree.FunctionDeclaration | ESTree.FunctionExpression | ESTree.ArrowFunctionExpression;
|
---|
| 124 | parent: null;
|
---|
| 125 | }
|
---|
| 126 | | { type: "TDZ"; node: any; parent: null }
|
---|
| 127 | | { type: "Variable"; node: ESTree.VariableDeclarator; parent: ESTree.VariableDeclaration };
|
---|
| 128 |
|
---|
| 129 | type Definition = DefinitionType & { name: ESTree.Identifier };
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | //#region SourceCode
|
---|
| 133 |
|
---|
| 134 | export class SourceCode {
|
---|
| 135 | text: string;
|
---|
| 136 | ast: AST.Program;
|
---|
| 137 | lines: string[];
|
---|
| 138 | hasBOM: boolean;
|
---|
| 139 | parserServices: SourceCode.ParserServices;
|
---|
| 140 | scopeManager: Scope.ScopeManager;
|
---|
| 141 | visitorKeys: SourceCode.VisitorKeys;
|
---|
| 142 |
|
---|
| 143 | constructor(text: string, ast: AST.Program);
|
---|
| 144 | constructor(config: SourceCode.Config);
|
---|
| 145 |
|
---|
| 146 | static splitLines(text: string): string[];
|
---|
| 147 |
|
---|
| 148 | getText(node?: ESTree.Node, beforeCount?: number, afterCount?: number): string;
|
---|
| 149 |
|
---|
| 150 | getLines(): string[];
|
---|
| 151 |
|
---|
| 152 | getAllComments(): ESTree.Comment[];
|
---|
| 153 |
|
---|
| 154 | getComments(node: ESTree.Node): { leading: ESTree.Comment[]; trailing: ESTree.Comment[] };
|
---|
| 155 |
|
---|
| 156 | getJSDocComment(node: ESTree.Node): ESTree.Comment | null;
|
---|
| 157 |
|
---|
| 158 | getNodeByRangeIndex(index: number): ESTree.Node | null;
|
---|
| 159 |
|
---|
| 160 | isSpaceBetweenTokens(first: AST.Token, second: AST.Token): boolean;
|
---|
| 161 |
|
---|
| 162 | getLocFromIndex(index: number): ESTree.Position;
|
---|
| 163 |
|
---|
| 164 | getIndexFromLoc(location: ESTree.Position): number;
|
---|
| 165 |
|
---|
| 166 | // Inherited methods from TokenStore
|
---|
| 167 | // ---------------------------------
|
---|
| 168 |
|
---|
| 169 | getTokenByRangeStart(offset: number, options?: { includeComments: false }): AST.Token | null;
|
---|
| 170 | getTokenByRangeStart(offset: number, options: { includeComments: boolean }): AST.Token | ESTree.Comment | null;
|
---|
| 171 |
|
---|
| 172 | getFirstToken: SourceCode.UnaryNodeCursorWithSkipOptions;
|
---|
| 173 |
|
---|
| 174 | getFirstTokens: SourceCode.UnaryNodeCursorWithCountOptions;
|
---|
| 175 |
|
---|
| 176 | getLastToken: SourceCode.UnaryNodeCursorWithSkipOptions;
|
---|
| 177 |
|
---|
| 178 | getLastTokens: SourceCode.UnaryNodeCursorWithCountOptions;
|
---|
| 179 |
|
---|
| 180 | getTokenBefore: SourceCode.UnaryCursorWithSkipOptions;
|
---|
| 181 |
|
---|
| 182 | getTokensBefore: SourceCode.UnaryCursorWithCountOptions;
|
---|
| 183 |
|
---|
| 184 | getTokenAfter: SourceCode.UnaryCursorWithSkipOptions;
|
---|
| 185 |
|
---|
| 186 | getTokensAfter: SourceCode.UnaryCursorWithCountOptions;
|
---|
| 187 |
|
---|
| 188 | getFirstTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
|
---|
| 189 |
|
---|
| 190 | getFirstTokensBetween: SourceCode.BinaryCursorWithCountOptions;
|
---|
| 191 |
|
---|
| 192 | getLastTokenBetween: SourceCode.BinaryCursorWithSkipOptions;
|
---|
| 193 |
|
---|
| 194 | getLastTokensBetween: SourceCode.BinaryCursorWithCountOptions;
|
---|
| 195 |
|
---|
| 196 | getTokensBetween: SourceCode.BinaryCursorWithCountOptions;
|
---|
| 197 |
|
---|
| 198 | getTokens: ((node: ESTree.Node, beforeCount?: number, afterCount?: number) => AST.Token[]) &
|
---|
| 199 | SourceCode.UnaryNodeCursorWithCountOptions;
|
---|
| 200 |
|
---|
| 201 | commentsExistBetween(
|
---|
| 202 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 203 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 204 | ): boolean;
|
---|
| 205 |
|
---|
| 206 | getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
|
---|
| 207 |
|
---|
| 208 | getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[];
|
---|
| 209 |
|
---|
| 210 | getCommentsInside(node: ESTree.Node): ESTree.Comment[];
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | export namespace SourceCode {
|
---|
| 214 | interface Config {
|
---|
| 215 | text: string;
|
---|
| 216 | ast: AST.Program;
|
---|
| 217 | parserServices?: ParserServices | undefined;
|
---|
| 218 | scopeManager?: Scope.ScopeManager | undefined;
|
---|
| 219 | visitorKeys?: VisitorKeys | undefined;
|
---|
| 220 | }
|
---|
| 221 |
|
---|
| 222 | type ParserServices = any;
|
---|
| 223 |
|
---|
| 224 | interface VisitorKeys {
|
---|
| 225 | [nodeType: string]: string[];
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | interface UnaryNodeCursorWithSkipOptions {
|
---|
| 229 | <T extends AST.Token>(
|
---|
| 230 | node: ESTree.Node,
|
---|
| 231 | options:
|
---|
| 232 | | ((token: AST.Token) => token is T)
|
---|
| 233 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
|
---|
| 234 | ): T | null;
|
---|
| 235 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 236 | node: ESTree.Node,
|
---|
| 237 | options: {
|
---|
| 238 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 239 | includeComments: boolean;
|
---|
| 240 | skip?: number | undefined;
|
---|
| 241 | },
|
---|
| 242 | ): T | null;
|
---|
| 243 | (
|
---|
| 244 | node: ESTree.Node,
|
---|
| 245 | options?:
|
---|
| 246 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
|
---|
| 247 | | ((token: AST.Token) => boolean)
|
---|
| 248 | | number,
|
---|
| 249 | ): AST.Token | null;
|
---|
| 250 | (
|
---|
| 251 | node: ESTree.Node,
|
---|
| 252 | options: {
|
---|
| 253 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 254 | includeComments: boolean;
|
---|
| 255 | skip?: number | undefined;
|
---|
| 256 | },
|
---|
| 257 | ): AST.Token | ESTree.Comment | null;
|
---|
| 258 | }
|
---|
| 259 |
|
---|
| 260 | interface UnaryNodeCursorWithCountOptions {
|
---|
| 261 | <T extends AST.Token>(
|
---|
| 262 | node: ESTree.Node,
|
---|
| 263 | options:
|
---|
| 264 | | ((token: AST.Token) => token is T)
|
---|
| 265 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
|
---|
| 266 | ): T[];
|
---|
| 267 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 268 | node: ESTree.Node,
|
---|
| 269 | options: {
|
---|
| 270 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 271 | includeComments: boolean;
|
---|
| 272 | count?: number | undefined;
|
---|
| 273 | },
|
---|
| 274 | ): T[];
|
---|
| 275 | (
|
---|
| 276 | node: ESTree.Node,
|
---|
| 277 | options?:
|
---|
| 278 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
|
---|
| 279 | | ((token: AST.Token) => boolean)
|
---|
| 280 | | number,
|
---|
| 281 | ): AST.Token[];
|
---|
| 282 | (
|
---|
| 283 | node: ESTree.Node,
|
---|
| 284 | options: {
|
---|
| 285 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 286 | includeComments: boolean;
|
---|
| 287 | count?: number | undefined;
|
---|
| 288 | },
|
---|
| 289 | ): Array<AST.Token | ESTree.Comment>;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 | interface UnaryCursorWithSkipOptions {
|
---|
| 293 | <T extends AST.Token>(
|
---|
| 294 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 295 | options:
|
---|
| 296 | | ((token: AST.Token) => token is T)
|
---|
| 297 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
|
---|
| 298 | ): T | null;
|
---|
| 299 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 300 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 301 | options: {
|
---|
| 302 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 303 | includeComments: boolean;
|
---|
| 304 | skip?: number | undefined;
|
---|
| 305 | },
|
---|
| 306 | ): T | null;
|
---|
| 307 | (
|
---|
| 308 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 309 | options?:
|
---|
| 310 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
|
---|
| 311 | | ((token: AST.Token) => boolean)
|
---|
| 312 | | number,
|
---|
| 313 | ): AST.Token | null;
|
---|
| 314 | (
|
---|
| 315 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 316 | options: {
|
---|
| 317 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 318 | includeComments: boolean;
|
---|
| 319 | skip?: number | undefined;
|
---|
| 320 | },
|
---|
| 321 | ): AST.Token | ESTree.Comment | null;
|
---|
| 322 | }
|
---|
| 323 |
|
---|
| 324 | interface UnaryCursorWithCountOptions {
|
---|
| 325 | <T extends AST.Token>(
|
---|
| 326 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 327 | options:
|
---|
| 328 | | ((token: AST.Token) => token is T)
|
---|
| 329 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
|
---|
| 330 | ): T[];
|
---|
| 331 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 332 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 333 | options: {
|
---|
| 334 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 335 | includeComments: boolean;
|
---|
| 336 | count?: number | undefined;
|
---|
| 337 | },
|
---|
| 338 | ): T[];
|
---|
| 339 | (
|
---|
| 340 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 341 | options?:
|
---|
| 342 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
|
---|
| 343 | | ((token: AST.Token) => boolean)
|
---|
| 344 | | number,
|
---|
| 345 | ): AST.Token[];
|
---|
| 346 | (
|
---|
| 347 | node: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 348 | options: {
|
---|
| 349 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 350 | includeComments: boolean;
|
---|
| 351 | count?: number | undefined;
|
---|
| 352 | },
|
---|
| 353 | ): Array<AST.Token | ESTree.Comment>;
|
---|
| 354 | }
|
---|
| 355 |
|
---|
| 356 | interface BinaryCursorWithSkipOptions {
|
---|
| 357 | <T extends AST.Token>(
|
---|
| 358 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 359 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 360 | options:
|
---|
| 361 | | ((token: AST.Token) => token is T)
|
---|
| 362 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined },
|
---|
| 363 | ): T | null;
|
---|
| 364 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 365 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 366 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 367 | options: {
|
---|
| 368 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 369 | includeComments: boolean;
|
---|
| 370 | skip?: number | undefined;
|
---|
| 371 | },
|
---|
| 372 | ): T | null;
|
---|
| 373 | (
|
---|
| 374 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 375 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 376 | options?:
|
---|
| 377 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined }
|
---|
| 378 | | ((token: AST.Token) => boolean)
|
---|
| 379 | | number,
|
---|
| 380 | ): AST.Token | null;
|
---|
| 381 | (
|
---|
| 382 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 383 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 384 | options: {
|
---|
| 385 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 386 | includeComments: boolean;
|
---|
| 387 | skip?: number | undefined;
|
---|
| 388 | },
|
---|
| 389 | ): AST.Token | ESTree.Comment | null;
|
---|
| 390 | }
|
---|
| 391 |
|
---|
| 392 | interface BinaryCursorWithCountOptions {
|
---|
| 393 | <T extends AST.Token>(
|
---|
| 394 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 395 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 396 | options:
|
---|
| 397 | | ((token: AST.Token) => token is T)
|
---|
| 398 | | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined },
|
---|
| 399 | ): T[];
|
---|
| 400 | <T extends AST.Token | ESTree.Comment>(
|
---|
| 401 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 402 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 403 | options: {
|
---|
| 404 | filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T;
|
---|
| 405 | includeComments: boolean;
|
---|
| 406 | count?: number | undefined;
|
---|
| 407 | },
|
---|
| 408 | ): T[];
|
---|
| 409 | (
|
---|
| 410 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 411 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 412 | options?:
|
---|
| 413 | | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined }
|
---|
| 414 | | ((token: AST.Token) => boolean)
|
---|
| 415 | | number,
|
---|
| 416 | ): AST.Token[];
|
---|
| 417 | (
|
---|
| 418 | left: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 419 | right: ESTree.Node | AST.Token | ESTree.Comment,
|
---|
| 420 | options: {
|
---|
| 421 | filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined;
|
---|
| 422 | includeComments: boolean;
|
---|
| 423 | count?: number | undefined;
|
---|
| 424 | },
|
---|
| 425 | ): Array<AST.Token | ESTree.Comment>;
|
---|
| 426 | }
|
---|
| 427 | }
|
---|
| 428 |
|
---|
| 429 | //#endregion
|
---|
| 430 |
|
---|
| 431 | export namespace Rule {
|
---|
| 432 | interface RuleModule {
|
---|
| 433 | create(context: RuleContext): RuleListener;
|
---|
| 434 | meta?: RuleMetaData | undefined;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | type NodeTypes = ESTree.Node["type"];
|
---|
| 438 | interface NodeListener {
|
---|
| 439 | ArrayExpression?: ((node: ESTree.ArrayExpression & NodeParentExtension) => void) | undefined;
|
---|
| 440 | ArrayPattern?: ((node: ESTree.ArrayPattern & NodeParentExtension) => void) | undefined;
|
---|
| 441 | ArrowFunctionExpression?: ((node: ESTree.ArrowFunctionExpression & NodeParentExtension) => void) | undefined;
|
---|
| 442 | AssignmentExpression?: ((node: ESTree.AssignmentExpression & NodeParentExtension) => void) | undefined;
|
---|
| 443 | AssignmentPattern?: ((node: ESTree.AssignmentPattern & NodeParentExtension) => void) | undefined;
|
---|
| 444 | AwaitExpression?: ((node: ESTree.AwaitExpression & NodeParentExtension) => void) | undefined;
|
---|
| 445 | BinaryExpression?: ((node: ESTree.BinaryExpression & NodeParentExtension) => void) | undefined;
|
---|
| 446 | BlockStatement?: ((node: ESTree.BlockStatement & NodeParentExtension) => void) | undefined;
|
---|
| 447 | BreakStatement?: ((node: ESTree.BreakStatement & NodeParentExtension) => void) | undefined;
|
---|
| 448 | CallExpression?: ((node: ESTree.CallExpression & NodeParentExtension) => void) | undefined;
|
---|
| 449 | CatchClause?: ((node: ESTree.CatchClause & NodeParentExtension) => void) | undefined;
|
---|
| 450 | ChainExpression?: ((node: ESTree.ChainExpression & NodeParentExtension) => void) | undefined;
|
---|
| 451 | ClassBody?: ((node: ESTree.ClassBody & NodeParentExtension) => void) | undefined;
|
---|
| 452 | ClassDeclaration?: ((node: ESTree.ClassDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 453 | ClassExpression?: ((node: ESTree.ClassExpression & NodeParentExtension) => void) | undefined;
|
---|
| 454 | ConditionalExpression?: ((node: ESTree.ConditionalExpression & NodeParentExtension) => void) | undefined;
|
---|
| 455 | ContinueStatement?: ((node: ESTree.ContinueStatement & NodeParentExtension) => void) | undefined;
|
---|
| 456 | DebuggerStatement?: ((node: ESTree.DebuggerStatement & NodeParentExtension) => void) | undefined;
|
---|
| 457 | DoWhileStatement?: ((node: ESTree.DoWhileStatement & NodeParentExtension) => void) | undefined;
|
---|
| 458 | EmptyStatement?: ((node: ESTree.EmptyStatement & NodeParentExtension) => void) | undefined;
|
---|
| 459 | ExportAllDeclaration?: ((node: ESTree.ExportAllDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 460 | ExportDefaultDeclaration?: ((node: ESTree.ExportDefaultDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 461 | ExportNamedDeclaration?: ((node: ESTree.ExportNamedDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 462 | ExportSpecifier?: ((node: ESTree.ExportSpecifier & NodeParentExtension) => void) | undefined;
|
---|
| 463 | ExpressionStatement?: ((node: ESTree.ExpressionStatement & NodeParentExtension) => void) | undefined;
|
---|
| 464 | ForInStatement?: ((node: ESTree.ForInStatement & NodeParentExtension) => void) | undefined;
|
---|
| 465 | ForOfStatement?: ((node: ESTree.ForOfStatement & NodeParentExtension) => void) | undefined;
|
---|
| 466 | ForStatement?: ((node: ESTree.ForStatement & NodeParentExtension) => void) | undefined;
|
---|
| 467 | FunctionDeclaration?: ((node: ESTree.FunctionDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 468 | FunctionExpression?: ((node: ESTree.FunctionExpression & NodeParentExtension) => void) | undefined;
|
---|
| 469 | Identifier?: ((node: ESTree.Identifier & NodeParentExtension) => void) | undefined;
|
---|
| 470 | IfStatement?: ((node: ESTree.IfStatement & NodeParentExtension) => void) | undefined;
|
---|
| 471 | ImportDeclaration?: ((node: ESTree.ImportDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 472 | ImportDefaultSpecifier?: ((node: ESTree.ImportDefaultSpecifier & NodeParentExtension) => void) | undefined;
|
---|
| 473 | ImportExpression?: ((node: ESTree.ImportExpression & NodeParentExtension) => void) | undefined;
|
---|
| 474 | ImportNamespaceSpecifier?: ((node: ESTree.ImportNamespaceSpecifier & NodeParentExtension) => void) | undefined;
|
---|
| 475 | ImportSpecifier?: ((node: ESTree.ImportSpecifier & NodeParentExtension) => void) | undefined;
|
---|
| 476 | LabeledStatement?: ((node: ESTree.LabeledStatement & NodeParentExtension) => void) | undefined;
|
---|
| 477 | Literal?: ((node: ESTree.Literal & NodeParentExtension) => void) | undefined;
|
---|
| 478 | LogicalExpression?: ((node: ESTree.LogicalExpression & NodeParentExtension) => void) | undefined;
|
---|
| 479 | MemberExpression?: ((node: ESTree.MemberExpression & NodeParentExtension) => void) | undefined;
|
---|
| 480 | MetaProperty?: ((node: ESTree.MetaProperty & NodeParentExtension) => void) | undefined;
|
---|
| 481 | MethodDefinition?: ((node: ESTree.MethodDefinition & NodeParentExtension) => void) | undefined;
|
---|
| 482 | NewExpression?: ((node: ESTree.NewExpression & NodeParentExtension) => void) | undefined;
|
---|
| 483 | ObjectExpression?: ((node: ESTree.ObjectExpression & NodeParentExtension) => void) | undefined;
|
---|
| 484 | ObjectPattern?: ((node: ESTree.ObjectPattern & NodeParentExtension) => void) | undefined;
|
---|
| 485 | Program?: ((node: ESTree.Program) => void) | undefined;
|
---|
| 486 | Property?: ((node: ESTree.Property & NodeParentExtension) => void) | undefined;
|
---|
| 487 | RestElement?: ((node: ESTree.RestElement & NodeParentExtension) => void) | undefined;
|
---|
| 488 | ReturnStatement?: ((node: ESTree.ReturnStatement & NodeParentExtension) => void) | undefined;
|
---|
| 489 | SequenceExpression?: ((node: ESTree.SequenceExpression & NodeParentExtension) => void) | undefined;
|
---|
| 490 | SpreadElement?: ((node: ESTree.SpreadElement & NodeParentExtension) => void) | undefined;
|
---|
| 491 | Super?: ((node: ESTree.Super & NodeParentExtension) => void) | undefined;
|
---|
| 492 | SwitchCase?: ((node: ESTree.SwitchCase & NodeParentExtension) => void) | undefined;
|
---|
| 493 | SwitchStatement?: ((node: ESTree.SwitchStatement & NodeParentExtension) => void) | undefined;
|
---|
| 494 | TaggedTemplateExpression?: ((node: ESTree.TaggedTemplateExpression & NodeParentExtension) => void) | undefined;
|
---|
| 495 | TemplateElement?: ((node: ESTree.TemplateElement & NodeParentExtension) => void) | undefined;
|
---|
| 496 | TemplateLiteral?: ((node: ESTree.TemplateLiteral & NodeParentExtension) => void) | undefined;
|
---|
| 497 | ThisExpression?: ((node: ESTree.ThisExpression & NodeParentExtension) => void) | undefined;
|
---|
| 498 | ThrowStatement?: ((node: ESTree.ThrowStatement & NodeParentExtension) => void) | undefined;
|
---|
| 499 | TryStatement?: ((node: ESTree.TryStatement & NodeParentExtension) => void) | undefined;
|
---|
| 500 | UnaryExpression?: ((node: ESTree.UnaryExpression & NodeParentExtension) => void) | undefined;
|
---|
| 501 | UpdateExpression?: ((node: ESTree.UpdateExpression & NodeParentExtension) => void) | undefined;
|
---|
| 502 | VariableDeclaration?: ((node: ESTree.VariableDeclaration & NodeParentExtension) => void) | undefined;
|
---|
| 503 | VariableDeclarator?: ((node: ESTree.VariableDeclarator & NodeParentExtension) => void) | undefined;
|
---|
| 504 | WhileStatement?: ((node: ESTree.WhileStatement & NodeParentExtension) => void) | undefined;
|
---|
| 505 | WithStatement?: ((node: ESTree.WithStatement & NodeParentExtension) => void) | undefined;
|
---|
| 506 | YieldExpression?: ((node: ESTree.YieldExpression & NodeParentExtension) => void) | undefined;
|
---|
| 507 | }
|
---|
| 508 |
|
---|
| 509 | interface NodeParentExtension {
|
---|
| 510 | parent: Node;
|
---|
| 511 | }
|
---|
| 512 | type Node = ESTree.Node & NodeParentExtension;
|
---|
| 513 |
|
---|
| 514 | interface RuleListener extends NodeListener {
|
---|
| 515 | onCodePathStart?(codePath: CodePath, node: Node): void;
|
---|
| 516 |
|
---|
| 517 | onCodePathEnd?(codePath: CodePath, node: Node): void;
|
---|
| 518 |
|
---|
| 519 | onCodePathSegmentStart?(segment: CodePathSegment, node: Node): void;
|
---|
| 520 |
|
---|
| 521 | onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void;
|
---|
| 522 |
|
---|
| 523 | onCodePathSegmentLoop?(fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node): void;
|
---|
| 524 |
|
---|
| 525 | [key: string]:
|
---|
| 526 | | ((codePath: CodePath, node: Node) => void)
|
---|
| 527 | | ((segment: CodePathSegment, node: Node) => void)
|
---|
| 528 | | ((fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node) => void)
|
---|
| 529 | | ((node: Node) => void)
|
---|
| 530 | | NodeListener[keyof NodeListener]
|
---|
| 531 | | undefined;
|
---|
| 532 | }
|
---|
| 533 |
|
---|
| 534 | interface CodePath {
|
---|
| 535 | id: string;
|
---|
| 536 | initialSegment: CodePathSegment;
|
---|
| 537 | finalSegments: CodePathSegment[];
|
---|
| 538 | returnedSegments: CodePathSegment[];
|
---|
| 539 | thrownSegments: CodePathSegment[];
|
---|
| 540 | currentSegments: CodePathSegment[];
|
---|
| 541 | upper: CodePath | null;
|
---|
| 542 | childCodePaths: CodePath[];
|
---|
| 543 | }
|
---|
| 544 |
|
---|
| 545 | interface CodePathSegment {
|
---|
| 546 | id: string;
|
---|
| 547 | nextSegments: CodePathSegment[];
|
---|
| 548 | prevSegments: CodePathSegment[];
|
---|
| 549 | reachable: boolean;
|
---|
| 550 | }
|
---|
| 551 |
|
---|
| 552 | interface RuleMetaData {
|
---|
| 553 | docs?: {
|
---|
| 554 | /** provides the short description of the rule in the [rules index](https://eslint.org/docs/rules/) */
|
---|
| 555 | description?: string | undefined;
|
---|
| 556 | /** specifies the heading under which the rule is listed in the [rules index](https://eslint.org/docs/rules/) */
|
---|
| 557 | category?: string | undefined;
|
---|
| 558 | /** is whether the `"extends": "eslint:recommended"` property in a [configuration file](https://eslint.org/docs/user-guide/configuring#extending-configuration-files) enables the rule */
|
---|
| 559 | recommended?: boolean | undefined;
|
---|
| 560 | /** specifies the URL at which the full documentation can be accessed */
|
---|
| 561 | url?: string | undefined;
|
---|
| 562 | /** specifies whether rules can return suggestions (defaults to false if omitted) */
|
---|
| 563 | suggestion?: boolean | undefined;
|
---|
| 564 | } | undefined;
|
---|
| 565 | messages?: { [messageId: string]: string } | undefined;
|
---|
| 566 | fixable?: "code" | "whitespace" | undefined;
|
---|
| 567 | schema?: JSONSchema4 | JSONSchema4[] | undefined;
|
---|
| 568 | deprecated?: boolean | undefined;
|
---|
| 569 | type?: "problem" | "suggestion" | "layout" | undefined;
|
---|
| 570 | }
|
---|
| 571 |
|
---|
| 572 | interface RuleContext {
|
---|
| 573 | id: string;
|
---|
| 574 | options: any[];
|
---|
| 575 | settings: { [name: string]: any };
|
---|
| 576 | parserPath: string;
|
---|
| 577 | parserOptions: Linter.ParserOptions;
|
---|
| 578 | parserServices: SourceCode.ParserServices;
|
---|
| 579 |
|
---|
| 580 | getAncestors(): ESTree.Node[];
|
---|
| 581 |
|
---|
| 582 | getDeclaredVariables(node: ESTree.Node): Scope.Variable[];
|
---|
| 583 |
|
---|
| 584 | getFilename(): string;
|
---|
| 585 |
|
---|
| 586 | getPhysicalFilename(): string;
|
---|
| 587 |
|
---|
| 588 | getCwd(): string;
|
---|
| 589 |
|
---|
| 590 | getScope(): Scope.Scope;
|
---|
| 591 |
|
---|
| 592 | getSourceCode(): SourceCode;
|
---|
| 593 |
|
---|
| 594 | markVariableAsUsed(name: string): boolean;
|
---|
| 595 |
|
---|
| 596 | report(descriptor: ReportDescriptor): void;
|
---|
| 597 | }
|
---|
| 598 |
|
---|
| 599 | type ReportFixer = (fixer: RuleFixer) => null | Fix | IterableIterator<Fix> | Fix[];
|
---|
| 600 |
|
---|
| 601 | interface ReportDescriptorOptionsBase {
|
---|
| 602 | data?: { [key: string]: string };
|
---|
| 603 |
|
---|
| 604 | fix?: null | ReportFixer;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | interface SuggestionReportOptions {
|
---|
| 608 | data?: { [key: string]: string };
|
---|
| 609 |
|
---|
| 610 | fix: ReportFixer;
|
---|
| 611 | }
|
---|
| 612 |
|
---|
| 613 | type SuggestionDescriptorMessage = { desc: string } | { messageId: string };
|
---|
| 614 | type SuggestionReportDescriptor = SuggestionDescriptorMessage & SuggestionReportOptions;
|
---|
| 615 |
|
---|
| 616 | interface ReportDescriptorOptions extends ReportDescriptorOptionsBase {
|
---|
| 617 | suggest?: SuggestionReportDescriptor[] | null | undefined;
|
---|
| 618 | }
|
---|
| 619 |
|
---|
| 620 | type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
|
---|
| 621 | type ReportDescriptorMessage = { message: string } | { messageId: string };
|
---|
| 622 | type ReportDescriptorLocation =
|
---|
| 623 | | { node: ESTree.Node }
|
---|
| 624 | | { loc: AST.SourceLocation | { line: number; column: number } };
|
---|
| 625 |
|
---|
| 626 | interface RuleFixer {
|
---|
| 627 | insertTextAfter(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
|
---|
| 628 |
|
---|
| 629 | insertTextAfterRange(range: AST.Range, text: string): Fix;
|
---|
| 630 |
|
---|
| 631 | insertTextBefore(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
|
---|
| 632 |
|
---|
| 633 | insertTextBeforeRange(range: AST.Range, text: string): Fix;
|
---|
| 634 |
|
---|
| 635 | remove(nodeOrToken: ESTree.Node | AST.Token): Fix;
|
---|
| 636 |
|
---|
| 637 | removeRange(range: AST.Range): Fix;
|
---|
| 638 |
|
---|
| 639 | replaceText(nodeOrToken: ESTree.Node | AST.Token, text: string): Fix;
|
---|
| 640 |
|
---|
| 641 | replaceTextRange(range: AST.Range, text: string): Fix;
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | interface Fix {
|
---|
| 645 | range: AST.Range;
|
---|
| 646 | text: string;
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 |
|
---|
| 650 | //#region Linter
|
---|
| 651 |
|
---|
| 652 | export class Linter {
|
---|
| 653 | static version: string;
|
---|
| 654 |
|
---|
| 655 | version: string;
|
---|
| 656 |
|
---|
| 657 | constructor(options?: { cwd?: string | undefined });
|
---|
| 658 |
|
---|
| 659 | verify(code: SourceCode | string, config: Linter.Config, filename?: string): Linter.LintMessage[];
|
---|
| 660 | verify(code: SourceCode | string, config: Linter.Config, options: Linter.LintOptions): Linter.LintMessage[];
|
---|
| 661 |
|
---|
| 662 | verifyAndFix(code: string, config: Linter.Config, filename?: string): Linter.FixReport;
|
---|
| 663 | verifyAndFix(code: string, config: Linter.Config, options: Linter.FixOptions): Linter.FixReport;
|
---|
| 664 |
|
---|
| 665 | getSourceCode(): SourceCode;
|
---|
| 666 |
|
---|
| 667 | defineRule(name: string, rule: Rule.RuleModule): void;
|
---|
| 668 |
|
---|
| 669 | defineRules(rules: { [name: string]: Rule.RuleModule }): void;
|
---|
| 670 |
|
---|
| 671 | getRules(): Map<string, Rule.RuleModule>;
|
---|
| 672 |
|
---|
| 673 | defineParser(name: string, parser: Linter.ParserModule): void;
|
---|
| 674 | }
|
---|
| 675 |
|
---|
| 676 | export namespace Linter {
|
---|
| 677 | type Severity = 0 | 1 | 2;
|
---|
| 678 |
|
---|
| 679 | type RuleLevel = Severity | "off" | "warn" | "error";
|
---|
| 680 | type RuleLevelAndOptions<Options extends any[] = any[]> = Prepend<Partial<Options>, RuleLevel>;
|
---|
| 681 |
|
---|
| 682 | type RuleEntry<Options extends any[] = any[]> = RuleLevel | RuleLevelAndOptions<Options>;
|
---|
| 683 |
|
---|
| 684 | interface RulesRecord {
|
---|
| 685 | [rule: string]: RuleEntry;
|
---|
| 686 | }
|
---|
| 687 |
|
---|
| 688 | interface HasRules<Rules extends RulesRecord = RulesRecord> {
|
---|
| 689 | rules?: Partial<Rules> | undefined;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | interface BaseConfig<Rules extends RulesRecord = RulesRecord> extends HasRules<Rules> {
|
---|
| 693 | $schema?: string | undefined;
|
---|
| 694 | env?: { [name: string]: boolean } | undefined;
|
---|
| 695 | extends?: string | string[] | undefined;
|
---|
| 696 | globals?: { [name: string]: boolean | "readonly" | "readable" | "writable" | "writeable" } | undefined;
|
---|
| 697 | noInlineConfig?: boolean | undefined;
|
---|
| 698 | overrides?: ConfigOverride[] | undefined;
|
---|
| 699 | parser?: string | undefined;
|
---|
| 700 | parserOptions?: ParserOptions | undefined;
|
---|
| 701 | plugins?: string[] | undefined;
|
---|
| 702 | processor?: string | undefined;
|
---|
| 703 | reportUnusedDisableDirectives?: boolean | undefined;
|
---|
| 704 | settings?: { [name: string]: any } | undefined;
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | interface ConfigOverride<Rules extends RulesRecord = RulesRecord> extends BaseConfig<Rules> {
|
---|
| 708 | excludedFiles?: string | string[] | undefined;
|
---|
| 709 | files: string | string[];
|
---|
| 710 | }
|
---|
| 711 |
|
---|
| 712 | // https://github.com/eslint/eslint/blob/v6.8.0/conf/config-schema.js
|
---|
| 713 | interface Config<Rules extends RulesRecord = RulesRecord> extends BaseConfig<Rules> {
|
---|
| 714 | ignorePatterns?: string | string[] | undefined;
|
---|
| 715 | root?: boolean | undefined;
|
---|
| 716 | }
|
---|
| 717 |
|
---|
| 718 | interface ParserOptions {
|
---|
[e29cc2e] | 719 | ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | "latest" |undefined;
|
---|
[6a3a178] | 720 | sourceType?: "script" | "module" | undefined;
|
---|
| 721 | ecmaFeatures?: {
|
---|
| 722 | globalReturn?: boolean | undefined;
|
---|
| 723 | impliedStrict?: boolean | undefined;
|
---|
| 724 | jsx?: boolean | undefined;
|
---|
| 725 | experimentalObjectRestSpread?: boolean | undefined;
|
---|
| 726 | [key: string]: any;
|
---|
| 727 | } | undefined;
|
---|
| 728 | [key: string]: any;
|
---|
| 729 | }
|
---|
| 730 |
|
---|
| 731 | interface LintOptions {
|
---|
| 732 | filename?: string | undefined;
|
---|
| 733 | preprocess?: ((code: string) => string[]) | undefined;
|
---|
| 734 | postprocess?: ((problemLists: LintMessage[][]) => LintMessage[]) | undefined;
|
---|
| 735 | filterCodeBlock?: boolean | undefined;
|
---|
| 736 | disableFixes?: boolean | undefined;
|
---|
| 737 | allowInlineConfig?: boolean | undefined;
|
---|
| 738 | reportUnusedDisableDirectives?: boolean | undefined;
|
---|
| 739 | }
|
---|
| 740 |
|
---|
| 741 | interface LintSuggestion {
|
---|
| 742 | desc: string;
|
---|
| 743 | fix: Rule.Fix;
|
---|
| 744 | messageId?: string | undefined;
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | interface LintMessage {
|
---|
| 748 | column: number;
|
---|
| 749 | line: number;
|
---|
| 750 | endColumn?: number | undefined;
|
---|
| 751 | endLine?: number | undefined;
|
---|
| 752 | ruleId: string | null;
|
---|
| 753 | message: string;
|
---|
| 754 | messageId?: string | undefined;
|
---|
| 755 | nodeType?: string | undefined;
|
---|
| 756 | fatal?: true | undefined;
|
---|
| 757 | severity: Severity;
|
---|
| 758 | fix?: Rule.Fix | undefined;
|
---|
| 759 | /** @deprecated Use `linter.getSourceCode()` */
|
---|
| 760 | source?: string | null | undefined;
|
---|
| 761 | suggestions?: LintSuggestion[] | undefined;
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | interface FixOptions extends LintOptions {
|
---|
| 765 | fix?: boolean | undefined;
|
---|
| 766 | }
|
---|
| 767 |
|
---|
| 768 | interface FixReport {
|
---|
| 769 | fixed: boolean;
|
---|
| 770 | output: string;
|
---|
| 771 | messages: LintMessage[];
|
---|
| 772 | }
|
---|
| 773 |
|
---|
| 774 | type ParserModule =
|
---|
| 775 | | {
|
---|
| 776 | parse(text: string, options?: any): AST.Program;
|
---|
| 777 | }
|
---|
| 778 | | {
|
---|
| 779 | parseForESLint(text: string, options?: any): ESLintParseResult;
|
---|
| 780 | };
|
---|
| 781 |
|
---|
| 782 | interface ESLintParseResult {
|
---|
| 783 | ast: AST.Program;
|
---|
| 784 | parserServices?: SourceCode.ParserServices | undefined;
|
---|
| 785 | scopeManager?: Scope.ScopeManager | undefined;
|
---|
| 786 | visitorKeys?: SourceCode.VisitorKeys | undefined;
|
---|
| 787 | }
|
---|
| 788 |
|
---|
| 789 | interface ProcessorFile {
|
---|
| 790 | text: string;
|
---|
| 791 | filename: string;
|
---|
| 792 | }
|
---|
| 793 |
|
---|
| 794 | // https://eslint.org/docs/developer-guide/working-with-plugins#processors-in-plugins
|
---|
| 795 | interface Processor<T extends string | ProcessorFile = string | ProcessorFile> {
|
---|
| 796 | supportsAutofix?: boolean | undefined;
|
---|
| 797 | preprocess?(text: string, filename: string): T[];
|
---|
| 798 | postprocess?(messages: LintMessage[][], filename: string): LintMessage[];
|
---|
| 799 | }
|
---|
| 800 | }
|
---|
| 801 |
|
---|
| 802 | //#endregion
|
---|
| 803 |
|
---|
| 804 | //#region ESLint
|
---|
| 805 |
|
---|
| 806 | export class ESLint {
|
---|
| 807 | static version: string;
|
---|
| 808 |
|
---|
| 809 | static outputFixes(results: ESLint.LintResult[]): Promise<void>;
|
---|
| 810 |
|
---|
| 811 | static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[];
|
---|
| 812 |
|
---|
| 813 | constructor(options?: ESLint.Options);
|
---|
| 814 |
|
---|
| 815 | lintFiles(patterns: string | string[]): Promise<ESLint.LintResult[]>;
|
---|
| 816 |
|
---|
| 817 | lintText(code: string, options?: { filePath?: string | undefined; warnIgnored?: boolean | undefined }): Promise<ESLint.LintResult[]>;
|
---|
| 818 |
|
---|
[e29cc2e] | 819 | getRulesMetaForResults(results: ESLint.LintResult[]): ESLint.LintResultData['rulesMeta'];
|
---|
| 820 |
|
---|
[6a3a178] | 821 | calculateConfigForFile(filePath: string): Promise<any>;
|
---|
| 822 |
|
---|
| 823 | isPathIgnored(filePath: string): Promise<boolean>;
|
---|
| 824 |
|
---|
| 825 | loadFormatter(nameOrPath?: string): Promise<ESLint.Formatter>;
|
---|
| 826 | }
|
---|
| 827 |
|
---|
| 828 | export namespace ESLint {
|
---|
| 829 | interface Options {
|
---|
| 830 | // File enumeration
|
---|
| 831 | cwd?: string | undefined;
|
---|
| 832 | errorOnUnmatchedPattern?: boolean | undefined;
|
---|
| 833 | extensions?: string[] | undefined;
|
---|
| 834 | globInputPaths?: boolean | undefined;
|
---|
| 835 | ignore?: boolean | undefined;
|
---|
| 836 | ignorePath?: string | undefined;
|
---|
| 837 |
|
---|
| 838 | // Linting
|
---|
| 839 | allowInlineConfig?: boolean | undefined;
|
---|
| 840 | baseConfig?: Linter.Config | undefined;
|
---|
| 841 | overrideConfig?: Linter.Config | undefined;
|
---|
| 842 | overrideConfigFile?: string | undefined;
|
---|
| 843 | plugins?: Record<string, any> | undefined;
|
---|
| 844 | reportUnusedDisableDirectives?: Linter.RuleLevel | undefined;
|
---|
| 845 | resolvePluginsRelativeTo?: string | undefined;
|
---|
| 846 | rulePaths?: string[] | undefined;
|
---|
| 847 | useEslintrc?: boolean | undefined;
|
---|
| 848 |
|
---|
| 849 | // Autofix
|
---|
| 850 | fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined;
|
---|
| 851 | fixTypes?: Array<Rule.RuleMetaData["type"]> | undefined;
|
---|
| 852 |
|
---|
| 853 | // Cache-related
|
---|
| 854 | cache?: boolean | undefined;
|
---|
| 855 | cacheLocation?: string | undefined;
|
---|
| 856 | cacheStrategy?: "content" | "metadata" | undefined;
|
---|
| 857 | }
|
---|
| 858 |
|
---|
| 859 | interface LintResult {
|
---|
| 860 | filePath: string;
|
---|
| 861 | messages: Linter.LintMessage[];
|
---|
| 862 | errorCount: number;
|
---|
[e29cc2e] | 863 | fatalErrorCount: number;
|
---|
[6a3a178] | 864 | warningCount: number;
|
---|
| 865 | fixableErrorCount: number;
|
---|
| 866 | fixableWarningCount: number;
|
---|
| 867 | output?: string | undefined;
|
---|
| 868 | source?: string | undefined;
|
---|
| 869 | usedDeprecatedRules: DeprecatedRuleUse[];
|
---|
| 870 | }
|
---|
| 871 |
|
---|
| 872 | interface LintResultData {
|
---|
| 873 | rulesMeta: {
|
---|
| 874 | [ruleId: string]: Rule.RuleMetaData;
|
---|
| 875 | };
|
---|
| 876 | }
|
---|
| 877 |
|
---|
| 878 | interface DeprecatedRuleUse {
|
---|
| 879 | ruleId: string;
|
---|
| 880 | replacedBy: string[];
|
---|
| 881 | }
|
---|
| 882 |
|
---|
| 883 | interface Formatter {
|
---|
| 884 | format(results: LintResult[], data?: LintResultData): string;
|
---|
| 885 | }
|
---|
| 886 |
|
---|
| 887 | // Docs reference the type by this name
|
---|
| 888 | type EditInfo = Rule.Fix;
|
---|
| 889 | }
|
---|
| 890 |
|
---|
| 891 | //#endregion
|
---|
| 892 |
|
---|
| 893 | //#region RuleTester
|
---|
| 894 |
|
---|
| 895 | export class RuleTester {
|
---|
| 896 | constructor(config?: any);
|
---|
| 897 |
|
---|
| 898 | run(
|
---|
| 899 | name: string,
|
---|
| 900 | rule: Rule.RuleModule,
|
---|
| 901 | tests: {
|
---|
| 902 | valid?: Array<string | RuleTester.ValidTestCase> | undefined;
|
---|
| 903 | invalid?: RuleTester.InvalidTestCase[] | undefined;
|
---|
| 904 | },
|
---|
| 905 | ): void;
|
---|
[e29cc2e] | 906 |
|
---|
| 907 | static only(
|
---|
| 908 | item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase,
|
---|
| 909 | ): RuleTester.ValidTestCase | RuleTester.InvalidTestCase;
|
---|
[6a3a178] | 910 | }
|
---|
| 911 |
|
---|
| 912 | export namespace RuleTester {
|
---|
| 913 | interface ValidTestCase {
|
---|
| 914 | code: string;
|
---|
| 915 | options?: any;
|
---|
| 916 | filename?: string | undefined;
|
---|
[e29cc2e] | 917 | only?: boolean;
|
---|
[6a3a178] | 918 | parserOptions?: Linter.ParserOptions | undefined;
|
---|
| 919 | settings?: { [name: string]: any } | undefined;
|
---|
| 920 | parser?: string | undefined;
|
---|
| 921 | globals?: { [name: string]: boolean } | undefined;
|
---|
| 922 | }
|
---|
| 923 |
|
---|
| 924 | interface SuggestionOutput {
|
---|
| 925 | messageId?: string | undefined;
|
---|
| 926 | desc?: string | undefined;
|
---|
| 927 | data?: Record<string, unknown> | undefined;
|
---|
| 928 | output: string;
|
---|
| 929 | }
|
---|
| 930 |
|
---|
| 931 | interface InvalidTestCase extends ValidTestCase {
|
---|
| 932 | errors: number | Array<TestCaseError | string>;
|
---|
| 933 | output?: string | null | undefined;
|
---|
| 934 | }
|
---|
| 935 |
|
---|
| 936 | interface TestCaseError {
|
---|
| 937 | message?: string | RegExp | undefined;
|
---|
| 938 | messageId?: string | undefined;
|
---|
| 939 | type?: string | undefined;
|
---|
| 940 | data?: any;
|
---|
| 941 | line?: number | undefined;
|
---|
| 942 | column?: number | undefined;
|
---|
| 943 | endLine?: number | undefined;
|
---|
| 944 | endColumn?: number | undefined;
|
---|
| 945 | suggestions?: SuggestionOutput[] | undefined;
|
---|
| 946 | }
|
---|
| 947 | }
|
---|
| 948 |
|
---|
| 949 | //#endregion
|
---|