Skip to content

Commit

Permalink
FileConventions: use BetterAssert() & update Fsdk
Browse files Browse the repository at this point in the history
We updated fsdk to the latest version becuase the old
version of fsdk does not have `Misc.BetterAssert` and
we use `Misc.BetterAssert()` becuase assert is for
debug mode.
  • Loading branch information
Mersho committed Aug 21, 2023
1 parent 21f3749 commit 81bfb57
Show file tree
Hide file tree
Showing 18 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion scripts/checkCommits1by1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ open System.Net.Http.Headers
#r "nuget: FSharp.Data, Version=5.0.2"
open FSharp.Data

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

open Fsdk
open Fsdk.Process
Expand Down
2 changes: 1 addition & 1 deletion scripts/compileFSharpScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open System
open System.IO

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"
#load "../src/FileConventions/Helpers.fs"

Fsdk
Expand Down
1 change: 1 addition & 0 deletions scripts/eofConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System.IO
open System

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Helpers.fs"
#load "../src/FileConventions/Library.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/executableConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"
#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"

Expand Down
2 changes: 1 addition & 1 deletion scripts/gitPush1by1.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open System.Threading
#r "System.Configuration"
open System.Configuration

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

open Fsdk
open Fsdk.Process
Expand Down
1 change: 1 addition & 0 deletions scripts/inconsistentVersionsInFSharpScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System.IO
open System.Linq

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/inconsistentVersionsInGitHubCI.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/mixedLineEndings.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/nonVerboseFlagsInGitHubCIAndScripts.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/shebangConvention.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/unpinnedDotnetPackageVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/unpinnedDotnetToolInstallVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/unpinnedGitHubActionsImageVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
1 change: 1 addition & 0 deletions scripts/unpinnedNugetPackageReferenceVersions.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open System
open System.IO

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"
#load "../src/FileConventions/Helpers.fs"
Expand Down
3 changes: 1 addition & 2 deletions scripts/wrapLatestCommitMsg.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ open System
open System.Text.RegularExpressions

#r "nuget: Mono.Unix, Version=7.1.0-final.1.21458.1"
#r "nuget: Fsdk, Version=0.6.0--date20230821-0702.git-5488853"

#load "../src/FileConventions/Library.fs"

#r "nuget: Fsdk, Version=0.6.0--date20230214-0422.git-1ea6f62"

open Fsdk
open Fsdk.Process

Expand Down
2 changes: 1 addition & 1 deletion src/FileConventions.Test/FileConventions.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
<PackageReference Include="Fsdk" Version="0.6.0--date20230214-0422.git-1ea6f62" />
<PackageReference Include="Fsdk" Version="0.6.0--date20230821-0702.git-5488853" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/FileConventions/FileConventions.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Mono.Posix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
<PackageReference Include="Fsdk" Version="0.6.0--date20230821-0702.git-5488853" />
</ItemGroup>

</Project>
28 changes: 19 additions & 9 deletions src/FileConventions/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ open System.Text.RegularExpressions

open Mono
open Mono.Unix.Native
open Fsdk

let ymlAssertionError = "Bug: file should be a .yml file"
let projAssertionError = "Bug: file should be a proj file"
let fsxAssertionError = "Bug: file was not a F#/C# source file"

let HasCorrectShebang(fileInfo: FileInfo) =
let fileText = File.ReadLines fileInfo.FullName
Expand Down Expand Up @@ -42,7 +47,7 @@ let MixedLineEndings(fileInfo: FileInfo) =
numberOfLineEndings > 1

let DetectUnpinnedVersionsInGitHubCI(fileInfo: FileInfo) =
assert (fileInfo.FullName.EndsWith(".yml"))
Misc.BetterAssert (fileInfo.FullName.EndsWith ".yml") ymlAssertionError

let fileText = File.ReadAllText fileInfo.FullName

Expand All @@ -52,7 +57,7 @@ let DetectUnpinnedVersionsInGitHubCI(fileInfo: FileInfo) =
latestTagInRunsOnRegex.IsMatch fileText

let DetectUnpinnedDotnetToolInstallVersions(fileInfo: FileInfo) =
assert (fileInfo.FullName.EndsWith(".yml"))
Misc.BetterAssert (fileInfo.FullName.EndsWith ".yml") ymlAssertionError

let fileLines = File.ReadLines fileInfo.FullName

Expand All @@ -70,7 +75,7 @@ let DetectUnpinnedDotnetToolInstallVersions(fileInfo: FileInfo) =
unpinnedDotnetToolInstallVersions

let DetectAsteriskInPackageReferenceItems(fileInfo: FileInfo) =
assert (fileInfo.FullName.EndsWith "proj")
Misc.BetterAssert (fileInfo.FullName.EndsWith "proj") projAssertionError

let fileText = File.ReadAllText fileInfo.FullName

Expand All @@ -83,7 +88,7 @@ let DetectAsteriskInPackageReferenceItems(fileInfo: FileInfo) =
asteriskInPackageReference.IsMatch fileText

let DetectMissingVersionsInNugetPackageReferences(fileInfo: FileInfo) =
assert (fileInfo.FullName.EndsWith ".fsx")
Misc.BetterAssert (fileInfo.FullName.EndsWith ".fsx") fsxAssertionError

let fileLines = File.ReadLines fileInfo.FullName

Expand Down Expand Up @@ -284,7 +289,9 @@ let private DetectInconsistentVersions

let DetectInconsistentVersionsInGitHubCIWorkflow(fileInfos: seq<FileInfo>) =
fileInfos
|> Seq.iter(fun fileInfo -> assert (fileInfo.FullName.EndsWith ".yml"))
|> Seq.iter(fun fileInfo ->
Misc.BetterAssert (fileInfo.FullName.EndsWith ".yml") ymlAssertionError
)

let inconsistentVersionsType1 =
DetectInconsistentVersions
Expand All @@ -310,7 +317,9 @@ let DetectInconsistentVersionsInNugetRefsInFSharpScripts
(fileInfos: seq<FileInfo>)
=
fileInfos
|> Seq.iter(fun fileInfo -> assert (fileInfo.FullName.EndsWith ".fsx"))
|> Seq.iter(fun fileInfo ->
Misc.BetterAssert (fileInfo.FullName.EndsWith ".fsx") fsxAssertionError
)

DetectInconsistentVersions
fileInfos
Expand Down Expand Up @@ -397,7 +406,7 @@ let DefiningEmptyStringsWithDoubleQuotes(fileInfo: FileInfo) =

let ProjFilesNamingConvention(fileInfo: FileInfo) =
let regex = new Regex("(.*)\..*proj$")
assert (regex.IsMatch fileInfo.FullName)
Misc.BetterAssert (regex.IsMatch fileInfo.FullName) projAssertionError
let fileName = Path.GetFileNameWithoutExtension fileInfo.FullName

let parentDirectoryName =
Expand All @@ -423,8 +432,9 @@ let DoesNamespaceInclude (fileInfo: FileInfo) (word: string) =
false

let NotFollowingNamespaceConvention(fileInfo: FileInfo) =
assert
(fileInfo.FullName.EndsWith(".fs") || fileInfo.FullName.EndsWith(".cs"))
Misc.BetterAssert
(fileInfo.FullName.EndsWith ".fs" || fileInfo.FullName.EndsWith ".cs")
fsxAssertionError

let fileName = Path.GetFileNameWithoutExtension fileInfo.FullName
let parentDir = Path.GetDirectoryName fileInfo.FullName |> DirectoryInfo
Expand Down

0 comments on commit 81bfb57

Please sign in to comment.