Skip to content

Commit

Permalink
chore(terraform-provider): replace if chain with array.some()
Browse files Browse the repository at this point in the history
  • Loading branch information
secustor committed Jun 28, 2020
1 parent a189f31 commit 0af36ae
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/manager/terraform/extract.ts
Expand Up @@ -33,16 +33,22 @@ export function getTerraformDependencyType(
}
}

function checkFileContainsDependency(
content: string,
checkList: string[]
): boolean {
return checkList.some((check) => {
return content.includes(check);
});
}

const dependencyBlockExtractionRegex = /^\s*(?<type>module|provider|required_providers)\s+("(?<lookupName>[^"]+)"\s+)?{\s*$/;
const contentCheckList = ['module "', 'provider "', 'required_providers '];
const keyValueExtractionRegex = /^\s*(?<key>[^\s]+)\s+=\s+"(?<value>[^"]+)"\s*$/; // extracts `exampleKey = exampleValue`

export function extractPackageFile(content: string): PackageFile | null {
logger.trace({ content }, 'terraform.extractPackageFile()');
if (
!content.includes('module "') &&
!content.includes('provider "') &&
!content.includes('required_providers ')
) {
if (!checkFileContainsDependency(content, contentCheckList)) {
return null;
}
const deps: PackageDependency[] = [];
Expand Down

0 comments on commit 0af36ae

Please sign in to comment.