This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
594 additions
and
552 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { TSESLint, TSESTree } from '@typescript-eslint/utils'; | ||
|
||
/** | ||
* Get the ancestors of a node from the source code. | ||
* | ||
* NOTE: For ESLint <9.0.0 will return ancestors of the currently-traversed node in the context. | ||
* | ||
* @internal | ||
*/ | ||
export function getSourceAncestors< | ||
TMessageIds extends string, | ||
TOptions extends readonly unknown[], | ||
>( | ||
node: TSESTree.Node, | ||
context: TSESLint.RuleContext<TMessageIds, TOptions> | ESLintRuleContextPreV9, | ||
): TSESTree.Node[] { | ||
// Use ESLint 9.0.0 API if available | ||
return 'sourceCode' in context | ||
? context.sourceCode.getAncestors?.(node) ?? [] | ||
: // Fallback to ESLint <9.0.0 API | ||
context.getAncestors(); | ||
} | ||
|
||
/** | ||
* Backwards compatibility interface for ESLint <9.0.0 | ||
* | ||
* @deprecated API of ESLint <9.0.0 | ||
*/ | ||
interface ESLintRuleContextPreV9 { | ||
getAncestors(): TSESTree.Node[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './get-source-ancestors'; | ||
export * from './stringify-jsdoc-tag'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters