import type { JSONSchema4 } from '../json-schema'; import type { ParserServices, TSESTree } from '../ts-estree'; import type { AST } from './AST'; import type { Linter } from './Linter'; import type { Scope } from './Scope'; import type { SourceCode } from './SourceCode'; export declare type RuleRecommendation = 'error' | 'strict' | 'warn' | false; interface RuleMetaDataDocs { /** * Concise description of the rule */ description: string; /** * The recommendation level for the rule. * Used by the build tools to generate the recommended and strict configs. * Set to false to not include it as a recommendation */ recommended: 'error' | 'strict' | 'warn' | false; /** * The URL of the rule's docs */ url?: string; /** * Specifies whether the rule can return suggestions. */ suggestion?: boolean; /** * Does the rule require us to create a full TypeScript Program in order for it * to type-check code. This is only used for documentation purposes. */ requiresTypeChecking?: boolean; /** * Does the rule extend (or is it based off of) an ESLint code rule? * Alternately accepts the name of the base rule, in case the rule has been renamed. * This is only used for documentation purposes. */ extendsBaseRule?: boolean | string; } interface RuleMetaData { /** * True if the rule is deprecated, false otherwise */ deprecated?: boolean; /** * Documentation for the rule, unnecessary for custom rules/plugins */ docs?: RuleMetaDataDocs; /** * The fixer category. Omit if there is no fixer */ fixable?: 'code' | 'whitespace'; /** * Specifies whether rules can return suggestions. Omit if there is no suggestions */ hasSuggestions?: boolean; /** * A map of messages which the rule can report. * The key is the messageId, and the string is the parameterised error string. * See: https://eslint.org/docs/developer-guide/working-with-rules#messageids */ messages: Record; /** * 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: 'suggestion' | 'problem' | 'layout'; /** * The name of the rule this rule was replaced by, if it was deprecated. */ replacedBy?: readonly string[]; /** * The options schema. Supply an empty array if there are no options. */ schema: JSONSchema4 | readonly JSONSchema4[]; } interface RuleFix { range: Readonly; text: string; } interface RuleFixer { insertTextAfter(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix; insertTextAfterRange(range: Readonly, text: string): RuleFix; insertTextBefore(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix; insertTextBeforeRange(range: Readonly, text: string): RuleFix; remove(nodeOrToken: TSESTree.Node | TSESTree.Token): RuleFix; removeRange(range: Readonly): RuleFix; replaceText(nodeOrToken: TSESTree.Node | TSESTree.Token, text: string): RuleFix; replaceTextRange(range: Readonly, text: string): RuleFix; } interface SuggestionReportDescriptor extends Omit, 'fix'> { readonly fix: ReportFixFunction; } declare type ReportFixFunction = (fixer: RuleFixer) => null | RuleFix | readonly RuleFix[] | IterableIterator; declare type ReportSuggestionArray = SuggestionReportDescriptor[]; interface ReportDescriptorBase { /** * The parameters for the message string associated with `messageId`. */ readonly data?: Readonly>; /** * The fixer function. */ readonly fix?: ReportFixFunction | null; /** * The messageId which is being reported. */ readonly messageId: TMessageIds; } interface ReportDescriptorWithSuggestion extends ReportDescriptorBase { /** * 6.7's Suggestions API */ readonly suggest?: Readonly> | null; } interface ReportDescriptorNodeOptionalLoc { /** * The Node or AST Token which the report is being attached to */ readonly node: TSESTree.Node | TSESTree.Token; /** * An override of the location of the report */ readonly loc?: Readonly | Readonly; } interface ReportDescriptorLocOnly { /** * An override of the location of the report */ loc: Readonly | Readonly; } declare type ReportDescriptor = ReportDescriptorWithSuggestion & (ReportDescriptorNodeOptionalLoc | ReportDescriptorLocOnly); /** * Plugins can add their settings using declaration * merging against this interface. */ interface SharedConfigurationSettings { [name: string]: unknown; } interface RuleContext { /** * The rule ID. */ id: string; /** * An array of the configured options for this rule. * This array does not include the rule severity. */ options: TOptions; /** * The name of the parser from configuration. */ parserPath: string; /** * The parser options configured for this run */ parserOptions: Linter.ParserOptions; /** * An object containing parser-provided services for rules */ parserServices?: ParserServices; /** * The shared settings from configuration. * We do not have any shared settings in this plugin. */ settings: SharedConfigurationSettings; /** * Returns an array of the ancestors of the currently-traversed node, starting at * the root of the AST and continuing through the direct parent of the current node. * This array does not include the currently-traversed node itself. */ getAncestors(): TSESTree.Node[]; /** * Returns a list of variables declared by the given node. * This information can be used to track references to variables. */ getDeclaredVariables(node: TSESTree.Node): readonly Scope.Variable[]; /** * Returns the current working directory passed to Linter. * It is a path to a directory that should be considered as the current working directory. * @since 6.6.0 */ getCwd?(): string; /** * Returns the filename associated with the source. */ getFilename(): string; /** * Returns the full path of the file on disk without any code block information (unlike `getFilename()`). * @since 7.28.0 */ getPhysicalFilename?(): string; /** * Returns the scope of the currently-traversed node. * This information can be used track references to variables. */ getScope(): Scope.Scope; /** * Returns a SourceCode object that you can use to work with the source that * was passed to ESLint. */ getSourceCode(): Readonly; /** * Marks a variable with the given name in the current scope as used. * This affects the no-unused-vars rule. */ markVariableAsUsed(name: string): boolean; /** * Reports a problem in the code. */ report(descriptor: ReportDescriptor): void; } declare type RuleFunction = (node: T) => void; interface RuleListener { [nodeSelector: string]: RuleFunction | undefined; ArrayExpression?: RuleFunction; ArrayPattern?: RuleFunction; ArrowFunctionExpression?: RuleFunction; AssignmentExpression?: RuleFunction; AssignmentPattern?: RuleFunction; AwaitExpression?: RuleFunction; BigIntLiteral?: RuleFunction; BinaryExpression?: RuleFunction; BlockStatement?: RuleFunction; BreakStatement?: RuleFunction; CallExpression?: RuleFunction; CatchClause?: RuleFunction; ChainExpression?: RuleFunction; ClassBody?: RuleFunction; ClassDeclaration?: RuleFunction; ClassExpression?: RuleFunction; ConditionalExpression?: RuleFunction; ContinueStatement?: RuleFunction; DebuggerStatement?: RuleFunction; Decorator?: RuleFunction; DoWhileStatement?: RuleFunction; EmptyStatement?: RuleFunction; ExportAllDeclaration?: RuleFunction; ExportDefaultDeclaration?: RuleFunction; ExportNamedDeclaration?: RuleFunction; ExportSpecifier?: RuleFunction; ExpressionStatement?: RuleFunction; ForInStatement?: RuleFunction; ForOfStatement?: RuleFunction; ForStatement?: RuleFunction; FunctionDeclaration?: RuleFunction; FunctionExpression?: RuleFunction; Identifier?: RuleFunction; IfStatement?: RuleFunction; ImportDeclaration?: RuleFunction; ImportDefaultSpecifier?: RuleFunction; ImportExpression?: RuleFunction; ImportNamespaceSpecifier?: RuleFunction; ImportSpecifier?: RuleFunction; JSXAttribute?: RuleFunction; JSXClosingElement?: RuleFunction; JSXClosingFragment?: RuleFunction; JSXElement?: RuleFunction; JSXEmptyExpression?: RuleFunction; JSXExpressionContainer?: RuleFunction; JSXFragment?: RuleFunction; JSXIdentifier?: RuleFunction; JSXMemberExpression?: RuleFunction; JSXOpeningElement?: RuleFunction; JSXOpeningFragment?: RuleFunction; JSXSpreadAttribute?: RuleFunction; JSXSpreadChild?: RuleFunction; JSXText?: RuleFunction; LabeledStatement?: RuleFunction; Literal?: RuleFunction; LogicalExpression?: RuleFunction; MemberExpression?: RuleFunction; MetaProperty?: RuleFunction; MethodDefinition?: RuleFunction; NewExpression?: RuleFunction; ObjectExpression?: RuleFunction; ObjectPattern?: RuleFunction; Program?: RuleFunction; Property?: RuleFunction; PropertyDefinition?: RuleFunction; RestElement?: RuleFunction; ReturnStatement?: RuleFunction; SequenceExpression?: RuleFunction; SpreadElement?: RuleFunction; Super?: RuleFunction; SwitchCase?: RuleFunction; SwitchStatement?: RuleFunction; TaggedTemplateExpression?: RuleFunction; TemplateElement?: RuleFunction; TemplateLiteral?: RuleFunction; ThisExpression?: RuleFunction; ThrowStatement?: RuleFunction; TryStatement?: RuleFunction; TSAbstractKeyword?: RuleFunction; TSAbstractMethodDefinition?: RuleFunction; TSAbstractPropertyDefinition?: RuleFunction; TSAnyKeyword?: RuleFunction; TSArrayType?: RuleFunction; TSAsExpression?: RuleFunction; TSAsyncKeyword?: RuleFunction; TSBigIntKeyword?: RuleFunction; TSBooleanKeyword?: RuleFunction; TSCallSignatureDeclaration?: RuleFunction; TSClassImplements?: RuleFunction; TSConditionalType?: RuleFunction; TSConstructorType?: RuleFunction; TSConstructSignatureDeclaration?: RuleFunction; TSDeclareFunction?: RuleFunction; TSDeclareKeyword?: RuleFunction; TSEmptyBodyFunctionExpression?: RuleFunction; TSEnumDeclaration?: RuleFunction; TSEnumMember?: RuleFunction; TSExportAssignment?: RuleFunction; TSExportKeyword?: RuleFunction; TSExternalModuleReference?: RuleFunction; TSFunctionType?: RuleFunction; TSImportEqualsDeclaration?: RuleFunction; TSImportType?: RuleFunction; TSIndexedAccessType?: RuleFunction; TSIndexSignature?: RuleFunction; TSInferType?: RuleFunction; TSInterfaceBody?: RuleFunction; TSInterfaceDeclaration?: RuleFunction; TSInterfaceHeritage?: RuleFunction; TSIntersectionType?: RuleFunction; TSLiteralType?: RuleFunction; TSMappedType?: RuleFunction; TSMethodSignature?: RuleFunction; TSModuleBlock?: RuleFunction; TSModuleDeclaration?: RuleFunction; TSNamespaceExportDeclaration?: RuleFunction; TSNeverKeyword?: RuleFunction; TSNonNullExpression?: RuleFunction; TSNullKeyword?: RuleFunction; TSNumberKeyword?: RuleFunction; TSObjectKeyword?: RuleFunction; TSOptionalType?: RuleFunction; TSParameterProperty?: RuleFunction; TSPrivateKeyword?: RuleFunction; TSPropertySignature?: RuleFunction; TSProtectedKeyword?: RuleFunction; TSPublicKeyword?: RuleFunction; TSQualifiedName?: RuleFunction; TSReadonlyKeyword?: RuleFunction; TSRestType?: RuleFunction; TSStaticKeyword?: RuleFunction; TSStringKeyword?: RuleFunction; TSSymbolKeyword?: RuleFunction; TSThisType?: RuleFunction; TSTupleType?: RuleFunction; TSTypeAliasDeclaration?: RuleFunction; TSTypeAnnotation?: RuleFunction; TSTypeAssertion?: RuleFunction; TSTypeLiteral?: RuleFunction; TSTypeOperator?: RuleFunction; TSTypeParameter?: RuleFunction; TSTypeParameterDeclaration?: RuleFunction; TSTypeParameterInstantiation?: RuleFunction; TSTypePredicate?: RuleFunction; TSTypeQuery?: RuleFunction; TSTypeReference?: RuleFunction; TSUndefinedKeyword?: RuleFunction; TSUnionType?: RuleFunction; TSUnknownKeyword?: RuleFunction; TSVoidKeyword?: RuleFunction; UnaryExpression?: RuleFunction; UpdateExpression?: RuleFunction; VariableDeclaration?: RuleFunction; VariableDeclarator?: RuleFunction; WhileStatement?: RuleFunction; WithStatement?: RuleFunction; YieldExpression?: RuleFunction; } interface RuleModule { /** * Metadata about the rule */ meta: RuleMetaData; /** * Function which returns an object with methods that ESLint calls to “visit” * nodes while traversing the abstract syntax tree. */ create(context: Readonly>): TRuleListener; } declare type RuleCreateFunction = (context: Readonly>) => TRuleListener; export { ReportDescriptor, ReportFixFunction, ReportSuggestionArray, RuleContext, RuleCreateFunction, RuleFix, RuleFixer, RuleFunction, RuleListener, RuleMetaData, RuleMetaDataDocs, RuleModule, SharedConfigurationSettings, }; //# sourceMappingURL=Rule.d.ts.map