📄 getTextWithParentheses¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 7 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/getTextWithParentheses.ts
📦 Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
SourceCode |
@typescript-eslint/utils/ts-eslint |
isClosingParenToken |
. |
isOpeningParenToken |
. |
isParenthesized |
. |
nullThrows |
. |
NullThrowsReasons |
. |
Functions¶
getTextWithParentheses(sourceCode: Readonly<SourceCode>, node: TSESTree.Node): string¶
Parameters:
sourceCodeReadonly<SourceCode>nodeTSESTree.Node
Returns: string
Calls:
isParenthesized (from .)nullThrows (from .)sourceCode.getTokenBeforeNullThrowsReasons.MissingTokensourceCode.getTokenAftersourceCode.getText
Internal Comments:
Code
export function getTextWithParentheses(
sourceCode: Readonly<SourceCode>,
node: TSESTree.Node,
): string {
// Capture parentheses before and after the node
let beforeCount = 0;
let afterCount = 0;
if (isParenthesized(node, sourceCode)) {
const bodyOpeningParen = nullThrows(
sourceCode.getTokenBefore(node, isOpeningParenToken),
NullThrowsReasons.MissingToken('(', 'node'),
);
const bodyClosingParen = nullThrows(
sourceCode.getTokenAfter(node, isClosingParenToken),
NullThrowsReasons.MissingToken(')', 'node'),
);
beforeCount = node.range[0] - bodyOpeningParen.range[0];
afterCount = bodyClosingParen.range[1] - node.range[1];
}
return sourceCode.getText(node, beforeCount, afterCount);
}
Generated by Syntax Scribe