UNPKG

eslint-codemod-utils

Version:

A collection of AST helper functions for more complex ESLint rule fixes.

19 lines (18 loc) 545 B
/** * @example * ```tsx * // this is the search comment * const findThisNode = 10 * ^^^^^^^^^^^^^^^^^^^^^^^ * ``` */ export function getNodeAfterComment(source, comment) { // `eslint.SourceCode.getTokenAfter` expects the vanilla-ESLint `Comment` // shape; cast across the thin-but-real shape difference between it and // `TSESTree.Comment` (the runtime objects are the same). const token = source.getTokenAfter(comment); if (token) { return source.getNodeByRangeIndex(token.range[1]); } return null; }