-
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.
Updated import declaration to return boolean
- Loading branch information
1 parent
8f56df8
commit 5f60623
Showing
1 changed file
with
8 additions
and
8 deletions.
There are no files selected for viewing
16 changes: 8 additions & 8 deletions
16
...eslint-plugin-pf-codemods/src/rules/helpers/nodeMatches/checkMatchingImportDeclaration.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,30 +1,30 @@ | ||
import { ImportDeclaration, ImportSpecifier } from "estree-jsx"; | ||
import { pfPackageMatches } from "../pfPackageMatches"; | ||
|
||
function findSpecifier( | ||
function checkSpecifierExists( | ||
node: ImportDeclaration, | ||
imporSpecifier: ImportSpecifier | ||
importSpecifier: ImportSpecifier | ||
) { | ||
return node.specifiers.find( | ||
return node.specifiers.some( | ||
(specifier) => | ||
specifier.type === "ImportSpecifier" && | ||
specifier.imported.name === imporSpecifier.imported.name | ||
specifier.imported.name === importSpecifier.imported.name | ||
); | ||
} | ||
|
||
/** Used to check whether the current ImportDeclaration node matches at least 1 of the import specifiers. */ | ||
export function checkMatchingImportDeclaration( | ||
node: ImportDeclaration, | ||
imports: ImportSpecifier | ImportSpecifier[], | ||
packageNamne: string = "@patternfly/react-core" | ||
packageName: string = "@patternfly/react-core" | ||
) { | ||
if (!pfPackageMatches(packageNamne, node.source.value)) { | ||
if (!pfPackageMatches(packageName, node.source.value)) { | ||
return false; | ||
} | ||
|
||
if (Array.isArray(imports)) { | ||
return imports.some((imp) => findSpecifier(node, imp)); | ||
return imports.some((imp) => checkSpecifierExists(node, imp)); | ||
} | ||
|
||
return findSpecifier(node, imports); | ||
return checkSpecifierExists(node, imports); | ||
} |