-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(helpers): extract findAncestor helper (#603)
* chore(helpers): extract findAncestor helper * Removed extraneous import * Add back conditionCallback * Updated typing * Removed comments
- Loading branch information
1 parent
9df19dd
commit c7e95cf
Showing
4 changed files
with
62 additions
and
41 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
packages/eslint-plugin-pf-codemods/src/rules/helpers/findAncestor.ts
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,24 @@ | ||
import { JSXElement, JSXOpeningElement } from "estree-jsx"; | ||
|
||
type NodeWithParent = (JSXOpeningElement | JSXElement) & { | ||
parent?: NodeWithParent | null; | ||
}; | ||
|
||
export function findAncestor( | ||
node: NodeWithParent, | ||
conditionCallback: (_current: NodeWithParent) => boolean | ||
): NodeWithParent | undefined { | ||
if (!node) { | ||
return; | ||
} | ||
|
||
let current = node.parent; | ||
|
||
while (current) { | ||
if (conditionCallback(current)) { | ||
return current; | ||
} | ||
|
||
current = current.parent; | ||
} | ||
} |
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
7 changes: 4 additions & 3 deletions
7
packages/eslint-plugin-pf-codemods/src/rules/helpers/index.ts
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './helpers'; | ||
export * from './pfPackageMatches'; | ||
export * from './getFromPackage'; | ||
export * from "./findAncestor"; | ||
export * from "./helpers"; | ||
export * from "./pfPackageMatches"; | ||
export * from "./getFromPackage"; |
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