Skip to content

Commit

Permalink
Updated import declaration to return boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Aug 28, 2024
1 parent 8f56df8 commit 5f60623
Showing 1 changed file with 8 additions and 8 deletions.
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);
}

0 comments on commit 5f60623

Please sign in to comment.