β¬ οΈ Back to Table of Contents
π getForStatementHeadLoc¶
π Analysis Summary¶
| Metric | Count |
|---|---|
| π§ Functions | 1 |
| π¦ Imports | 3 |
π Table of Contents¶
π οΈ File Location:¶
π packages/eslint-plugin/src/util/getForStatementHeadLoc.ts
π¦ Imports¶
| Name | Source |
|---|---|
TSESLint |
@typescript-eslint/utils |
TSESTree |
@typescript-eslint/utils |
nullThrows |
@typescript-eslint/utils/eslint-utils |
Functions¶
getForStatementHeadLoc(sourceCode: TSESLint.SourceCode, node: TSESTree.ForInStatement | TSESTree.ForOβ¦): TSESTree.SourceLocation¶
Gets the location of the head of the given for statement variant for reporting.
-
for (const foo in bar) expressionOrBlock^^^^^^^^^^^^^^^^^^^^^^ -
for (const foo of bar) expressionOrBlock^^^^^^^^^^^^^^^^^^^^^^ -
for await (const foo of bar) expressionOrBlock^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -
for (let i = 0; i < 10; i++) expressionOrBlock^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Raw JSDoc
/**
* Gets the location of the head of the given for statement variant for reporting.
*
* - `for (const foo in bar) expressionOrBlock`
* ^^^^^^^^^^^^^^^^^^^^^^
*
* - `for (const foo of bar) expressionOrBlock`
* ^^^^^^^^^^^^^^^^^^^^^^
*
* - `for await (const foo of bar) expressionOrBlock`
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*
* - `for (let i = 0; i < 10; i++) expressionOrBlock`
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*/
Calls:
nullThrows (from @typescript-eslint/utils/eslint-utils)sourceCode.getTokenBeforestructuredClone
Code
export function getForStatementHeadLoc(
sourceCode: TSESLint.SourceCode,
node:
TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement,
): TSESTree.SourceLocation {
const closingParens = nullThrows(
sourceCode.getTokenBefore(node.body, token => token.value === ')'),
'for statement must have a closing parenthesis.',
);
return {
end: structuredClone(closingParens.loc.end),
start: structuredClone(node.loc.start),
};
}
Generated by Syntax Scribe