utils.d.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import * as ts from "typescript";
  2. import { IDisabledInterval, RuleFailure } from "./rule/rule";
  3. export declare function getSourceFile(fileName: string, source: string): ts.SourceFile;
  4. /** @deprecated See IDisabledInterval. */
  5. export declare function doesIntersect(failure: RuleFailure, disabledIntervals: IDisabledInterval[]): boolean;
  6. /**
  7. * @returns true if any modifier kinds passed along exist in the given modifiers array
  8. *
  9. * @deprecated use `hasModifier` from `tsutils`
  10. */
  11. export declare function hasModifier(modifiers: ts.ModifiersArray | undefined, ...modifierKinds: ts.SyntaxKind[]): boolean;
  12. /**
  13. * Determines if the appropriate bit in the parent (VariableDeclarationList) is set,
  14. * which indicates this is a "let" or "const".
  15. *
  16. * @deprecated use `isBlockScopedVariableDeclarationList` from `tsutils`
  17. */
  18. export declare function isBlockScopedVariable(node: ts.VariableDeclaration | ts.VariableStatement): boolean;
  19. /** @deprecated use `isBlockScopedVariableDeclarationList` and `getDeclarationOfBindingElement` from `tsutils` */
  20. export declare function isBlockScopedBindingElement(node: ts.BindingElement): boolean;
  21. /** @deprecated use `getDeclarationOfBindingElement` from `tsutils` */
  22. export declare function getBindingElementVariableDeclaration(node: ts.BindingElement): ts.VariableDeclaration | null;
  23. /**
  24. * Finds a child of a given node with a given kind.
  25. * Note: This uses `node.getChildren()`, which does extra parsing work to include tokens.
  26. *
  27. * @deprecated use `getChildOfKind` from `tsutils`
  28. */
  29. export declare function childOfKind(node: ts.Node, kind: ts.SyntaxKind): ts.Node | undefined;
  30. /**
  31. * @returns true if some ancestor of `node` satisfies `predicate`, including `node` itself.
  32. *
  33. * @deprecated no longer used, use a `while` loop instead
  34. */
  35. export declare function someAncestor(node: ts.Node, predicate: (n: ts.Node) => boolean): boolean;
  36. export declare function ancestorWhere<T extends ts.Node = ts.Node>(node: ts.Node, predicate: ((n: ts.Node) => n is T) | ((n: ts.Node) => boolean)): T | undefined;
  37. /** @deprecated use `isBinaryExpression(node) && isAssignmentKind(node.operatorToken.kind)` with functions from `tsutils` */
  38. export declare function isAssignment(node: ts.Node): boolean;
  39. /**
  40. * Bitwise check for node flags.
  41. *
  42. * @deprecated use `isNodeFlagSet` from `tsutils`
  43. */
  44. export declare function isNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean;
  45. /**
  46. * Bitwise check for combined node flags.
  47. *
  48. * @deprecated no longer used
  49. */
  50. export declare function isCombinedNodeFlagSet(node: ts.Node, flagToCheck: ts.NodeFlags): boolean;
  51. /**
  52. * Bitwise check for combined modifier flags.
  53. *
  54. * @deprecated no longer used
  55. */
  56. export declare function isCombinedModifierFlagSet(node: ts.Node, flagToCheck: ts.ModifierFlags): boolean;
  57. /**
  58. * Bitwise check for type flags.
  59. *
  60. * @deprecated use `isTypeFlagSet` from `tsutils`
  61. */
  62. export declare function isTypeFlagSet(type: ts.Type, flagToCheck: ts.TypeFlags): boolean;
  63. /**
  64. * Bitwise check for symbol flags.
  65. *
  66. * @deprecated use `isSymbolFlagSet` from `tsutils`
  67. */
  68. export declare function isSymbolFlagSet(symbol: ts.Symbol, flagToCheck: ts.SymbolFlags): boolean;
  69. /**
  70. * Bitwise check for object flags.
  71. * Does not work with TypeScript 2.0.x
  72. *
  73. * @deprecated use `isObjectFlagSet` from `tsutils`
  74. */
  75. export declare function isObjectFlagSet(objectType: ts.ObjectType, flagToCheck: ts.ObjectFlags): boolean;
  76. /**
  77. * @returns true if decl is a nested module declaration, i.e. represents a segment of a dotted module path.
  78. *
  79. * @deprecated use `decl.parent!.kind === ts.SyntaxKind.ModuleDeclaration`
  80. */
  81. export declare function isNestedModuleDeclaration(decl: ts.ModuleDeclaration): boolean;
  82. export declare function unwrapParentheses(node: ts.Expression): ts.Expression;
  83. /** @deprecated use `isFunctionScopeBoundary` from `tsutils` */
  84. export declare function isScopeBoundary(node: ts.Node): boolean;
  85. /** @deprecated use `isBlockScopeBoundary` from `tsutils` */
  86. export declare function isBlockScopeBoundary(node: ts.Node): boolean;
  87. /** @deprecated use `isIterationStatement` from `tsutils` or `typescript` */
  88. export declare function isLoop(node: ts.Node): node is ts.IterationStatement;
  89. /**
  90. * @returns Whether node is a numeric expression.
  91. */
  92. export declare function isNumeric(node: ts.Expression): boolean;
  93. export interface TokenPosition {
  94. /** The start of the token including all trivia before it */
  95. fullStart: number;
  96. /** The start of the token */
  97. tokenStart: number;
  98. /** The end of the token */
  99. end: number;
  100. }
  101. export declare type ForEachTokenCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition, parent: ts.Node) => void;
  102. export declare type ForEachCommentCallback = (fullText: string, kind: ts.SyntaxKind, pos: TokenPosition) => void;
  103. export declare type FilterCallback = (node: ts.Node) => boolean;
  104. /**
  105. * Iterate over all tokens of `node`
  106. *
  107. * @description JsDoc comments are treated like regular comments and only visited if `skipTrivia` === false.
  108. *
  109. * @param node The node whose tokens should be visited
  110. * @param skipTrivia If set to false all trivia preceeding `node` or any of its children is included
  111. * @param cb Is called for every token of `node`. It gets the full text of the SourceFile and the position of the token within that text.
  112. * @param filter If provided, will be called for every Node and Token found. If it returns false `cb` will not be called for this subtree.
  113. *
  114. * @deprecated use `forEachToken` or `forEachTokenWithTrivia` from `tsutils`
  115. */
  116. export declare function forEachToken(node: ts.Node, skipTrivia: boolean, cb: ForEachTokenCallback, filter?: FilterCallback): void;
  117. /**
  118. * Iterate over all comments owned by `node` or its children
  119. *
  120. * @deprecated use `forEachComment` from `tsutils`
  121. */
  122. export declare function forEachComment(node: ts.Node, cb: ForEachCommentCallback): void;
  123. /**
  124. * Checks if there are any comments between `position` and the next non-trivia token
  125. *
  126. * @param text The text to scan
  127. * @param position The position inside `text` where to start scanning. Make sure that this is a valid start position.
  128. * This value is typically obtained from `node.getFullStart()` or `node.getEnd()`
  129. */
  130. export declare function hasCommentAfterPosition(text: string, position: number): boolean;
  131. export interface EqualsKind {
  132. isPositive: boolean;
  133. isStrict: boolean;
  134. }
  135. export declare function getEqualsKind(node: ts.BinaryOperatorToken): EqualsKind | undefined;
  136. export declare function isStrictNullChecksEnabled(options: ts.CompilerOptions): boolean;
  137. export declare function isNegativeNumberLiteral(node: ts.Node): node is ts.PrefixUnaryExpression & {
  138. operand: ts.NumericLiteral;
  139. };
  140. /** Wrapper for compatibility with typescript@<2.3.1 */
  141. export declare function isWhiteSpace(ch: number): boolean;