locations.d.ts 1.9 KB

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