UNPKG

eslint-plugin-sonarjs

Version:
40 lines (39 loc) 2.2 kB
import estree from 'estree'; import type { AST, Rule } from 'eslint'; import type { TSESLint, TSESTree } from '@typescript-eslint/utils'; export type LocationHolder = AST.Token | TSESTree.Node | estree.Node | { loc: AST.SourceLocation; }; export interface IssueLocation { column: number; line: number; endColumn: number; endLine: number; message?: string; } export interface EncodedMessage { message: string; cost?: number; secondaryLocations: IssueLocation[]; } export declare function encodeContents(message: string, secondaryLocations?: IssueLocation[], cost?: number): string; export declare function toSecondaryLocation(startLoc: LocationHolder): IssueLocation; export declare function toSecondaryLocation(startLoc: LocationHolder, message: string): IssueLocation; export declare function toSecondaryLocation(startLoc: LocationHolder, endLoc: LocationHolder): IssueLocation; export declare function toSecondaryLocation(startLoc: LocationHolder, endLoc: LocationHolder, message: string): IssueLocation; /** * Wrapper for `context.report`, supporting secondary locations and cost. * Encode those extra information in the issue message when rule is executed * in Sonar* environment. */ export declare function report(context: Rule.RuleContext, reportDescriptor: Rule.ReportDescriptor, secondaryLocations?: IssueLocation[], cost?: number): void; export declare function expandMessage(message: string, reportDescriptorData: Record<string, unknown> | undefined): string; /** * Returns a location of the "main" function token: * - function name for a function declaration, method or accessor * - "function" keyword for a function expression * - "=>" for an arrow function */ export declare function getMainFunctionTokenLocation<T = string>(fn: TSESTree.FunctionLike, parent: TSESTree.Node | undefined, context: TSESLint.RuleContext<string, T[]>): TSESTree.SourceLocation; export declare function getFirstTokenAfter<T = string>(node: TSESTree.Node, context: TSESLint.RuleContext<string, T[]>): TSESLint.AST.Token | null; export declare function getFirstToken<T = string>(node: TSESTree.Node, context: TSESLint.RuleContext<string, T[]>): TSESLint.AST.Token;