import { TextSourceCode, SourceRange, TraversalStep, RuleDefinition, RuleVisitor, DeprecatedInfo, RuleContext, Language, LanguageOptions } from '@eslint/core'; // This definition file follows a somewhat unusual format. ESTree allows // runtime type checks based on the `type` parameter. In order to explain this // to typescript we want to use discriminated union types: // https://github.com/Microsoft/TypeScript/pull/9163 // // For ESTree this is a bit tricky because the high level interfaces like // Node or Function are pulling double duty. We want to pass common fields down // to the interfaces that extend them (like Identifier or // ArrowFunctionExpression), but you can't extend a type union or enforce // common fields on them. So we've split the high level interfaces into two // types, a base type which passes down inherited fields, and a type union of // all types which extend the base type. Only the type union is exported, and // the union is how other types refer to the collection of inheriting types. // // This makes the definitions file here somewhat more difficult to maintain, // but it has the notable advantage of making ESTree much easier to use as // an end user. interface BaseNodeWithoutComments { // Every leaf interface that extends BaseNode must specify a type property. // The type property should be a string literal. For example, Identifier // has: `type: "Identifier"` type: string; loc?: SourceLocation | null | undefined; range?: [number, number] | undefined; } interface BaseNode extends BaseNodeWithoutComments { leadingComments?: Comment[] | undefined; trailingComments?: Comment[] | undefined; } interface NodeMap { AssignmentProperty: AssignmentProperty; CatchClause: CatchClause; Class: Class; ClassBody: ClassBody; Expression: Expression; Function: Function; Identifier: Identifier; Literal: Literal; MethodDefinition: MethodDefinition; ModuleDeclaration: ModuleDeclaration; ModuleSpecifier: ModuleSpecifier; Pattern: Pattern; PrivateIdentifier: PrivateIdentifier; Program: Program; Property: Property; PropertyDefinition: PropertyDefinition; SpreadElement: SpreadElement; Statement: Statement; Super: Super; SwitchCase: SwitchCase; TemplateElement: TemplateElement; VariableDeclarator: VariableDeclarator; } type Node = NodeMap[keyof NodeMap]; interface Comment extends BaseNodeWithoutComments { type: 'Line' | 'Block'; value: string; } interface SourceLocation { source?: string | null | undefined; start: Position; end: Position; } interface Position { /** >= 1 */ line: number; /** >= 0 */ column: number; } interface Program extends BaseNode { type: 'Program'; sourceType: 'script' | 'module'; body: Array; comments?: Comment[] | undefined; } interface Directive extends BaseNode { type: 'ExpressionStatement'; expression: Literal; directive: string; } interface BaseFunction extends BaseNode { params: Pattern[]; generator?: boolean | undefined; async?: boolean | undefined; // The body is either BlockStatement or Expression because arrow functions // can have a body that's either. FunctionDeclarations and // FunctionExpressions have only BlockStatement bodies. body: BlockStatement | Expression; } type Function = FunctionDeclaration | FunctionExpression | ArrowFunctionExpression; type Statement = | ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration; interface BaseStatement extends BaseNode {} interface EmptyStatement extends BaseStatement { type: 'EmptyStatement'; } interface BlockStatement extends BaseStatement { type: 'BlockStatement'; body: Statement[]; innerComments?: Comment[] | undefined; } interface StaticBlock extends Omit { type: 'StaticBlock'; } interface ExpressionStatement extends BaseStatement { type: 'ExpressionStatement'; expression: Expression; } interface IfStatement extends BaseStatement { type: 'IfStatement'; test: Expression; consequent: Statement; alternate?: Statement | null | undefined; } interface LabeledStatement extends BaseStatement { type: 'LabeledStatement'; label: Identifier; body: Statement; } interface BreakStatement extends BaseStatement { type: 'BreakStatement'; label?: Identifier | null | undefined; } interface ContinueStatement extends BaseStatement { type: 'ContinueStatement'; label?: Identifier | null | undefined; } interface WithStatement extends BaseStatement { type: 'WithStatement'; object: Expression; body: Statement; } interface SwitchStatement extends BaseStatement { type: 'SwitchStatement'; discriminant: Expression; cases: SwitchCase[]; } interface ReturnStatement extends BaseStatement { type: 'ReturnStatement'; argument?: Expression | null | undefined; } interface ThrowStatement extends BaseStatement { type: 'ThrowStatement'; argument: Expression; } interface TryStatement extends BaseStatement { type: 'TryStatement'; block: BlockStatement; handler?: CatchClause | null | undefined; finalizer?: BlockStatement | null | undefined; } interface WhileStatement extends BaseStatement { type: 'WhileStatement'; test: Expression; body: Statement; } interface DoWhileStatement extends BaseStatement { type: 'DoWhileStatement'; body: Statement; test: Expression; } interface ForStatement extends BaseStatement { type: 'ForStatement'; init?: VariableDeclaration | Expression | null | undefined; test?: Expression | null | undefined; update?: Expression | null | undefined; body: Statement; } interface BaseForXStatement extends BaseStatement { left: VariableDeclaration | Pattern; right: Expression; body: Statement; } interface ForInStatement extends BaseForXStatement { type: 'ForInStatement'; } interface DebuggerStatement extends BaseStatement { type: 'DebuggerStatement'; } type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration; interface BaseDeclaration extends BaseStatement {} interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration { type: 'FunctionDeclaration'; /** It is null when a function declaration is a part of the `export default function` statement */ id: Identifier | null; body: BlockStatement; } interface FunctionDeclaration extends MaybeNamedFunctionDeclaration { id: Identifier; } interface VariableDeclaration extends BaseDeclaration { type: 'VariableDeclaration'; declarations: VariableDeclarator[]; kind: 'var' | 'let' | 'const'; } interface VariableDeclarator extends BaseNode { type: 'VariableDeclarator'; id: Pattern; init?: Expression | null | undefined; } interface ExpressionMap { ArrayExpression: ArrayExpression; ArrowFunctionExpression: ArrowFunctionExpression; AssignmentExpression: AssignmentExpression; AwaitExpression: AwaitExpression; BinaryExpression: BinaryExpression; CallExpression: CallExpression; ChainExpression: ChainExpression; ClassExpression: ClassExpression; ConditionalExpression: ConditionalExpression; FunctionExpression: FunctionExpression; Identifier: Identifier; ImportExpression: ImportExpression; Literal: Literal; LogicalExpression: LogicalExpression; MemberExpression: MemberExpression; MetaProperty: MetaProperty; NewExpression: NewExpression; ObjectExpression: ObjectExpression; SequenceExpression: SequenceExpression; TaggedTemplateExpression: TaggedTemplateExpression; TemplateLiteral: TemplateLiteral; ThisExpression: ThisExpression; UnaryExpression: UnaryExpression; UpdateExpression: UpdateExpression; YieldExpression: YieldExpression; } type Expression = ExpressionMap[keyof ExpressionMap]; interface BaseExpression extends BaseNode {} type ChainElement = SimpleCallExpression | MemberExpression; interface ChainExpression extends BaseExpression { type: 'ChainExpression'; expression: ChainElement; } interface ThisExpression extends BaseExpression { type: 'ThisExpression'; } interface ArrayExpression extends BaseExpression { type: 'ArrayExpression'; elements: Array; } interface ObjectExpression extends BaseExpression { type: 'ObjectExpression'; properties: Array; } interface PrivateIdentifier extends BaseNode { type: 'PrivateIdentifier'; name: string; } interface Property extends BaseNode { type: 'Property'; key: Expression | PrivateIdentifier; value: Expression | Pattern; // Could be an AssignmentProperty kind: 'init' | 'get' | 'set'; method: boolean; shorthand: boolean; computed: boolean; } interface PropertyDefinition extends BaseNode { type: 'PropertyDefinition'; key: Expression | PrivateIdentifier; value?: Expression | null | undefined; computed: boolean; static: boolean; } interface FunctionExpression extends BaseFunction, BaseExpression { id?: Identifier | null | undefined; type: 'FunctionExpression'; body: BlockStatement; } interface SequenceExpression extends BaseExpression { type: 'SequenceExpression'; expressions: Expression[]; } interface UnaryExpression extends BaseExpression { type: 'UnaryExpression'; operator: UnaryOperator; prefix: true; argument: Expression; } interface BinaryExpression extends BaseExpression { type: 'BinaryExpression'; operator: BinaryOperator; left: Expression | PrivateIdentifier; right: Expression; } interface AssignmentExpression extends BaseExpression { type: 'AssignmentExpression'; operator: AssignmentOperator; left: Pattern | MemberExpression; right: Expression; } interface UpdateExpression extends BaseExpression { type: 'UpdateExpression'; operator: UpdateOperator; argument: Expression; prefix: boolean; } interface LogicalExpression extends BaseExpression { type: 'LogicalExpression'; operator: LogicalOperator; left: Expression; right: Expression; } interface ConditionalExpression extends BaseExpression { type: 'ConditionalExpression'; test: Expression; alternate: Expression; consequent: Expression; } interface BaseCallExpression extends BaseExpression { callee: Expression | Super; arguments: Array; } type CallExpression = SimpleCallExpression | NewExpression; interface SimpleCallExpression extends BaseCallExpression { type: 'CallExpression'; optional: boolean; } interface NewExpression extends BaseCallExpression { type: 'NewExpression'; } interface MemberExpression extends BaseExpression, BasePattern { type: 'MemberExpression'; object: Expression | Super; property: Expression | PrivateIdentifier; computed: boolean; optional: boolean; } type Pattern = | Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression; interface BasePattern extends BaseNode {} interface SwitchCase extends BaseNode { type: 'SwitchCase'; test?: Expression | null | undefined; consequent: Statement[]; } interface CatchClause extends BaseNode { type: 'CatchClause'; param: Pattern | null; body: BlockStatement; } interface Identifier extends BaseNode, BaseExpression, BasePattern { type: 'Identifier'; name: string; } type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral; interface SimpleLiteral extends BaseNode, BaseExpression { type: 'Literal'; value: string | boolean | number | null; raw?: string | undefined; } interface RegExpLiteral extends BaseNode, BaseExpression { type: 'Literal'; value?: RegExp | null | undefined; regex: { pattern: string; flags: string; }; raw?: string | undefined; } interface BigIntLiteral extends BaseNode, BaseExpression { type: 'Literal'; value?: bigint | null | undefined; bigint: string; raw?: string | undefined; } type UnaryOperator = '-' | '+' | '!' | '~' | 'typeof' | 'void' | 'delete'; type BinaryOperator = | '==' | '!=' | '===' | '!==' | '<' | '<=' | '>' | '>=' | '<<' | '>>' | '>>>' | '+' | '-' | '*' | '/' | '%' | '**' | '|' | '^' | '&' | 'in' | 'instanceof'; type LogicalOperator = '||' | '&&' | '??'; type AssignmentOperator = | '=' | '+=' | '-=' | '*=' | '/=' | '%=' | '**=' | '<<=' | '>>=' | '>>>=' | '|=' | '^=' | '&=' | '||=' | '&&=' | '??='; type UpdateOperator = '++' | '--'; interface ForOfStatement extends BaseForXStatement { type: 'ForOfStatement'; await: boolean; } interface Super extends BaseNode { type: 'Super'; } interface SpreadElement extends BaseNode { type: 'SpreadElement'; argument: Expression; } interface ArrowFunctionExpression extends BaseExpression, BaseFunction { type: 'ArrowFunctionExpression'; expression: boolean; body: BlockStatement | Expression; } interface YieldExpression extends BaseExpression { type: 'YieldExpression'; argument?: Expression | null | undefined; delegate: boolean; } interface TemplateLiteral extends BaseExpression { type: 'TemplateLiteral'; quasis: TemplateElement[]; expressions: Expression[]; } interface TaggedTemplateExpression extends BaseExpression { type: 'TaggedTemplateExpression'; tag: Expression; quasi: TemplateLiteral; } interface TemplateElement extends BaseNode { type: 'TemplateElement'; tail: boolean; value: { /** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */ cooked?: string | null | undefined; raw: string; }; } interface AssignmentProperty extends Property { value: Pattern; kind: 'init'; method: boolean; // false } interface ObjectPattern extends BasePattern { type: 'ObjectPattern'; properties: Array; } interface ArrayPattern extends BasePattern { type: 'ArrayPattern'; elements: Array; } interface RestElement extends BasePattern { type: 'RestElement'; argument: Pattern; } interface AssignmentPattern extends BasePattern { type: 'AssignmentPattern'; left: Pattern; right: Expression; } type Class = ClassDeclaration | ClassExpression; interface BaseClass extends BaseNode { superClass?: Expression | null | undefined; body: ClassBody; } interface ClassBody extends BaseNode { type: 'ClassBody'; body: Array; } interface MethodDefinition extends BaseNode { type: 'MethodDefinition'; key: Expression | PrivateIdentifier; value: FunctionExpression; kind: 'constructor' | 'method' | 'get' | 'set'; computed: boolean; static: boolean; } interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration { type: 'ClassDeclaration'; /** It is null when a class declaration is a part of the `export default class` statement */ id: Identifier | null; } interface ClassDeclaration extends MaybeNamedClassDeclaration { id: Identifier; } interface ClassExpression extends BaseClass, BaseExpression { type: 'ClassExpression'; id?: Identifier | null | undefined; } interface MetaProperty extends BaseExpression { type: 'MetaProperty'; meta: Identifier; property: Identifier; } type ModuleDeclaration = | ImportDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration; interface BaseModuleDeclaration extends BaseNode {} type ModuleSpecifier = | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier | ExportSpecifier; interface BaseModuleSpecifier extends BaseNode { local: Identifier; } interface ImportDeclaration extends BaseModuleDeclaration { type: 'ImportDeclaration'; specifiers: Array; source: Literal; } interface ImportSpecifier extends BaseModuleSpecifier { type: 'ImportSpecifier'; imported: Identifier | Literal; } interface ImportExpression extends BaseExpression { type: 'ImportExpression'; source: Expression; } interface ImportDefaultSpecifier extends BaseModuleSpecifier { type: 'ImportDefaultSpecifier'; } interface ImportNamespaceSpecifier extends BaseModuleSpecifier { type: 'ImportNamespaceSpecifier'; } interface ExportNamedDeclaration extends BaseModuleDeclaration { type: 'ExportNamedDeclaration'; declaration?: Declaration | null | undefined; specifiers: ExportSpecifier[]; source?: Literal | null | undefined; } interface ExportSpecifier extends Omit { type: 'ExportSpecifier'; local: Identifier | Literal; exported: Identifier | Literal; } interface ExportDefaultDeclaration extends BaseModuleDeclaration { type: 'ExportDefaultDeclaration'; declaration: MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration | Expression; } interface ExportAllDeclaration extends BaseModuleDeclaration { type: 'ExportAllDeclaration'; exported: Identifier | Literal | null; source: Literal; } interface AwaitExpression extends BaseExpression { type: 'AwaitExpression'; argument: Expression; } /* eslint-disable */ // ================================================================================================== // JSON Schema Draft 04 // ================================================================================================== /** * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.1 */ type JSONSchema4TypeName = | "string" // | "number" | "integer" | "boolean" | "object" | "array" | "null" | "any"; /** * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-3.5 */ type JSONSchema4Type = | string // | number | boolean | JSONSchema4Object | JSONSchema4Array | null; // Workaround for infinite type recursion interface JSONSchema4Object { [key: string]: JSONSchema4Type; } // Workaround for infinite type recursion // https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 interface JSONSchema4Array extends Array {} /** * Meta schema * * Recommended values: * - 'http://json-schema.org/schema#' * - 'http://json-schema.org/hyper-schema#' * - 'http://json-schema.org/draft-04/schema#' * - 'http://json-schema.org/draft-04/hyper-schema#' * - 'http://json-schema.org/draft-03/schema#' * - 'http://json-schema.org/draft-03/hyper-schema#' * * @see https://tools.ietf.org/html/draft-handrews-json-schema-validation-01#section-5 */ type JSONSchema4Version = string; /** * JSON Schema V4 * @see https://tools.ietf.org/html/draft-zyp-json-schema-04 */ interface JSONSchema4 { id?: string | undefined; $ref?: string | undefined; $schema?: JSONSchema4Version | undefined; /** * This attribute is a string that provides a short description of the * instance property. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.21 */ title?: string | undefined; /** * This attribute is a string that provides a full description of the of * purpose the instance property. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.22 */ description?: string | undefined; default?: JSONSchema4Type | undefined; multipleOf?: number | undefined; maximum?: number | undefined; exclusiveMaximum?: boolean | undefined; minimum?: number | undefined; exclusiveMinimum?: boolean | undefined; maxLength?: number | undefined; minLength?: number | undefined; pattern?: string | undefined; /** * May only be defined when "items" is defined, and is a tuple of JSONSchemas. * * This provides a definition for additional items in an array instance * when tuple definitions of the items is provided. This can be false * to indicate additional items in the array are not allowed, or it can * be a schema that defines the schema of the additional items. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.6 */ additionalItems?: boolean | JSONSchema4 | undefined; /** * This attribute defines the allowed items in an instance array, and * MUST be a schema or an array of schemas. The default value is an * empty schema which allows any value for items in the instance array. * * When this attribute value is a schema and the instance value is an * array, then all the items in the array MUST be valid according to the * schema. * * When this attribute value is an array of schemas and the instance * value is an array, each position in the instance array MUST conform * to the schema in the corresponding position for this array. This * called tuple typing. When tuple typing is used, additional items are * allowed, disallowed, or constrained by the "additionalItems" * (Section 5.6) attribute using the same rules as * "additionalProperties" (Section 5.4) for objects. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5 */ items?: JSONSchema4 | JSONSchema4[] | undefined; maxItems?: number | undefined; minItems?: number | undefined; uniqueItems?: boolean | undefined; maxProperties?: number | undefined; minProperties?: number | undefined; /** * This attribute indicates if the instance must have a value, and not * be undefined. This is false by default, making the instance * optional. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.7 */ required?: boolean | string[] | undefined; /** * This attribute defines a schema for all properties that are not * explicitly defined in an object type definition. If specified, the * value MUST be a schema or a boolean. If false is provided, no * additional properties are allowed beyond the properties defined in * the schema. The default value is an empty schema which allows any * value for additional properties. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.4 */ additionalProperties?: boolean | JSONSchema4 | undefined; definitions?: { [k: string]: JSONSchema4; } | undefined; /** * This attribute is an object with property definitions that define the * valid values of instance object property values. When the instance * value is an object, the property values of the instance object MUST * conform to the property definitions in this object. In this object, * each property definition's value MUST be a schema, and the property's * name MUST be the name of the instance property that it defines. The * instance property value MUST be valid according to the schema from * the property definition. Properties are considered unordered, the * order of the instance properties MAY be in any order. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.2 */ properties?: { [k: string]: JSONSchema4; } | undefined; /** * This attribute is an object that defines the schema for a set of * property names of an object instance. The name of each property of * this attribute's object is a regular expression pattern in the ECMA * 262/Perl 5 format, while the value is a schema. If the pattern * matches the name of a property on the instance object, the value of * the instance's property MUST be valid against the pattern name's * schema value. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.3 */ patternProperties?: { [k: string]: JSONSchema4; } | undefined; dependencies?: { [k: string]: JSONSchema4 | string[]; } | undefined; /** * This provides an enumeration of all possible values that are valid * for the instance property. This MUST be an array, and each item in * the array represents a possible value for the instance value. If * this attribute is defined, the instance value MUST be one of the * values in the array in order for the schema to be valid. * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.19 */ enum?: JSONSchema4Type[] | undefined; /** * A single type, or a union of simple types */ type?: JSONSchema4TypeName | JSONSchema4TypeName[] | undefined; allOf?: JSONSchema4[] | undefined; anyOf?: JSONSchema4[] | undefined; oneOf?: JSONSchema4[] | undefined; not?: JSONSchema4 | undefined; /** * The value of this property MUST be another schema which will provide * a base schema which the current schema will inherit from. The * inheritance rules are such that any instance that is valid according * to the current schema MUST be valid according to the referenced * schema. This MAY also be an array, in which case, the instance MUST * be valid for all the schemas in the array. A schema that extends * another schema MAY define additional attributes, constrain existing * attributes, or add other constraints. * * Conceptually, the behavior of extends can be seen as validating an * instance against all constraints in the extending schema as well as * the extended schema(s). * * @see https://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.26 */ extends?: string | string[] | undefined; /** * @see https://tools.ietf.org/html/draft-zyp-json-schema-04#section-5.6 */ [k: string]: any; format?: string | undefined; } export namespace AST { type TokenType = | "Boolean" | "Null" | "Identifier" | "Keyword" | "Punctuator" | "JSXIdentifier" | "JSXText" | "Numeric" | "String" | "RegularExpression"; interface Token { type: TokenType; value: string; range: Range; loc: SourceLocation; } interface SourceLocation { start: Position; end: Position; } type Range = [number, number]; interface Program extends Program { comments: Comment[]; tokens: Token[]; loc: SourceLocation; range: Range; } } export namespace Scope { interface ScopeManager { scopes: Scope[]; globalScope: Scope | null; acquire(node: Node, inner?: boolean): Scope | null; getDeclaredVariables(node: Node): Variable[]; } interface Scope { type: | "block" | "catch" | "class" | "for" | "function" | "function-expression-name" | "global" | "module" | "switch" | "with" | "TDZ"; isStrict: boolean; upper: Scope | null; childScopes: Scope[]; variableScope: Scope; block: Node; variables: Variable[]; set: Map; references: Reference[]; through: Reference[]; functionExpressionScope: boolean; } interface Variable { name: string; scope: Scope; identifiers: Identifier[]; references: Reference[]; defs: Definition[]; } interface Reference { identifier: Identifier; from: Scope; resolved: Variable | null; writeExpr: Node | null; init: boolean; isWrite(): boolean; isRead(): boolean; isWriteOnly(): boolean; isReadOnly(): boolean; isReadWrite(): boolean; } type DefinitionType = | { type: "CatchClause"; node: CatchClause; parent: null } | { type: "ClassName"; node: ClassDeclaration | ClassExpression; parent: null; } | { type: "FunctionName"; node: FunctionDeclaration | FunctionExpression; parent: null; } | { type: "ImplicitGlobalVariable"; node: Program; parent: null } | { type: "ImportBinding"; node: | ImportSpecifier | ImportDefaultSpecifier | ImportNamespaceSpecifier; parent: ImportDeclaration; } | { type: "Parameter"; node: | FunctionDeclaration | FunctionExpression | ArrowFunctionExpression; parent: null; } | { type: "TDZ"; node: any; parent: null } | { type: "Variable"; node: VariableDeclarator; parent: VariableDeclaration; }; type Definition = DefinitionType & { name: Identifier }; } // #region SourceCode export class SourceCode implements TextSourceCode<{ LangOptions: Linter.LanguageOptions; RootNode: AST.Program; SyntaxElementWithLoc: AST.Token | Node; ConfigNode: Comment; }> { text: string; ast: AST.Program; lines: string[]; hasBOM: boolean; parserServices: SourceCode.ParserServices; scopeManager: Scope.ScopeManager; visitorKeys: SourceCode.VisitorKeys; constructor(text: string, ast: AST.Program); constructor(config: SourceCode.Config); static splitLines(text: string): string[]; getLoc(syntaxElement: AST.Token | Node): SourceLocation; getRange(syntaxElement: AST.Token | Node): SourceRange; getText( node?: Node, beforeCount?: number, afterCount?: number, ): string; getLines(): string[]; getAllComments(): Comment[]; getAncestors(node: Node): Node[]; getDeclaredVariables(node: Node): Scope.Variable[]; getJSDocComment(node: Node): Comment | null; getNodeByRangeIndex(index: number): Node | null; isSpaceBetweenTokens(first: AST.Token, second: AST.Token): boolean; getLocFromIndex(index: number): Position; getIndexFromLoc(location: Position): number; // Inherited methods from TokenStore // --------------------------------- getTokenByRangeStart( offset: number, options?: { includeComments: false }, ): AST.Token | null; getTokenByRangeStart( offset: number, options: { includeComments: boolean }, ): AST.Token | Comment | null; getFirstToken: SourceCode.UnaryNodeCursorWithSkipOptions; getFirstTokens: SourceCode.UnaryNodeCursorWithCountOptions; getLastToken: SourceCode.UnaryNodeCursorWithSkipOptions; getLastTokens: SourceCode.UnaryNodeCursorWithCountOptions; getTokenBefore: SourceCode.UnaryCursorWithSkipOptions; getTokensBefore: SourceCode.UnaryCursorWithCountOptions; getTokenAfter: SourceCode.UnaryCursorWithSkipOptions; getTokensAfter: SourceCode.UnaryCursorWithCountOptions; getFirstTokenBetween: SourceCode.BinaryCursorWithSkipOptions; getFirstTokensBetween: SourceCode.BinaryCursorWithCountOptions; getLastTokenBetween: SourceCode.BinaryCursorWithSkipOptions; getLastTokensBetween: SourceCode.BinaryCursorWithCountOptions; getTokensBetween: SourceCode.BinaryCursorWithCountOptions; getTokens: (( node: Node, beforeCount?: number, afterCount?: number, ) => AST.Token[]) & SourceCode.UnaryNodeCursorWithCountOptions; commentsExistBetween( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, ): boolean; getCommentsBefore(nodeOrToken: Node | AST.Token): Comment[]; getCommentsAfter(nodeOrToken: Node | AST.Token): Comment[]; getCommentsInside(node: Node): Comment[]; getScope(node: Node): Scope.Scope; isSpaceBetween( first: Node | AST.Token, second: Node | AST.Token, ): boolean; isGlobalReference(node: Identifier): boolean; markVariableAsUsed(name: string, refNode?: Node): boolean; traverse(): Iterable; } export namespace SourceCode { interface Config { text: string; ast: AST.Program; parserServices?: ParserServices | undefined; scopeManager?: Scope.ScopeManager | undefined; visitorKeys?: VisitorKeys | undefined; } type ParserServices = any; interface VisitorKeys { [nodeType: string]: string[]; } interface UnaryNodeCursorWithSkipOptions { ( node: Node, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }, ): T | null; ( node: Node, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }, ): T | null; ( node: Node, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token | null; ( node: Node, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }, ): AST.Token | Comment | null; } interface UnaryNodeCursorWithCountOptions { ( node: Node, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }, ): T[]; ( node: Node, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }, ): T[]; ( node: Node, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token[]; ( node: Node, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }, ): Array; } interface UnaryCursorWithSkipOptions { ( node: Node | AST.Token | Comment, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }, ): T | null; ( node: Node | AST.Token | Comment, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }, ): T | null; ( node: Node | AST.Token | Comment, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token | null; ( node: Node | AST.Token | Comment, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }, ): AST.Token | Comment | null; } interface UnaryCursorWithCountOptions { ( node: Node | AST.Token | Comment, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }, ): T[]; ( node: Node | AST.Token | Comment, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }, ): T[]; ( node: Node | AST.Token | Comment, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token[]; ( node: Node | AST.Token | Comment, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }, ): Array; } interface BinaryCursorWithSkipOptions { ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }, ): T | null; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }, ): T | null; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token | null; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }, ): AST.Token | Comment | null; } interface BinaryCursorWithCountOptions { ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: | ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }, ): T[]; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: { filter: ( tokenOrComment: AST.Token | Comment, ) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }, ): T[]; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options?: | { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number, ): AST.Token[]; ( left: Node | AST.Token | Comment, right: Node | AST.Token | Comment, options: { filter?: | ((token: AST.Token | Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }, ): Array; } } // #endregion type JSSyntaxElement = { type: string; loc?: SourceLocation | null | undefined; }; export namespace Rule { interface RuleModule extends RuleDefinition<{ LangOptions: Linter.LanguageOptions; Code: SourceCode; RuleOptions: any[]; Visitor: NodeListener; Node: JSSyntaxElement; MessageIds: string; ExtRuleDocs: {}; }> { create(context: RuleContext): NodeListener; } type NodeTypes = Node["type"]; interface NodeListener extends RuleVisitor { ArrayExpression?: | ((node: ArrayExpression & NodeParentExtension) => void) | undefined; "ArrayExpression:exit"?: | ((node: ArrayExpression & NodeParentExtension) => void) | undefined; ArrayPattern?: | ((node: ArrayPattern & NodeParentExtension) => void) | undefined; "ArrayPattern:exit"?: | ((node: ArrayPattern & NodeParentExtension) => void) | undefined; ArrowFunctionExpression?: | (( node: ArrowFunctionExpression & NodeParentExtension, ) => void) | undefined; "ArrowFunctionExpression:exit"?: | (( node: ArrowFunctionExpression & NodeParentExtension, ) => void) | undefined; AssignmentExpression?: | (( node: AssignmentExpression & NodeParentExtension, ) => void) | undefined; "AssignmentExpression:exit"?: | (( node: AssignmentExpression & NodeParentExtension, ) => void) | undefined; AssignmentPattern?: | ((node: AssignmentPattern & NodeParentExtension) => void) | undefined; "AssignmentPattern:exit"?: | ((node: AssignmentPattern & NodeParentExtension) => void) | undefined; AwaitExpression?: | ((node: AwaitExpression & NodeParentExtension) => void) | undefined; "AwaitExpression:exit"?: | ((node: AwaitExpression & NodeParentExtension) => void) | undefined; BinaryExpression?: | ((node: BinaryExpression & NodeParentExtension) => void) | undefined; "BinaryExpression:exit"?: | ((node: BinaryExpression & NodeParentExtension) => void) | undefined; BlockStatement?: | ((node: BlockStatement & NodeParentExtension) => void) | undefined; "BlockStatement:exit"?: | ((node: BlockStatement & NodeParentExtension) => void) | undefined; BreakStatement?: | ((node: BreakStatement & NodeParentExtension) => void) | undefined; "BreakStatement:exit"?: | ((node: BreakStatement & NodeParentExtension) => void) | undefined; CallExpression?: | ((node: CallExpression & NodeParentExtension) => void) | undefined; "CallExpression:exit"?: | ((node: CallExpression & NodeParentExtension) => void) | undefined; CatchClause?: | ((node: CatchClause & NodeParentExtension) => void) | undefined; "CatchClause:exit"?: | ((node: CatchClause & NodeParentExtension) => void) | undefined; ChainExpression?: | ((node: ChainExpression & NodeParentExtension) => void) | undefined; "ChainExpression:exit"?: | ((node: ChainExpression & NodeParentExtension) => void) | undefined; ClassBody?: | ((node: ClassBody & NodeParentExtension) => void) | undefined; "ClassBody:exit"?: | ((node: ClassBody & NodeParentExtension) => void) | undefined; ClassDeclaration?: | ((node: ClassDeclaration & NodeParentExtension) => void) | undefined; "ClassDeclaration:exit"?: | ((node: ClassDeclaration & NodeParentExtension) => void) | undefined; ClassExpression?: | ((node: ClassExpression & NodeParentExtension) => void) | undefined; "ClassExpression:exit"?: | ((node: ClassExpression & NodeParentExtension) => void) | undefined; ConditionalExpression?: | (( node: ConditionalExpression & NodeParentExtension, ) => void) | undefined; "ConditionalExpression:exit"?: | (( node: ConditionalExpression & NodeParentExtension, ) => void) | undefined; ContinueStatement?: | ((node: ContinueStatement & NodeParentExtension) => void) | undefined; "ContinueStatement:exit"?: | ((node: ContinueStatement & NodeParentExtension) => void) | undefined; DebuggerStatement?: | ((node: DebuggerStatement & NodeParentExtension) => void) | undefined; "DebuggerStatement:exit"?: | ((node: DebuggerStatement & NodeParentExtension) => void) | undefined; DoWhileStatement?: | ((node: DoWhileStatement & NodeParentExtension) => void) | undefined; "DoWhileStatement:exit"?: | ((node: DoWhileStatement & NodeParentExtension) => void) | undefined; EmptyStatement?: | ((node: EmptyStatement & NodeParentExtension) => void) | undefined; "EmptyStatement:exit"?: | ((node: EmptyStatement & NodeParentExtension) => void) | undefined; ExportAllDeclaration?: | (( node: ExportAllDeclaration & NodeParentExtension, ) => void) | undefined; "ExportAllDeclaration:exit"?: | (( node: ExportAllDeclaration & NodeParentExtension, ) => void) | undefined; ExportDefaultDeclaration?: | (( node: ExportDefaultDeclaration & NodeParentExtension, ) => void) | undefined; "ExportDefaultDeclaration:exit"?: | (( node: ExportDefaultDeclaration & NodeParentExtension, ) => void) | undefined; ExportNamedDeclaration?: | (( node: ExportNamedDeclaration & NodeParentExtension, ) => void) | undefined; "ExportNamedDeclaration:exit"?: | (( node: ExportNamedDeclaration & NodeParentExtension, ) => void) | undefined; ExportSpecifier?: | ((node: ExportSpecifier & NodeParentExtension) => void) | undefined; "ExportSpecifier:exit"?: | ((node: ExportSpecifier & NodeParentExtension) => void) | undefined; ExpressionStatement?: | ((node: ExpressionStatement & NodeParentExtension) => void) | undefined; "ExpressionStatement:exit"?: | ((node: ExpressionStatement & NodeParentExtension) => void) | undefined; ForInStatement?: | ((node: ForInStatement & NodeParentExtension) => void) | undefined; "ForInStatement:exit"?: | ((node: ForInStatement & NodeParentExtension) => void) | undefined; ForOfStatement?: | ((node: ForOfStatement & NodeParentExtension) => void) | undefined; "ForOfStatement:exit"?: | ((node: ForOfStatement & NodeParentExtension) => void) | undefined; ForStatement?: | ((node: ForStatement & NodeParentExtension) => void) | undefined; "ForStatement:exit"?: | ((node: ForStatement & NodeParentExtension) => void) | undefined; FunctionDeclaration?: | ((node: FunctionDeclaration & NodeParentExtension) => void) | undefined; "FunctionDeclaration:exit"?: | ((node: FunctionDeclaration & NodeParentExtension) => void) | undefined; FunctionExpression?: | ((node: FunctionExpression & NodeParentExtension) => void) | undefined; "FunctionExpression:exit"?: | ((node: FunctionExpression & NodeParentExtension) => void) | undefined; Identifier?: | ((node: Identifier & NodeParentExtension) => void) | undefined; "Identifier:exit"?: | ((node: Identifier & NodeParentExtension) => void) | undefined; IfStatement?: | ((node: IfStatement & NodeParentExtension) => void) | undefined; "IfStatement:exit"?: | ((node: IfStatement & NodeParentExtension) => void) | undefined; ImportDeclaration?: | ((node: ImportDeclaration & NodeParentExtension) => void) | undefined; "ImportDeclaration:exit"?: | ((node: ImportDeclaration & NodeParentExtension) => void) | undefined; ImportDefaultSpecifier?: | (( node: ImportDefaultSpecifier & NodeParentExtension, ) => void) | undefined; "ImportDefaultSpecifier:exit"?: | (( node: ImportDefaultSpecifier & NodeParentExtension, ) => void) | undefined; ImportExpression?: | ((node: ImportExpression & NodeParentExtension) => void) | undefined; "ImportExpression:exit"?: | ((node: ImportExpression & NodeParentExtension) => void) | undefined; ImportNamespaceSpecifier?: | (( node: ImportNamespaceSpecifier & NodeParentExtension, ) => void) | undefined; "ImportNamespaceSpecifier:exit"?: | (( node: ImportNamespaceSpecifier & NodeParentExtension, ) => void) | undefined; ImportSpecifier?: | ((node: ImportSpecifier & NodeParentExtension) => void) | undefined; "ImportSpecifier:exit"?: | ((node: ImportSpecifier & NodeParentExtension) => void) | undefined; LabeledStatement?: | ((node: LabeledStatement & NodeParentExtension) => void) | undefined; "LabeledStatement:exit"?: | ((node: LabeledStatement & NodeParentExtension) => void) | undefined; Literal?: | ((node: Literal & NodeParentExtension) => void) | undefined; "Literal:exit"?: | ((node: Literal & NodeParentExtension) => void) | undefined; LogicalExpression?: | ((node: LogicalExpression & NodeParentExtension) => void) | undefined; "LogicalExpression:exit"?: | ((node: LogicalExpression & NodeParentExtension) => void) | undefined; MemberExpression?: | ((node: MemberExpression & NodeParentExtension) => void) | undefined; "MemberExpression:exit"?: | ((node: MemberExpression & NodeParentExtension) => void) | undefined; MetaProperty?: | ((node: MetaProperty & NodeParentExtension) => void) | undefined; "MetaProperty:exit"?: | ((node: MetaProperty & NodeParentExtension) => void) | undefined; MethodDefinition?: | ((node: MethodDefinition & NodeParentExtension) => void) | undefined; "MethodDefinition:exit"?: | ((node: MethodDefinition & NodeParentExtension) => void) | undefined; NewExpression?: | ((node: NewExpression & NodeParentExtension) => void) | undefined; "NewExpression:exit"?: | ((node: NewExpression & NodeParentExtension) => void) | undefined; ObjectExpression?: | ((node: ObjectExpression & NodeParentExtension) => void) | undefined; "ObjectExpression:exit"?: | ((node: ObjectExpression & NodeParentExtension) => void) | undefined; ObjectPattern?: | ((node: ObjectPattern & NodeParentExtension) => void) | undefined; "ObjectPattern:exit"?: | ((node: ObjectPattern & NodeParentExtension) => void) | undefined; PrivateIdentifier?: | ((node: PrivateIdentifier & NodeParentExtension) => void) | undefined; "PrivateIdentifier:exit"?: | ((node: PrivateIdentifier & NodeParentExtension) => void) | undefined; Program?: ((node: Program) => void) | undefined; "Program:exit"?: ((node: Program) => void) | undefined; Property?: | ((node: Property & NodeParentExtension) => void) | undefined; "Property:exit"?: | ((node: Property & NodeParentExtension) => void) | undefined; PropertyDefinition?: | ((node: PropertyDefinition & NodeParentExtension) => void) | undefined; "PropertyDefinition:exit"?: | ((node: PropertyDefinition & NodeParentExtension) => void) | undefined; RestElement?: | ((node: RestElement & NodeParentExtension) => void) | undefined; "RestElement:exit"?: | ((node: RestElement & NodeParentExtension) => void) | undefined; ReturnStatement?: | ((node: ReturnStatement & NodeParentExtension) => void) | undefined; "ReturnStatement:exit"?: | ((node: ReturnStatement & NodeParentExtension) => void) | undefined; SequenceExpression?: | ((node: SequenceExpression & NodeParentExtension) => void) | undefined; "SequenceExpression:exit"?: | ((node: SequenceExpression & NodeParentExtension) => void) | undefined; SpreadElement?: | ((node: SpreadElement & NodeParentExtension) => void) | undefined; "SpreadElement:exit"?: | ((node: SpreadElement & NodeParentExtension) => void) | undefined; StaticBlock?: | ((node: StaticBlock & NodeParentExtension) => void) | undefined; "StaticBlock:exit"?: | ((node: StaticBlock & NodeParentExtension) => void) | undefined; Super?: | ((node: Super & NodeParentExtension) => void) | undefined; "Super:exit"?: | ((node: Super & NodeParentExtension) => void) | undefined; SwitchCase?: | ((node: SwitchCase & NodeParentExtension) => void) | undefined; "SwitchCase:exit"?: | ((node: SwitchCase & NodeParentExtension) => void) | undefined; SwitchStatement?: | ((node: SwitchStatement & NodeParentExtension) => void) | undefined; "SwitchStatement:exit"?: | ((node: SwitchStatement & NodeParentExtension) => void) | undefined; TaggedTemplateExpression?: | (( node: TaggedTemplateExpression & NodeParentExtension, ) => void) | undefined; "TaggedTemplateExpression:exit"?: | (( node: TaggedTemplateExpression & NodeParentExtension, ) => void) | undefined; TemplateElement?: | ((node: TemplateElement & NodeParentExtension) => void) | undefined; "TemplateElement:exit"?: | ((node: TemplateElement & NodeParentExtension) => void) | undefined; TemplateLiteral?: | ((node: TemplateLiteral & NodeParentExtension) => void) | undefined; "TemplateLiteral:exit"?: | ((node: TemplateLiteral & NodeParentExtension) => void) | undefined; ThisExpression?: | ((node: ThisExpression & NodeParentExtension) => void) | undefined; "ThisExpression:exit"?: | ((node: ThisExpression & NodeParentExtension) => void) | undefined; ThrowStatement?: | ((node: ThrowStatement & NodeParentExtension) => void) | undefined; "ThrowStatement:exit"?: | ((node: ThrowStatement & NodeParentExtension) => void) | undefined; TryStatement?: | ((node: TryStatement & NodeParentExtension) => void) | undefined; "TryStatement:exit"?: | ((node: TryStatement & NodeParentExtension) => void) | undefined; UnaryExpression?: | ((node: UnaryExpression & NodeParentExtension) => void) | undefined; "UnaryExpression:exit"?: | ((node: UnaryExpression & NodeParentExtension) => void) | undefined; UpdateExpression?: | ((node: UpdateExpression & NodeParentExtension) => void) | undefined; "UpdateExpression:exit"?: | ((node: UpdateExpression & NodeParentExtension) => void) | undefined; VariableDeclaration?: | ((node: VariableDeclaration & NodeParentExtension) => void) | undefined; "VariableDeclaration:exit"?: | ((node: VariableDeclaration & NodeParentExtension) => void) | undefined; VariableDeclarator?: | ((node: VariableDeclarator & NodeParentExtension) => void) | undefined; "VariableDeclarator:exit"?: | ((node: VariableDeclarator & NodeParentExtension) => void) | undefined; WhileStatement?: | ((node: WhileStatement & NodeParentExtension) => void) | undefined; "WhileStatement:exit"?: | ((node: WhileStatement & NodeParentExtension) => void) | undefined; WithStatement?: | ((node: WithStatement & NodeParentExtension) => void) | undefined; "WithStatement:exit"?: | ((node: WithStatement & NodeParentExtension) => void) | undefined; YieldExpression?: | ((node: YieldExpression & NodeParentExtension) => void) | undefined; "YieldExpression:exit"?: | ((node: YieldExpression & NodeParentExtension) => void) | undefined; } interface NodeParentExtension { parent: Node; } type Node = Node & NodeParentExtension; interface RuleListener extends NodeListener { onCodePathStart?(codePath: CodePath, node: Node): void; onCodePathEnd?(codePath: CodePath, node: Node): void; onCodePathSegmentStart?(segment: CodePathSegment, node: Node): void; onCodePathSegmentEnd?(segment: CodePathSegment, node: Node): void; onCodePathSegmentLoop?( fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node, ): void; [key: string]: | ((codePath: CodePath, node: Node) => void) | ((segment: CodePathSegment, node: Node) => void) | (( fromSegment: CodePathSegment, toSegment: CodePathSegment, node: Node, ) => void) | ((node: Node) => void) | NodeListener[keyof NodeListener] | undefined; } type CodePathOrigin = | "program" | "function" | "class-field-initializer" | "class-static-block"; interface CodePath { id: string; origin: CodePathOrigin; initialSegment: CodePathSegment; finalSegments: CodePathSegment[]; returnedSegments: CodePathSegment[]; thrownSegments: CodePathSegment[]; upper: CodePath | null; childCodePaths: CodePath[]; } interface CodePathSegment { id: string; nextSegments: CodePathSegment[]; prevSegments: CodePathSegment[]; reachable: boolean; } interface RuleMetaData { /** Properties often used for documentation generation and tooling. */ docs?: | { /** Provides a short description of the rule. Commonly used when generating lists of rules. */ description?: string | undefined; /** Historically used by some plugins that divide rules into categories in their documentation. */ category?: string | undefined; /** Historically used by some plugins to indicate a rule belongs in their `recommended` configuration. */ recommended?: boolean | undefined; /** 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. */ url?: string | undefined; } | undefined; /** Violation and suggestion messages. */ messages?: { [messageId: string]: string } | undefined; /** * Specifies if the `--fix` option on the command line automatically fixes problems reported by the rule. * Mandatory for fixable rules. */ fixable?: "code" | "whitespace" | undefined; /** * Specifies the [options](https://eslint.org/docs/latest/extend/custom-rules#options-schemas) * so ESLint can prevent invalid [rule configurations](https://eslint.org/docs/latest/use/configure/rules#configuring-rules). * Mandatory for rules with options. */ schema?: JSONSchema4 | JSONSchema4[] | false | undefined; /** Any default options to be recursively merged on top of any user-provided options. */ defaultOptions?: unknown[]; /** Indicates whether the rule has been deprecated or provides additional metadata about the deprecation. Omit if not deprecated. */ deprecated?: boolean | DeprecatedInfo | undefined; /** * @deprecated Use deprecated.replacedBy instead. * The name of the rule(s) this rule was replaced by, if it was deprecated. */ replacedBy?: readonly string[]; /** * Indicates the type of rule: * - `"problem"` means the rule is identifying code that either will cause an error or may cause a confusing behavior. Developers should consider this a high priority to resolve. * - `"suggestion"` means the rule is identifying something that could be done in a better way but no errors will occur if the code isn't changed. * - `"layout"` means the rule cares primarily about whitespace, semicolons, commas, and parentheses, * all the parts of the program that determine how the code looks rather than how it executes. * These rules work on parts of the code that aren't specified in the AST. */ type?: "problem" | "suggestion" | "layout" | undefined; /** * Specifies whether the rule can return suggestions (defaults to `false` if omitted). * Mandatory for rules that provide suggestions. */ hasSuggestions?: boolean | undefined; } interface RuleContext extends RuleContext<{ LangOptions: Linter.LanguageOptions; Code: SourceCode; RuleOptions: any[]; Node: JSSyntaxElement; MessageIds: string; }> {} type ReportFixer = ( fixer: RuleFixer, ) => null | Fix | IterableIterator | Fix[]; interface ReportDescriptorOptionsBase { data?: { [key: string]: string }; fix?: null | ReportFixer; } interface SuggestionReportOptions { data?: { [key: string]: string }; fix: ReportFixer; } type SuggestionDescriptorMessage = { desc: string } | { messageId: string }; type SuggestionReportDescriptor = SuggestionDescriptorMessage & SuggestionReportOptions; interface ReportDescriptorOptions extends ReportDescriptorOptionsBase { suggest?: SuggestionReportDescriptor[] | null | undefined; } type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions; type ReportDescriptorMessage = { message: string } | { messageId: string }; type ReportDescriptorLocation = | { node: Node } | { loc: AST.SourceLocation | { line: number; column: number } }; interface RuleFixer { insertTextAfter( nodeOrToken: Node | AST.Token, text: string, ): Fix; insertTextAfterRange(range: AST.Range, text: string): Fix; insertTextBefore( nodeOrToken: Node | AST.Token, text: string, ): Fix; insertTextBeforeRange(range: AST.Range, text: string): Fix; remove(nodeOrToken: Node | AST.Token): Fix; removeRange(range: AST.Range): Fix; replaceText(nodeOrToken: Node | AST.Token, text: string): Fix; replaceTextRange(range: AST.Range, text: string): Fix; } interface Fix { range: AST.Range; text: string; } } // #region Linter export class Linter { static readonly version: string; version: string; constructor(options?: { cwd?: string | undefined; configType?: "flat" | "eslintrc"; }); verify( code: SourceCode | string, config: Linter.LegacyConfig | Linter.Config | Linter.Config[], filename?: string, ): Linter.LintMessage[]; verify( code: SourceCode | string, config: Linter.LegacyConfig | Linter.Config | Linter.Config[], options: Linter.LintOptions, ): Linter.LintMessage[]; verifyAndFix( code: string, config: Linter.LegacyConfig | Linter.Config | Linter.Config[], filename?: string, ): Linter.FixReport; verifyAndFix( code: string, config: Linter.LegacyConfig | Linter.Config | Linter.Config[], options: Linter.FixOptions, ): Linter.FixReport; getSourceCode(): SourceCode; defineRule(name: string, rule: Rule.RuleModule): void; defineRules(rules: { [name: string]: Rule.RuleModule }): void; getRules(): Map; defineParser(name: string, parser: Linter.Parser): void; getTimes(): Linter.Stats["times"]; getFixPassCount(): Linter.Stats["fixPasses"]; } export namespace Linter { /** * The numeric severity level for a rule. * * - `0` means off. * - `1` means warn. * - `2` means error. * * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities) */ type Severity = 0 | 1 | 2; /** * The human readable severity level for a rule. * * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities) */ type StringSeverity = "off" | "warn" | "error"; /** * The numeric or human readable severity level for a rule. * * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities) */ type RuleSeverity = Severity | StringSeverity; /** * An array containing the rule severity level, followed by the rule options. * * @see [Rules](https://eslint.org/docs/latest/use/configure/rules) */ type RuleSeverityAndOptions = [ RuleSeverity, ...Partial, ]; /** * The severity level for the rule or an array containing the rule severity level, followed by the rule options. * * @see [Rules](https://eslint.org/docs/latest/use/configure/rules) */ type RuleEntry = | RuleSeverity | RuleSeverityAndOptions; /** * The rules config object is a key/value map of rule names and their severity and options. */ interface RulesRecord { [rule: string]: RuleEntry; } /** * A configuration object that may have a `rules` block. */ interface HasRules { rules?: Partial | undefined; } /** * The ECMAScript version of the code being linted. */ type EcmaVersion = | 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 | 2021 | 2022 | 2023 | 2024 | 2025 | 2026 | "latest"; /** * The type of JavaScript source code. */ type SourceType = "script" | "module" | "commonjs"; /** * ESLint legacy configuration. * * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/) */ interface BaseConfig< Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules, > extends HasRules { $schema?: string | undefined; /** * An environment provides predefined global variables. * * @see [Environments](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-environments) */ env?: { [name: string]: boolean } | undefined; /** * Extending configuration files. * * @see [Extends](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#extending-configuration-files) */ extends?: string | string[] | undefined; /** * Specifying globals. * * @see [Globals](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-globals) */ globals?: Linter.Globals | undefined; /** * Disable processing of inline comments. * * @see [Disabling Inline Comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#disabling-inline-comments) */ noInlineConfig?: boolean | undefined; /** * Overrides can be used to use a differing configuration for matching sub-directories and files. * * @see [How do overrides work](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#how-do-overrides-work) */ overrides?: Array> | undefined; /** * Parser. * * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers) * @see [Specifying Parser](https://eslint.org/docs/latest/use/configure/parser-deprecated) */ parser?: string | undefined; /** * Parser options. * * @see [Working with Custom Parsers](https://eslint.org/docs/latest/extend/custom-parsers) * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options) */ parserOptions?: ParserOptions | undefined; /** * Which third-party plugins define additional rules, environments, configs, etc. for ESLint to use. * * @see [Configuring Plugins](https://eslint.org/docs/latest/use/configure/plugins-deprecated#configure-plugins) */ plugins?: string[] | undefined; /** * Specifying processor. * * @see [processor](https://eslint.org/docs/latest/use/configure/plugins-deprecated#specify-a-processor) */ processor?: string | undefined; /** * Report unused eslint-disable comments as warning. * * @see [Report unused eslint-disable comments](https://eslint.org/docs/latest/use/configure/rules-deprecated#report-unused-eslint-disable-comments) */ reportUnusedDisableDirectives?: boolean | undefined; /** * Settings. * * @see [Settings](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#adding-shared-settings) */ settings?: { [name: string]: any } | undefined; } /** * The overwrites that apply more differing configuration to specific files or directories. */ interface ConfigOverride extends BaseConfig { /** * The glob patterns for excluded files. */ excludedFiles?: string | string[] | undefined; /** * The glob patterns for target files. */ files: string | string[]; } /** * ESLint legacy configuration. * * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/) */ // https://github.com/eslint/eslint/blob/v8.57.0/conf/config-schema.js interface LegacyConfig< Rules extends RulesRecord = RulesRecord, OverrideRules extends RulesRecord = Rules, > extends BaseConfig { /** * Tell ESLint to ignore specific files and directories. * * @see [Ignore Patterns](https://eslint.org/docs/latest/use/configure/ignore-deprecated#ignorepatterns-in-config-files) */ ignorePatterns?: string | string[] | undefined; /** * @see [Using Configuration Files](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated#using-configuration-files) */ root?: boolean | undefined; } /** * Parser options. * * @see [Specifying Parser Options](https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options) */ interface ParserOptions { /** * Allow the use of reserved words as identifiers (if `ecmaVersion` is 3). * * @default false */ allowReserved?: boolean | undefined; /** * Accepts any valid ECMAScript version number or `'latest'`: * * - A version: es3, es5, es6, es7, es8, es9, es10, es11, es12, es13, es14, ..., or * - A year: es2015, es2016, es2017, es2018, es2019, es2020, es2021, es2022, es2023, ..., or * - `'latest'` * * When it's a version or a year, the value must be a number - so do not include the `es` prefix. * * Specifies the version of ECMAScript syntax you want to use. This is used by the parser to determine how to perform scope analysis, and it affects the default * * @default 5 */ ecmaVersion?: EcmaVersion | undefined; /** * The type of JavaScript source code. Possible values are "script" for * traditional script files, "module" for ECMAScript modules (ESM), and * "commonjs" for CommonJS files. * * @default 'script' * * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options */ sourceType?: SourceType | undefined; /** * An object indicating which additional language features you'd like to use. * * @see https://eslint.org/docs/latest/use/configure/language-options-deprecated#specifying-parser-options */ ecmaFeatures?: | { globalReturn?: boolean | undefined; impliedStrict?: boolean | undefined; jsx?: boolean | undefined; [key: string]: any; } | undefined; [key: string]: any; } interface LintOptions { filename?: string | undefined; preprocess?: ((code: string) => string[]) | undefined; postprocess?: | ((problemLists: LintMessage[][]) => LintMessage[]) | undefined; filterCodeBlock?: | ((filename: string, text: string) => boolean) | undefined; disableFixes?: boolean | undefined; allowInlineConfig?: boolean | undefined; reportUnusedDisableDirectives?: boolean | undefined; } interface LintSuggestion { /** A short description. */ desc: string; /** Fix result info. */ fix: Rule.Fix; /** Id referencing a message for the description. */ messageId?: string | undefined; } interface LintMessage { /** The 1-based column number. */ column: number; /** The 1-based line number. */ line: number; /** The 1-based column number of the end location. */ endColumn?: number | undefined; /** The 1-based line number of the end location. */ endLine?: number | undefined; /** The ID of the rule which makes this message. */ ruleId: string | null; /** The reported message. */ message: string; /** The ID of the message in the rule's meta. */ messageId?: string | undefined; /** * Type of node. * @deprecated `nodeType` is deprecated and will be removed in the next major version. */ nodeType?: string | undefined; /** If `true` then this is a fatal error. */ fatal?: true | undefined; /** The severity of this message. */ severity: Exclude; /** Information for autofix. */ fix?: Rule.Fix | undefined; /** Information for suggestions. */ suggestions?: LintSuggestion[] | undefined; } interface LintSuppression { kind: string; justification: string; } interface SuppressedLintMessage extends LintMessage { /** The suppression info. */ suppressions: LintSuppression[]; } interface FixOptions extends LintOptions { fix?: boolean | undefined; } interface FixReport { fixed: boolean; output: string; messages: LintMessage[]; } // Temporarily loosen type for just flat config files (see https://github.com/DefinitelyTyped/DefinitelyTyped/pull/68232) type NonESTreeParser = ESLint.ObjectMetaProperties & ( | { parse(text: string, options?: any): unknown; } | { parseForESLint( text: string, options?: any, ): Omit & { ast: unknown; scopeManager?: unknown; }; } ); type ESTreeParser = ESLint.ObjectMetaProperties & ( | { parse(text: string, options?: any): AST.Program } | { parseForESLint(text: string, options?: any): ESLintParseResult } ); type Parser = NonESTreeParser | ESTreeParser; interface ESLintParseResult { /** The AST object. */ ast: AST.Program; /** The services that the parser provides. */ services?: SourceCode.ParserServices | undefined; /** The scope manager of the AST. */ scopeManager?: Scope.ScopeManager | undefined; /** The visitor keys of the AST. */ visitorKeys?: SourceCode.VisitorKeys | undefined; } interface ProcessorFile { text: string; filename: string; } // https://eslint.org/docs/latest/extend/plugins#processors-in-plugins interface Processor< T extends string | ProcessorFile = string | ProcessorFile, > extends ESLint.ObjectMetaProperties { /** If `true` then it means the processor supports autofix. */ supportsAutofix?: boolean | undefined; /** The function to extract code blocks. */ preprocess?(text: string, filename: string): T[]; /** The function to merge messages. */ postprocess?( messages: LintMessage[][], filename: string, ): LintMessage[]; } interface Config { /** * An string to identify the configuration object. Used in error messages and * inspection tools. */ name?: string; /** * Path to the directory where the configuration object should apply. * `files` and `ignores` patterns in the configuration object are * interpreted as relative to this path. */ basePath?: string; /** * An array of glob patterns indicating the files that the configuration * object should apply to. If not specified, the configuration object applies * to all files */ files?: Array; /** * An array of glob patterns indicating the files that the configuration * object should not apply to. If not specified, the configuration object * applies to all files matched by files */ ignores?: string[]; /** * The name of the language used for linting. This is used to determine the * parser and other language-specific settings. * @since 9.7.0 */ language?: string; /** * An object containing settings related to how JavaScript is configured for * linting. */ languageOptions?: LanguageOptions; /** * An object containing settings related to the linting process */ linterOptions?: LinterOptions; /** * Either an object containing preprocess() and postprocess() methods or a * string indicating the name of a processor inside of a plugin * (i.e., "pluginName/processorName"). */ processor?: string | Processor; /** * An object containing a name-value mapping of plugin names to plugin objects. * When files is specified, these plugins are only available to the matching files. */ plugins?: Record; /** * An object containing the configured rules. When files or ignores are specified, * these rule configurations are only available to the matching files. */ rules?: Partial; /** * An object containing name-value pairs of information that should be * available to all rules. */ settings?: Record; } /** @deprecated Use `Config` instead of `FlatConfig` */ type FlatConfig = Config; type GlobalConf = | boolean | "off" | "readable" | "readonly" | "writable" | "writeable"; interface Globals { [name: string]: GlobalConf; } interface LanguageOptions extends LanguageOptions { /** * The version of ECMAScript to support. May be any year (i.e., 2022) or * version (i.e., 5). Set to "latest" for the most recent supported version. * @default "latest" */ ecmaVersion?: EcmaVersion | undefined; /** * The type of JavaScript source code. Possible values are "script" for * traditional script files, "module" for ECMAScript modules (ESM), and * "commonjs" for CommonJS files. (default: "module" for .js and .mjs * files; "commonjs" for .cjs files) */ sourceType?: SourceType | undefined; /** * An object specifying additional objects that should be added to the * global scope during linting. */ globals?: Globals | undefined; /** * An object containing a parse() or parseForESLint() method. * If not configured, the default ESLint parser (Espree) will be used. */ parser?: Parser | undefined; /** * An object specifying additional options that are passed directly to the * parser() method on the parser. The available options are parser-dependent */ parserOptions?: Linter.ParserOptions | undefined; } interface LinterOptions { /** * A boolean value indicating if inline configuration is allowed. */ noInlineConfig?: boolean; /** * A severity value indicating if and how unused disable directives should be * tracked and reported. */ reportUnusedDisableDirectives?: Severity | StringSeverity | boolean; /** * A severity value indicating if and how unused inline configs should be * tracked and reported. */ reportUnusedInlineConfigs?: Severity | StringSeverity; } /** * Performance statistics. */ interface Stats { /** * The number of times ESLint has applied at least one fix after linting. */ fixPasses: number; /** * The times spent on (parsing, fixing, linting) a file, where the linting refers to the timing information for each rule. */ times: { passes: TimePass[] }; } interface TimePass { /** * The parse object containing all parse time information. */ parse: { total: number }; /** * The rules object containing all lint time information for each rule. */ rules?: Record; /** * The fix object containing all fix time information. */ fix: { total: number }; /** * The total time that is spent on (parsing, fixing, linting) a file. */ total: number; } } // #endregion // #region ESLint export class ESLint { static configType: "flat"; static readonly version: string; /** * The default configuration that ESLint uses internally. This is provided for tooling that wants to calculate configurations using the same defaults as ESLint. * Keep in mind that the default configuration may change from version to version, so you shouldn't rely on any particular keys or values to be present. */ static readonly defaultConfig: Linter.Config[]; static outputFixes(results: ESLint.LintResult[]): Promise; static getErrorResults(results: ESLint.LintResult[]): ESLint.LintResult[]; constructor(options?: ESLint.Options); lintFiles(patterns: string | string[]): Promise; lintText( code: string, options?: { filePath?: string | undefined; warnIgnored?: boolean | undefined; }, ): Promise; getRulesMetaForResults( results: ESLint.LintResult[], ): ESLint.LintResultData["rulesMeta"]; hasFlag(flag: string): boolean; calculateConfigForFile(filePath: string): Promise; findConfigFile(): Promise; isPathIgnored(filePath: string): Promise; loadFormatter(nameOrPath?: string): Promise; static fromOptionsModule(optionsURL: { readonly href: string; }): Promise; } export namespace ESLint { type ConfigData = Omit, "$schema">; interface Environment { /** The definition of global variables. */ globals?: Linter.Globals | undefined; /** The parser options that will be enabled under this environment. */ parserOptions?: Linter.ParserOptions | undefined; } interface ObjectMetaProperties { /** @deprecated Use `meta.name` instead. */ name?: string | undefined; /** @deprecated Use `meta.version` instead. */ version?: string | undefined; meta?: { name?: string | undefined; version?: string | undefined; }; } interface Plugin extends ObjectMetaProperties { meta?: ObjectMetaProperties["meta"] & { namespace?: string | undefined; }; configs?: | Record< string, Linter.LegacyConfig | Linter.Config | Linter.Config[] > | undefined; environments?: Record | undefined; languages?: Record | undefined; processors?: Record | undefined; rules?: Record | undefined; } type FixType = "directive" | "problem" | "suggestion" | "layout"; type CacheStrategy = "content" | "metadata"; interface Options { // File enumeration cwd?: string | undefined; errorOnUnmatchedPattern?: boolean | undefined; globInputPaths?: boolean | undefined; ignore?: boolean | undefined; ignorePatterns?: string[] | null | undefined; passOnNoPatterns?: boolean | undefined; warnIgnored?: boolean | undefined; // Linting allowInlineConfig?: boolean | undefined; baseConfig?: Linter.Config | Linter.Config[] | null | undefined; overrideConfig?: Linter.Config | Linter.Config[] | null | undefined; overrideConfigFile?: string | true | null | undefined; plugins?: Record | null | undefined; ruleFilter?: | ((arg: { ruleId: string; severity: Exclude; }) => boolean) | undefined; stats?: boolean | undefined; // Autofix fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined; fixTypes?: FixType[] | undefined; // Cache-related cache?: boolean | undefined; cacheLocation?: string | undefined; cacheStrategy?: CacheStrategy | undefined; // Other Options concurrency?: number | "auto" | "off" | undefined; flags?: string[] | undefined; } interface LegacyOptions { // File enumeration cwd?: string | undefined; errorOnUnmatchedPattern?: boolean | undefined; extensions?: string[] | undefined; globInputPaths?: boolean | undefined; ignore?: boolean | undefined; ignorePath?: string | undefined; // Linting allowInlineConfig?: boolean | undefined; baseConfig?: Linter.LegacyConfig | undefined; overrideConfig?: Linter.LegacyConfig | undefined; overrideConfigFile?: string | undefined; plugins?: Record | undefined; reportUnusedDisableDirectives?: Linter.StringSeverity | undefined; resolvePluginsRelativeTo?: string | undefined; rulePaths?: string[] | undefined; useEslintrc?: boolean | undefined; // Autofix fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined; fixTypes?: FixType[] | undefined; // Cache-related cache?: boolean | undefined; cacheLocation?: string | undefined; cacheStrategy?: CacheStrategy | undefined; // Other Options flags?: string[] | undefined; } /** A linting result. */ interface LintResult { /** The path to the file that was linted. */ filePath: string; /** All of the messages for the result. */ messages: Linter.LintMessage[]; /** All of the suppressed messages for the result. */ suppressedMessages: Linter.SuppressedLintMessage[]; /** Number of errors for the result. */ errorCount: number; /** Number of fatal errors for the result. */ fatalErrorCount: number; /** Number of warnings for the result. */ warningCount: number; /** Number of fixable errors for the result. */ fixableErrorCount: number; /** Number of fixable warnings for the result. */ fixableWarningCount: number; /** The source code of the file that was linted, with as many fixes applied as possible. */ output?: string | undefined; /** The source code of the file that was linted. */ source?: string | undefined; /** The performance statistics collected with the `stats` flag. */ stats?: Linter.Stats | undefined; /** The list of used deprecated rules. */ usedDeprecatedRules: DeprecatedRuleUse[]; } /** * Information provided when the maximum warning threshold is exceeded. */ interface MaxWarningsExceeded { /** * Number of warnings to trigger nonzero exit code. */ maxWarnings: number; /** * Number of warnings found while linting. */ foundWarnings: number; } interface LintResultData { cwd: string; maxWarningsExceeded?: MaxWarningsExceeded | undefined; rulesMeta: { [ruleId: string]: Rule.RuleMetaData; }; } /** * Information about deprecated rules. */ interface DeprecatedRuleUse { /** * The rule ID. */ ruleId: string; /** * The rule IDs that replace this deprecated rule. */ replacedBy: string[]; /** * The raw deprecated info provided by the rule. * Unset if the rule's `meta.deprecated` property is a boolean. */ info?: DeprecatedInfo; } /** * Metadata about results for formatters. */ interface ResultsMeta { /** * Present if the maxWarnings threshold was exceeded. */ maxWarningsExceeded?: MaxWarningsExceeded | undefined; } /** The type of an object resolved by {@link ESLint.loadFormatter}. */ interface LoadedFormatter { /** * Used to call the underlying formatter. * @param results An array of lint results to format. * @param resultsMeta An object with an optional `maxWarningsExceeded` property that will be * passed to the underlying formatter function along with other properties set by ESLint. * This argument can be omitted if `maxWarningsExceeded` is not needed. * @return The formatter output. */ format( results: LintResult[], resultsMeta?: ResultsMeta, ): string | Promise; } // The documented type name is `LoadedFormatter`, but `Formatter` has been historically more used. type Formatter = LoadedFormatter; /** * The expected signature of a custom formatter. * @param results An array of lint results to format. * @param context Additional information for the formatter. * @return The formatter output. */ type FormatterFunction = ( results: LintResult[], context: LintResultData, ) => string | Promise; // Docs reference the types by those name type EditInfo = Rule.Fix; } // #region RuleTester export class RuleTester { static describe: ((...args: any) => any) | null; static it: ((...args: any) => any) | null; static itOnly: ((...args: any) => any) | null; constructor(config?: Linter.Config); run( name: string, rule: RuleDefinition, tests: { valid: Array; invalid: RuleTester.InvalidTestCase[]; }, ): void; static only( item: string | RuleTester.ValidTestCase | RuleTester.InvalidTestCase, ): RuleTester.ValidTestCase | RuleTester.InvalidTestCase; } export namespace RuleTester { interface ValidTestCase { name?: string; code: string; options?: any; filename?: string | undefined; only?: boolean; languageOptions?: Linter.LanguageOptions | undefined; settings?: { [name: string]: any } | undefined; before?: () => void; after?: () => void; } interface SuggestionOutput { messageId?: string; desc?: string; data?: Record | undefined; output: string; } interface InvalidTestCase extends ValidTestCase { errors: number | Array; output?: string | null | undefined; } interface TestCaseError { message?: string | RegExp; messageId?: string; /** * @deprecated `type` is deprecated and will be removed in the next major version. */ type?: string | undefined; data?: any; line?: number | undefined; column?: number | undefined; endLine?: number | undefined; endColumn?: number | undefined; suggestions?: SuggestionOutput[] | undefined; } } // #endregion /** * Infinite array type. */ type InfiniteArray = T | InfiniteArray[]; /** * The type of array element in the `extends` property after flattening. */ type SimpleExtendsElement = string | Linter.Config; /** * The type of array element in the `extends` property before flattening. */ type ExtendsElement = | SimpleExtendsElement | InfiniteArray; /** * Config with extends. Valid only inside of `defineConfig()`. */ interface ConfigWithExtends extends Linter.Config { extends?: ExtendsElement[]; } type ConfigWithExtendsArray = InfiniteArray[]; export { AST as A, Linter as L, Rule as R, Scope as S, RuleTester as b, SourceCode as d }; export type { ConfigWithExtends as C, ExtendsElement as E, InfiniteArray as I, ConfigWithExtendsArray as a, SimpleExtendsElement as c };