import { BaseConfig as CoreBaseConfig, ConfigObject, ConfigOverride as CoreConfigOverride, DeprecatedInfo, EcmaVersion as CoreEcmaVersion, EnvironmentConfig, GlobalAccess, GlobalsConfig, HasRules as CoreHasRules, JavaScriptSourceType, LanguageOptions as GenericLanguageOptions, LegacyConfigObject, LintMessage as CoreLintMessage, LintSuggestion as CoreLintSuggestion, LinterOptionsConfig, ObjectMetaProperties as CoreObjectMetaProperties, Plugin as CorePlugin, Processor as CoreProcessor, ProcessorFile as CoreProcessorFile, RuleConfig, RuleContext as CoreRuleContext, RuleDefinition, RuleFixer as CoreRuleFixer, RuleTextEdit, RuleTextEditor, RulesConfig, RulesMeta, Severity as CoreSeverity, SeverityLevel, SeverityName, SourceRange, SuggestedEdit, SuggestedEditBase, SuggestionMessage, TextSourceCode, TraversalStep, ViolationLocation, ViolationMessage, ViolationReport, ViolationReportBase } from '@eslint/core'; import { CustomRuleVisitorWithExit } from '@eslint/plugin-kit'; import * as ESTree from 'estree'; import * as lsp from 'vscode-languageserver-protocol'; import { LSPAny, TextDocumentIdentifier, TextDocumentItem } from 'vscode-languageserver-protocol'; import { TextDocument } from 'vscode-languageserver-textdocument'; declare namespace AST { type TokenType = "Boolean" | "Null" | "Identifier" | "PrivateIdentifier" | "Keyword" | "Punctuator" | "JSXIdentifier" | "JSXText" | "Numeric" | "String" | "Template" | "RegularExpression"; interface Token { type: TokenType; value: string; range: Range; loc: SourceLocation; } interface SourceLocation { start: ESTree.Position; end: ESTree.Position; } type Range = SourceRange; interface Program extends ESTree.Program { comments: ESTree.Comment[]; tokens: Token[]; loc: SourceLocation; range: Range; } } export interface JSXIdentifier extends ESTree.BaseNode { type: "JSXIdentifier"; name: string; } declare namespace Scope { interface ScopeManager { scopes: Scope[]; globalScope: Scope | null; acquire(node: ESTree.Node, inner?: boolean): Scope | null; getDeclaredVariables(node: ESTree.Node): Variable[]; addGlobals(names: ReadonlyArray): void; } interface Scope { type: "block" | "catch" | "class" | "class-field-initializer" | "class-static-block" | "for" | "function" | "function-expression-name" | "global" | "module" | "switch" | "with"; isStrict: boolean; upper: Scope | null; childScopes: Scope[]; variableScope: Scope; block: ESTree.Node; variables: Variable[]; set: Map; references: Reference[]; through: Reference[]; functionExpressionScope: boolean; implicit?: { variables: Variable[]; set: Map; }; } interface Variable { name: string; scope: Scope; identifiers: ESTree.Identifier[]; references: Reference[]; defs: Definition[]; } interface Reference { identifier: ESTree.Identifier | JSXIdentifier; from: Scope; resolved: Variable | null; writeExpr?: ESTree.Expression | null; init?: boolean; isWrite(): boolean; isRead(): boolean; isWriteOnly(): boolean; isReadOnly(): boolean; isReadWrite(): boolean; } type DefinitionType = { type: "CatchClause"; node: ESTree.CatchClause; parent: null; } | { type: "ClassName"; node: ESTree.ClassDeclaration | ESTree.ClassExpression; parent: null; } | { type: "FunctionName"; node: ESTree.FunctionDeclaration | ESTree.FunctionExpression; parent: null; } | { type: "ImplicitGlobalVariable"; node: ESTree.AssignmentExpression | ESTree.ForInStatement | ESTree.ForOfStatement; parent: null; } | { type: "ImportBinding"; node: ESTree.ImportSpecifier | ESTree.ImportDefaultSpecifier | ESTree.ImportNamespaceSpecifier; parent: ESTree.ImportDeclaration; } | { type: "Parameter"; node: ESTree.FunctionDeclaration | ESTree.FunctionExpression | ESTree.ArrowFunctionExpression; parent: null; } | { type: "Variable"; node: ESTree.VariableDeclarator; parent: ESTree.VariableDeclaration; }; type Definition = DefinitionType & { name: ESTree.Identifier; }; } declare class SourceCode implements TextSourceCode<{ LangOptions: Linter.LanguageOptions; RootNode: AST.Program; SyntaxElementWithLoc: AST.Token | ESTree.Node | ESTree.Comment; ConfigNode: ESTree.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 | ESTree.Node | ESTree.Comment): ESTree.SourceLocation; getRange(syntaxElement: AST.Token | ESTree.Node | ESTree.Comment): SourceRange; getText(node?: ESTree.Node | AST.Token | ESTree.Comment, beforeCount?: number, afterCount?: number): string; getLines(): string[]; getAllComments(): ESTree.Comment[]; getAncestors(node: ESTree.Node): ESTree.Node[]; getDeclaredVariables(node: ESTree.Node): Scope.Variable[]; getNodeByRangeIndex(index: number): ESTree.Node | null; getLocFromIndex(index: number): ESTree.Position; getIndexFromLoc(location: ESTree.Position): number; // Inherited methods from TokenStore // --------------------------------- getTokenByRangeStart(offset: number, options?: { includeComments: false; }): AST.Token | null; getTokenByRangeStart(offset: number, options: { includeComments: boolean; }): AST.Token | ESTree.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: ESTree.Node, beforeCount?: number, afterCount?: number) => AST.Token[]) & SourceCode.UnaryNodeCursorWithCountOptions; commentsExistBetween(left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment): boolean; getCommentsBefore(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[]; getCommentsAfter(nodeOrToken: ESTree.Node | AST.Token): ESTree.Comment[]; getCommentsInside(node: ESTree.Node): ESTree.Comment[]; getScope(node: ESTree.Node): Scope.Scope; isSpaceBetween(first: ESTree.Node | AST.Token, second: ESTree.Node | AST.Token): boolean; isGlobalReference(node: ESTree.Identifier): boolean; markVariableAsUsed(name: string, refNode?: ESTree.Node): boolean; traverse(): Iterable; } declare namespace SourceCode { interface Config { text: string; ast: AST.Program; hasBOM?: boolean | undefined; parserServices?: ParserServices | null | undefined; scopeManager?: Scope.ScopeManager | null | undefined; visitorKeys?: VisitorKeys | null | undefined; } type ParserServices = any; interface VisitorKeys { [nodeType: string]: string[]; } interface UnaryNodeCursorWithSkipOptions { (node: ESTree.Node, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }): T | null; (node: ESTree.Node, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }): T | null; (node: ESTree.Node, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token | null; (node: ESTree.Node, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }): AST.Token | ESTree.Comment | null; } interface UnaryNodeCursorWithCountOptions { (node: ESTree.Node, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }): T[]; (node: ESTree.Node, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }): T[]; (node: ESTree.Node, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token[]; (node: ESTree.Node, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }): Array; } interface UnaryCursorWithSkipOptions { (node: ESTree.Node | AST.Token | ESTree.Comment, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }): T | null; (node: ESTree.Node | AST.Token | ESTree.Comment, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }): T | null; (node: ESTree.Node | AST.Token | ESTree.Comment, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token | null; (node: ESTree.Node | AST.Token | ESTree.Comment, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }): AST.Token | ESTree.Comment | null; } interface UnaryCursorWithCountOptions { (node: ESTree.Node | AST.Token | ESTree.Comment, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }): T[]; (node: ESTree.Node | AST.Token | ESTree.Comment, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }): T[]; (node: ESTree.Node | AST.Token | ESTree.Comment, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token[]; (node: ESTree.Node | AST.Token | ESTree.Comment, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }): Array; } interface BinaryCursorWithSkipOptions { (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; skip?: number | undefined; }): T | null; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; skip?: number | undefined; }): T | null; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; skip?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token | null; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; skip?: number | undefined; }): AST.Token | ESTree.Comment | null; } interface BinaryCursorWithCountOptions { (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: ((token: AST.Token) => token is T) | { filter: (token: AST.Token) => token is T; includeComments?: false | undefined; count?: number | undefined; }): T[]; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: { filter: (tokenOrComment: AST.Token | ESTree.Comment) => tokenOrComment is T; includeComments: boolean; count?: number | undefined; }): T[]; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options?: { filter?: ((token: AST.Token) => boolean) | undefined; includeComments?: false | undefined; count?: number | undefined; } | ((token: AST.Token) => boolean) | number): AST.Token[]; (left: ESTree.Node | AST.Token | ESTree.Comment, right: ESTree.Node | AST.Token | ESTree.Comment, options: { filter?: ((token: AST.Token | ESTree.Comment) => boolean) | undefined; includeComments: boolean; count?: number | undefined; }): Array; } } // #endregion export type JSSyntaxElement = { type: string; loc?: ESTree.SourceLocation | null | undefined; }; declare namespace Rule { interface RuleModule extends RuleDefinition<{ LangOptions: Linter.LanguageOptions; Code: SourceCode; RuleOptions: any[]; Visitor: RuleListener; Node: JSSyntaxElement; MessageIds: string; ExtRuleDocs: {}; }> { create(context: RuleContext): RuleListener; } type NodeTypes = ESTree.Node["type"]; interface NodeListener extends CustomRuleVisitorWithExit<{ [Node in Rule.Node as Node["type"]]?: ((node: Node) => void) | undefined; } & { // A `Program` visitor's node type has no `parent` property. Program?: ((node: AST.Program) => void) | undefined; }> { } interface NodeParentExtension { parent: Node; } type Node = (AST.Program & { parent: null; }) | (Exclude & 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; onUnreachableCodePathSegmentStart?(segment: CodePathSegment, node: Node): void; onUnreachableCodePathSegmentEnd?(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 CodePathSegmentTraversalController { skip(): void; break(): void; } type CodePathSegmentTraversalCallback = (this: CodePath, segment: CodePathSegment, controller: CodePathSegmentTraversalController) => void; interface CodePathTraversalOptions { first?: CodePathSegment | undefined; last?: CodePathSegment | undefined; } interface CodePath { id: string; origin: CodePathOrigin; initialSegment: CodePathSegment; finalSegments: CodePathSegment[]; returnedSegments: CodePathSegment[]; thrownSegments: CodePathSegment[]; upper: CodePath | null; childCodePaths: CodePath[]; traverseSegments(callback: CodePathSegmentTraversalCallback): void; traverseSegments(options: CodePathTraversalOptions, callback: CodePathSegmentTraversalCallback): void; } interface CodePathSegment { id: string; nextSegments: CodePathSegment[]; prevSegments: CodePathSegment[]; allNextSegments: CodePathSegment[]; allPrevSegments: CodePathSegment[]; reachable: boolean; } type RuleMetaData = RulesMeta; interface RuleContext extends CoreRuleContext<{ LangOptions: Linter.LanguageOptions; Code: SourceCode; RuleOptions: any[]; Node: JSSyntaxElement; MessageIds: string; }> { } type ReportFixer = CoreRuleFixer; /** @deprecated Use `ReportDescriptorOptions` instead. */ type ReportDescriptorOptionsBase = Omit; type SuggestionReportOptions = SuggestedEditBase; type SuggestionDescriptorMessage = SuggestionMessage; type SuggestionReportDescriptor = SuggestedEdit; // redundant with ReportDescriptorOptionsBase but kept for clarity type ReportDescriptorOptions = ViolationReportBase; type ReportDescriptor = ViolationReport; type ReportDescriptorMessage = ViolationMessage; type ReportDescriptorLocation = ViolationLocation; type RuleFixer = RuleTextEditor; type Fix = RuleTextEdit; } declare class Linter { static readonly version: string; version: string; constructor(options?: { cwd?: string | undefined; configType?: "flat"; }); verify(code: SourceCode | string, config: Linter.Config | Linter.Config[], filename?: string): Linter.LintMessage[]; verify(code: SourceCode | string, config: Linter.Config | Linter.Config[], options: Linter.LintOptions): Linter.LintMessage[]; verifyAndFix(code: string, config: Linter.Config | Linter.Config[], filename?: string): Linter.FixReport; verifyAndFix(code: string, config: Linter.Config | Linter.Config[], options: Linter.FixOptions): Linter.FixReport; getSourceCode(): SourceCode; getTimes(): Linter.Stats["times"]; getFixPassCount(): Linter.Stats["fixPasses"]; } declare 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 = SeverityLevel; /** * The human readable severity level for a rule. * * @see [Rule Severities](https://eslint.org/docs/latest/use/configure/rules#rule-severities) */ type StringSeverity = SeverityName; /** * 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 = CoreSeverity; /** * 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 = RuleConfig; /** * The rules config object is a key/value map of rule names and their severity and options. */ type RulesRecord = RulesConfig; /** * A configuration object that may have a `rules` block. */ type HasRules = CoreHasRules; /** * The ECMAScript version of the code being linted. */ type EcmaVersion = CoreEcmaVersion; /** * The type of JavaScript source code. */ type SourceType = JavaScriptSourceType; /** * ESLint legacy configuration. * * @see [ESLint Legacy Configuration](https://eslint.org/docs/latest/use/configure/) */ type BaseConfig = CoreBaseConfig; /** * The overwrites that apply more differing configuration to specific files or directories. */ type ConfigOverride = CoreConfigOverride; /** * 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 type LegacyConfig = LegacyConfigObject; /** * 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; /** * An object indicating which additional language features you'd like to use. * * @see https://eslint.org/docs/latest/use/configure/language-options#specifying-parser-options */ ecmaFeatures?: { /** * Allow `return` statements in the global scope. * * @default false */ globalReturn?: boolean | undefined; /** * Enable global [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) (if `ecmaVersion` is 5 or greater). * * @default false */ impliedStrict?: boolean | undefined; /** * Enable [JSX](https://react.github.io/jsx/). * * @default false */ jsx?: boolean | undefined; [key: string]: any; } | undefined; [key: string]: any; } /** * Options used for linting code with `Linter#verify` and `Linter#verifyAndFix`. */ 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; } type LintSuggestion = CoreLintSuggestion; type LintMessage = CoreLintMessage; 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; } type ProcessorFile = CoreProcessorFile; // https://eslint.org/docs/latest/extend/plugins#processors-in-plugins type Processor = CoreProcessor; type Config = ConfigObject; /** @deprecated Use `Config` instead of `FlatConfig` */ type FlatConfig = Config; type GlobalConf = GlobalAccess; type Globals = GlobalsConfig; interface LanguageOptions extends GenericLanguageOptions { /** * 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; } type LinterOptions = LinterOptionsConfig; /** * 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. * If no parsing was performed, the property is omitted. */ 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; } } declare 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(filePath?: string): Promise; isPathIgnored(filePath: string): Promise; loadFormatter(nameOrPath?: string): Promise; static fromOptionsModule(optionsURL: { readonly href: string; }): Promise; } declare namespace ESLint { type ConfigData = Omit, "$schema">; type Environment = EnvironmentConfig; type ObjectMetaProperties = CoreObjectMetaProperties; type Plugin = CorePlugin; type FixType = "directive" | "problem" | "suggestion" | "layout"; type CacheStrategy = "content" | "metadata"; /** The options with which to configure the ESLint instance. */ interface Options { // File enumeration /** The value to use for the current working directory. */ cwd?: string | undefined; /** If `false` then `ESLint#lintFiles()` doesn't throw even if no target files found. Defaults to `true`. */ errorOnUnmatchedPattern?: boolean | undefined; /** * Set to false to skip glob resolution of input file paths to lint (default: true). * If false, each input file path is assumed to be a non-glob path to an existing file. */ globInputPaths?: boolean | undefined; /** False disables all ignore patterns except for the default ones. */ ignore?: boolean | undefined; /** Ignore file patterns to use in addition to config ignores. These patterns are relative to `cwd`. */ ignorePatterns?: string[] | null | undefined; /** When set to true, missing patterns cause the linting operation to short circuit and not report any failures. */ passOnNoPatterns?: boolean | undefined; /** Show warnings when the file list includes ignored files. */ warnIgnored?: boolean | undefined; // Linting /** Enable or disable inline configuration comments. */ allowInlineConfig?: boolean | undefined; /** Base config, extended by all configs used with this instance. */ baseConfig?: Linter.Config | Linter.Config[] | null | undefined; /** Override config, overrides all configs used with this instance. */ overrideConfig?: Linter.Config | Linter.Config[] | null | undefined; /** * Searches for default config file when falsy; doesn't do any config file lookup when `true`; considered to be a config filename when a string. */ overrideConfigFile?: string | true | null | undefined; /** An array of plugin implementations. */ plugins?: Record | null | undefined; /** * Default is `() => true`. A predicate function that filters rules to be run. * This function is called with an object containing `ruleId` and `severity`, and returns `true` if the rule should be run. */ ruleFilter?: ((arg: { ruleId: string; severity: Exclude; }) => boolean) | undefined; /** True enables added statistics on lint results. */ stats?: boolean | undefined; // Autofix /** Execute in autofix mode. If a function, should return a boolean. */ fix?: boolean | ((message: Linter.LintMessage) => boolean) | undefined; /** Array of rule types to apply fixes for. */ fixTypes?: FixType[] | null | undefined; // Cache-related /** Enable result caching. */ cache?: boolean | undefined; /** The cache file to use instead of .eslintcache. */ cacheLocation?: string | undefined; /** The strategy used to detect changed files. */ cacheStrategy?: CacheStrategy | undefined; /** If true, apply suppressions automatically. Defaults to false. */ applySuppressions?: boolean | undefined; /** Path to suppressions file. Relative to cwd. Defaults to eslint-suppressions.json in cwd. */ suppressionsLocation?: string | undefined; // Other Options /** Maximum number of linting threads, "auto" to choose automatically, "off" for no multithreading. */ concurrency?: number | "auto" | "off" | undefined; /** Array of feature flags to enable. */ 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 extends ResultsMeta { cwd: string; 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. * - Undefined if the rule's `meta.deprecated` property is a boolean. * - Unset when using the legacy eslintrc configuration. */ info?: DeprecatedInfo | undefined; } /** * Metadata about results for formatters. */ interface ResultsMeta { /** * Whether or not to use color in the formatter output. * - If `--color` was set, this property is `true`. * - If `--no-color` was set, it is `false`. * - If neither option was provided, the property is omitted. */ color?: boolean | undefined; /** * 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 optional `color` and `maxWarningsExceeded` properties that will be * passed to the underlying formatter function along with other properties set by ESLint. * This argument can be omitted if `color` and `maxWarningsExceeded` are 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; } export interface LanguageService { documents: { [documentUri: string]: TextDocument; }; serviceName: string; mode: string; globalOptions: ServiceOptions; serviceData: LanguageClientConfig | ServiceConfig; serviceCapabilities: lsp.ServerCapabilities; workspaceUri?: string; format(document: lsp.TextDocumentIdentifier, range: lsp.Range, options: lsp.FormattingOptions): Promise; doHover(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; doValidation(document: lsp.TextDocumentIdentifier): Promise; doComplete(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; doInlineComplete(document: lsp.VersionedTextDocumentIdentifier, position: lsp.Position): Promise; doResolve(item: lsp.CompletionItem): Promise; setValue(identifier: lsp.VersionedTextDocumentIdentifier, value: string): void; applyDeltas(identifier: lsp.VersionedTextDocumentIdentifier, deltas: lsp.TextDocumentContentChangeEvent[]): void; addDocument(document: TextDocumentItem): void; setOptions(documentUri: string, options: ServiceOptions, merge?: boolean): void; setGlobalOptions(options: ServiceOptions): void; getDocument(uri: string): TextDocument; removeDocument(document: TextDocumentIdentifier): void; renameDocument(document: TextDocumentIdentifier, newDocumentUri: string): void; getDocumentValue(uri: string): string | undefined; provideSignatureHelp(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; findDocumentHighlights(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; getSemanticTokens(document: lsp.TextDocumentIdentifier, range: lsp.Range): Promise; getCodeActions(document: lsp.TextDocumentIdentifier, range: lsp.Range, context: lsp.CodeActionContext): Promise<(lsp.Command | lsp.CodeAction)[] | null>; executeCommand(command: string, args?: lsp.LSPAny[]): Promise; sendAppliedResult(result: lsp.ApplyWorkspaceEditResult, callbackId: number): void; dispose(): Promise; closeConnection(): Promise; setWorkspace(workspaceUri: string): void; sendRequest(name: string, args?: lsp.LSPAny): Promise; sendResponse(callbackId: number, args?: lsp.LSPAny): void; } export interface ServiceOptions { [name: string]: any; } export interface ServiceOptionsWithErrorMessages { errorMessagesToIgnore?: RegExp[]; errorMessagesToTreatAsWarning?: RegExp[]; errorMessagesToTreatAsInfo?: RegExp[]; } export interface JavascriptServiceOptions extends ServiceOptionsWithErrorMessages, Linter.FlatConfig { } export type ServiceFeatures = { [feature in SupportedFeatures]?: boolean; }; export type SupportedFeatures = "hover" | "completion" | "completionResolve" | "format" | "diagnostics" | "signatureHelp" | "documentHighlight" | "semanticTokens" | "codeAction" | "executeCommand" | "inlineCompletion"; export interface ServiceConfig extends BaseConfig { className: string; options?: ServiceOptions; } export interface BaseConfig { serviceName?: string; initializationOptions?: ServiceOptions; options?: ServiceOptions; serviceInstance?: LanguageService; /** * language modes separated with |; * means all available languages */ modes: string; className?: string; features?: ServiceFeatures; module: () => any; id?: string; } export interface WebWorkerConnection { type: "webworker"; worker: Worker; } export interface SocketConnection { type: "socket"; socket: WebSocket; } export interface StdioConnection { type: "stdio"; command: string; } export interface IpcConnection { type: "ipc"; ipcPath: string; } export type ConnectionType = WebWorkerConnection | SocketConnection | StdioConnection | IpcConnection; export type LanguageClientConfig = BaseConfig & ConnectionType; export interface FilterDiagnosticsOptions { errorCodesToIgnore?: string[]; errorCodesToTreatAsWarning?: string[]; errorCodesToTreatAsInfo?: string[]; errorMessagesToIgnore?: RegExp[]; errorMessagesToTreatAsWarning?: RegExp[]; errorMessagesToTreatAsInfo?: RegExp[]; } declare abstract class BaseService implements LanguageService { serviceName: string; mode: string; documents: { [documentUri: lsp.DocumentUri]: TextDocument; }; options: { [documentUri: string]: OptionsType; }; globalOptions: OptionsType; serviceData: ServiceConfig; serviceCapabilities: lsp.ServerCapabilities; workspaceUri?: string; clientCapabilities: lsp.ClientCapabilities; protected constructor(mode: string, workspaceUri?: string); addDocument(document: lsp.TextDocumentItem): void; getDocument(uri: string): TextDocument; removeDocument(document: lsp.TextDocumentIdentifier): void; renameDocument(document: lsp.TextDocumentIdentifier, newDocumentUri: string): void; getDocumentValue(uri: string): string | undefined; setValue(identifier: lsp.VersionedTextDocumentIdentifier, value: string): void; setGlobalOptions(options: OptionsType): void; setWorkspace(workspaceUri: string): void; setOptions(documentUri: string, options: OptionsType, merge?: boolean): void; getOption(documentUri: string, optionName: T): OptionsType[T]; applyDeltas(identifier: lsp.VersionedTextDocumentIdentifier, deltas: lsp.TextDocumentContentChangeEvent[]): void; doComplete(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; doInlineComplete(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; doHover(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; doResolve(item: lsp.CompletionItem): Promise; doValidation(document: lsp.TextDocumentIdentifier): Promise; format(document: lsp.TextDocumentIdentifier, range: lsp.Range, options: lsp.FormattingOptions): Promise; provideSignatureHelp(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; findDocumentHighlights(document: lsp.TextDocumentIdentifier, position: lsp.Position): Promise; get optionsToFilterDiagnostics(): FilterDiagnosticsOptions; getSemanticTokens(document: lsp.TextDocumentIdentifier, range: lsp.Range): Promise; dispose(): Promise; closeConnection(): Promise; getCodeActions(document: lsp.TextDocumentIdentifier, range: lsp.Range, context: lsp.CodeActionContext): Promise<(lsp.Command | lsp.CodeAction)[] | null>; executeCommand(command: string, args?: any[]): Promise; sendAppliedResult(result: lsp.ApplyWorkspaceEditResult, callbackId: number): void; sendRequest(name: string, args?: LSPAny): Promise; sendResponse(callbackId: number, args?: LSPAny): void; } export declare class JavascriptService extends BaseService implements LanguageService { private $service; private config; $languageOptions: JavascriptServiceOptions["languageOptions"]; $rules: JavascriptServiceOptions["rules"]; serviceCapabilities: { diagnosticProvider: { interFileDependencies: boolean; workspaceDiagnostics: boolean; }; }; constructor(mode: string); initConfig(): void; doValidation(document: lsp.TextDocumentIdentifier): Promise; setGlobalOptions(options: JavascriptServiceOptions): void; } export {};