From 987d0520c388e714964c6f9723946f31e3c4a372 Mon Sep 17 00:00:00 2001 From: realmarv Date: Thu, 6 Jul 2023 16:13:43 +0330 Subject: [PATCH] FileConventions: fix the test Fix DetectUnpinnedNpmPackageInstallVersions function. --- src/FileConventions/Library.fs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index bcca98147..f91de6d49 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -79,9 +79,22 @@ let DetectUnpinnedNpmPackageInstallVersions(fileInfo: FileInfo) = let unpinnedNpmPackageInstallVersions = fileLines + |> Seq.filter(fun line -> npmPackageInstallRegex.IsMatch line) |> Seq.filter(fun line -> - npmPackageInstallRegex.IsMatch line - && npmPackageVersionRegex.IsMatch line |> not + let npmPackagesRegex = + Regex("(?<=npm install ).*$", RegexOptions.Compiled) + + let npmInstallPackages = npmPackagesRegex.Match line + + let numNpmInstallPackages = + npmInstallPackages.Value.Split(" ") + |> Seq.filter(fun word -> word.Trim().StartsWith("-") |> not) + |> Seq.length + + let numNpmInstallVersions = + npmPackageVersionRegex.Matches line |> Seq.length + + numNpmInstallPackages = numNpmInstallVersions |> not ) |> (fun unpinnedVersions -> Seq.length unpinnedVersions > 0)