-
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.
- Loading branch information
1 parent
4c45148
commit 0062d93
Showing
3 changed files
with
70 additions
and
128 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
packages/eslint-plugin-pf-codemods/src/rules/helpers/getImportedName.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,17 @@ | ||
import { ImportSpecifier, JSXOpeningElement } from "estree-jsx"; | ||
|
||
/** Resolves the imported name of a node, even if that node has an aliased local name */ | ||
export function getImportedName( | ||
namedImports: ImportSpecifier[], | ||
node: JSXOpeningElement | ||
) { | ||
if (node.name.type !== "JSXIdentifier") { | ||
return; | ||
} | ||
|
||
const nodeName = node.name.name; | ||
|
||
const nodeImport = namedImports.find((imp) => imp.local.name === nodeName); | ||
|
||
return nodeImport?.imported.name; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/eslint-plugin-pf-codemods/src/rules/helpers/getLocalComponentName.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,20 @@ | ||
import { ImportSpecifier } from "estree-jsx"; | ||
|
||
/** Resolves the local name of an import */ | ||
export function getLocalComponentName( | ||
namedImports: ImportSpecifier[], | ||
importedName: string | ||
) { | ||
const componentImport = namedImports.find( | ||
(name) => name.imported.name === importedName | ||
); | ||
|
||
const isAlias = | ||
componentImport?.imported.name !== componentImport?.local.name; | ||
|
||
if (componentImport && isAlias) { | ||
return componentImport.local.name; | ||
} | ||
|
||
return importedName; | ||
} |
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