UNPKG

1.83 kBTypeScriptView Raw
1import type { TSESTree, TSESLint } from '@typescript-eslint/experimental-utils';
2import { Rule } from './types';
3export interface IssueLocation {
4 column: number;
5 line: number;
6 endColumn: number;
7 endLine: number;
8 message?: string;
9}
10export interface EncodedMessage {
11 message: string;
12 cost?: number;
13 secondaryLocations: IssueLocation[];
14}
15/**
16 * Returns a location of the "main" function token:
17 * - function name for a function declaration, method or accessor
18 * - "function" keyword for a function expression
19 * - "=>" for an arrow function
20 */
21export declare function getMainFunctionTokenLocation(fn: TSESTree.FunctionLike, parent: TSESTree.Node | undefined, context: Rule.RuleContext): TSESTree.SourceLocation;
22/**
23 * Wrapper for `context.report`, supporting secondary locations and cost.
24 * Encode those extra information in the issue message when rule is executed
25 * in Sonar* environment.
26 */
27export declare function report(context: Rule.RuleContext, reportDescriptor: Rule.ReportDescriptor, secondaryLocations?: IssueLocation[], cost?: number): void;
28/**
29 * Converts `SourceLocation` range into `IssueLocation`
30 */
31export declare function issueLocation(startLoc: TSESTree.SourceLocation, endLoc?: TSESTree.SourceLocation, message?: string): IssueLocation;
32export declare function toEncodedMessage(message: string, secondaryLocationsHolder: Array<TSESLint.AST.Token | TSESTree.Node>, secondaryMessages?: string[], cost?: number): string;
33export declare function toSecondaryLocation(locationHolder: TSESLint.AST.Token | TSESTree.Node, message?: string): IssueLocation;
34export declare function getFirstTokenAfter(node: TSESTree.Node, context: Rule.RuleContext): TSESLint.AST.Token | null;
35export declare function getFirstToken(node: TSESTree.Node, context: Rule.RuleContext): TSESLint.AST.Token;