From 4156fa4c99116b2da11142a0a336aec7910fe280 Mon Sep 17 00:00:00 2001 From: realmarv Date: Wed, 5 Jul 2023 17:01:41 +0330 Subject: [PATCH] FileConventions: refactor --- scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx | 2 +- src/FileConventions.Test/FileConventions.Test.fs | 12 ++++++------ src/FileConventions/Library.fs | 14 +++++++++----- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx index ddfe372a5..6ffb88019 100644 --- a/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx +++ b/scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx @@ -22,7 +22,7 @@ let invalidFiles = Helpers.GetInvalidFiles rootDir ("*" + ext) - FileConventions.NonVerboseFlagsInGitHubCI + FileConventions.NonVerboseFlags ) |> Seq.concat diff --git a/src/FileConventions.Test/FileConventions.Test.fs b/src/FileConventions.Test/FileConventions.Test.fs index 75b1d506f..15ba902ec 100644 --- a/src/FileConventions.Test/FileConventions.Test.fs +++ b/src/FileConventions.Test/FileConventions.Test.fs @@ -559,7 +559,7 @@ let NonVerboseFlagsInGitHubCI1() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo true) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo true) [] @@ -572,7 +572,7 @@ let NonVerboseFlagsInGitHubCI2() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false) [] @@ -585,7 +585,7 @@ let NonVerboseFlagsInGitHubCI3() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false) [] @@ -598,7 +598,7 @@ let NonVerboseFlagsInGitHubCI4() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo true) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo true) [] @@ -611,7 +611,7 @@ let NonVerboseFlagsInGitHubCI5() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false) [] @@ -624,4 +624,4 @@ let NonVerboseFlagsInGitHubCI6() = ) )) - Assert.That(NonVerboseFlagsInGitHubCI fileInfo, Is.EqualTo false) + Assert.That(NonVerboseFlags fileInfo, Is.EqualTo false) diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index 953d9c017..821984798 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -339,7 +339,7 @@ let allowedNonVerboseFlags = "env -S" } -let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) = +let NonVerboseFlags(fileInfo: FileInfo) = let validExtensions = seq { ".yml" @@ -348,12 +348,16 @@ let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) = ".sh" } - assert + let isFileExtentionValid = validExtensions - |> Seq.map(fun ext -> fileInfo.FullName.EndsWith(ext)) + |> Seq.map(fun ext -> fileInfo.FullName.EndsWith ext) |> Seq.contains true - let fileLines = File.ReadLines(fileInfo.FullName) + if not isFileExtentionValid then + failwith + "NonVerboseFlags function only supports '.yml', '.fsx', '.fs' and '.sh' files." + + let fileLines = File.ReadLines fileInfo.FullName let nonVerboseFlagsRegex = Regex("\\s-[a-zA-Z]\\b", RegexOptions.Compiled) @@ -367,7 +371,7 @@ let NonVerboseFlagsInGitHubCI(fileInfo: FileInfo) = |> Seq.map(fun allowedFlag -> line.Contains allowedFlag) |> Seq.contains true - nonVerboseFlag && not(allowedNonVerboseFlag) + nonVerboseFlag && not allowedNonVerboseFlag ) |> Seq.length