From 217858e61a6cfb733dff6cfc858465ea926db6d9 Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Mon, 4 Sep 2023 12:30:48 +0330 Subject: [PATCH] FileConventions: improvements to Library.fs An assert error message has been added for *.fsx files & renaming the func. --- scripts/dotnetFileConventions.fsx | 4 ++-- src/FileConventions/Library.fs | 13 +++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/dotnetFileConventions.fsx b/scripts/dotnetFileConventions.fsx index 86a16465b..0c868a6f0 100644 --- a/scripts/dotnetFileConventions.fsx +++ b/scripts/dotnetFileConventions.fsx @@ -27,11 +27,11 @@ if args.Length > 1 then let rootDir = DirectoryInfo args.[0] // DefiningEmptyStringsWithDoubleQuotes -let allSourceFiles = ReturnAllProjectSourceFile rootDir [ "*.cs"; "*.fs" ] true +let allSourceFiles = ReturnAllProjectSourceFiles rootDir [ "*.cs"; "*.fs" ] true printfn "%A" (String.Join("\n", allSourceFiles)) let allProjFiles = - ReturnAllProjectSourceFile rootDir [ "*.csproj"; "*.fsproj" ] true + ReturnAllProjectSourceFiles rootDir [ "*.csproj"; "*.fsproj" ] true for sourceFile in allSourceFiles do let isStringEmpty = DefiningEmptyStringsWithDoubleQuotes sourceFile diff --git a/src/FileConventions/Library.fs b/src/FileConventions/Library.fs index ac3865fb9..70358045c 100644 --- a/src/FileConventions/Library.fs +++ b/src/FileConventions/Library.fs @@ -12,6 +12,7 @@ open Fsdk let ymlAssertionError = "Bug: file should be a .yml file" let projAssertionError = "Bug: file should be a proj file" let sourceFileAssertionError = "Bug: file was not a F#/C# source file" +let fsxAssertionError = "Bug: file was not a F# script source file" let HasCorrectShebang(fileInfo: FileInfo) = let fileText = File.ReadLines fileInfo.FullName @@ -88,9 +89,7 @@ let DetectAsteriskInPackageReferenceItems(fileInfo: FileInfo) = asteriskInPackageReference.IsMatch fileText let DetectMissingVersionsInNugetPackageReferences(fileInfo: FileInfo) = - Misc.BetterAssert - (fileInfo.FullName.EndsWith ".fsx") - sourceFileAssertionError + Misc.BetterAssert (fileInfo.FullName.EndsWith ".fsx") fsxAssertionError let fileLines = File.ReadLines fileInfo.FullName @@ -320,9 +319,7 @@ let DetectInconsistentVersionsInNugetRefsInFSharpScripts = fileInfos |> Seq.iter(fun fileInfo -> - Misc.BetterAssert - (fileInfo.FullName.EndsWith ".fsx") - sourceFileAssertionError + Misc.BetterAssert (fileInfo.FullName.EndsWith ".fsx") fsxAssertionError ) DetectInconsistentVersions @@ -491,7 +488,7 @@ let ContainsConsoleMethods(fileInfo: FileInfo) = checkLine fileLines -let ReturnAllProjectSourceFile +let ReturnAllProjectSourceFiles (parentDir: DirectoryInfo) (patterns: List) (shouldFilter: bool) @@ -521,7 +518,7 @@ let NotFollowingConsoleAppConvention (fileInfo: FileInfo) (shouldFilter: bool) = if not(fileText.Contains "Exe") then let sourceFiles = - ReturnAllProjectSourceFile + ReturnAllProjectSourceFiles (DirectoryInfo parentDir) [ "*.cs"; "*.fs" ] shouldFilter