From 6d89ec5c8f53b8af7f55b8d722ba5df38442d920 Mon Sep 17 00:00:00 2001 From: SteveGilham Date: Sat, 18 Nov 2023 11:17:35 +0000 Subject: [PATCH] Misc compiler enhancements --- AltCover.Async/AltCover.Async.fsproj | 1 + AltCover.Avalonia/MainWindow.fs | 2 +- AltCover.Engine/Augment.fs | 1 + AltCover.Engine/CecilEx.fs | 2 +- AltCover.Engine/OpenCover.fs | 2 +- AltCover.Engine/ProgramDatabase.fs | 4 ++-- AltCover.Engine/WhatIfExtension.fs | 2 -- AltCover.Engine/WhatIfExtension.fsi | 2 -- AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs | 6 ++++-- AltCover.PowerShell/Accelerator.fs | 6 ++++-- AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj | 1 + AltCover.Recorder/AltCover.Recorder.fsproj | 3 ++- AltCover.Recorder/Base.fs | 4 +++- AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj | 1 + AltCover.Tests/Runner.Tests.fs | 4 ++-- AltCover.Tests/Tests.fs | 4 ++-- AltCover.Tests/Tests2.fs | 4 ++-- AltCover.Tests/Tests3.fs | 4 ++-- AltCover.Tests/XTests.fs | 4 ++-- AltCover.UICommon/CoverageFileTree.fs | 2 +- AltCover.ValidateGendarmeEmulation/Tests.fs | 3 +-- AltCover.Visualizer/Visualizer.fs | 6 +++--- Build/targets.fs | 2 +- OutputBuildProps.props | 3 ++- Samples/Sample25/Sample25.fsproj | 1 + 25 files changed, 41 insertions(+), 33 deletions(-) diff --git a/AltCover.Async/AltCover.Async.fsproj b/AltCover.Async/AltCover.Async.fsproj index 68b3e298a..0d8e7e6e7 100644 --- a/AltCover.Async/AltCover.Async.fsproj +++ b/AltCover.Async/AltCover.Async.fsproj @@ -7,6 +7,7 @@ false false false + --keyfile:$(InfrastructureKey) diff --git a/AltCover.Avalonia/MainWindow.fs b/AltCover.Avalonia/MainWindow.fs index 7c28869ca..439b52791 100644 --- a/AltCover.Avalonia/MainWindow.fs +++ b/AltCover.Avalonia/MainWindow.fs @@ -1016,7 +1016,7 @@ type MainWindow() as this = |> Event.add (fun index -> let mutable auxModel = { Model = List() - Row = null } + Row = nullObject } let addNode = fun diff --git a/AltCover.Engine/Augment.fs b/AltCover.Engine/Augment.fs index caf6f1d96..5a94cb5f4 100644 --- a/AltCover.Engine/Augment.fs +++ b/AltCover.Engine/Augment.fs @@ -12,6 +12,7 @@ module Augment = #else module internal Augment = #endif + let nullObject : System.Object = null #if !ValidateGendarmeEmulation [ Seq.filter (fun i -> i.OpCode = OpCodes.Tail) |> Seq.iter (fun i -> i.OpCode <- OpCodes.Nop - i.Operand <- null) \ No newline at end of file + i.Operand <- nullObject) \ No newline at end of file diff --git a/AltCover.Engine/OpenCover.fs b/AltCover.Engine/OpenCover.fs index 920a413ab..1ce73d28d 100644 --- a/AltCover.Engine/OpenCover.fs +++ b/AltCover.Engine/OpenCover.fs @@ -351,7 +351,7 @@ module internal OpenCover = |> Option.map _.Value if e.Interesting && attr = Some "File" then - element.SetAttributeValue("skippedDueTo".X, null) + element.SetAttributeValue("skippedDueTo".X, nullObject) match (e.Interesting, e.SeqPnt, s.Excluded) with | (true, Some codeSegment, Nothing) -> diff --git a/AltCover.Engine/ProgramDatabase.fs b/AltCover.Engine/ProgramDatabase.fs index b18bdd778..03a4e42b1 100644 --- a/AltCover.Engine/ProgramDatabase.fs +++ b/AltCover.Engine/ProgramDatabase.fs @@ -31,7 +31,7 @@ module internal ProgramDatabase = .GetMethod("GetEmbeddedPortablePdbEntry") let internal getEmbeddedPortablePdbEntry (assembly: AssemblyDefinition) = - getEmbed.Invoke(null, [| assembly.MainModule.GetDebugHeader() :> obj |]) + getEmbed.Invoke(nullObject, [| assembly.MainModule.GetDebugHeader() :> obj |]) :?> ImageDebugHeaderEntry let internal getSymbolsByFolder fileName folderName = @@ -176,7 +176,7 @@ module internal ProgramDatabase = let msfdirectory, dir = construct "Microsoft.Cci.Pdb.MsfDirectory" [| reader; head; bits |] - let datastream = + let datastream : Object = (field msfdirectory "streams" dir) :?> System.Collections.IEnumerable |> Seq.cast |> Seq.skip 1 diff --git a/AltCover.Engine/WhatIfExtension.fs b/AltCover.Engine/WhatIfExtension.fs index 1f38dea1a..1e9f32c20 100644 --- a/AltCover.Engine/WhatIfExtension.fs +++ b/AltCover.Engine/WhatIfExtension.fs @@ -3,7 +3,6 @@ open System.Diagnostics.CodeAnalysis open System.Runtime.CompilerServices -[] module PrepareExtension = [] let WhatIf (prepare: Abstract.IPrepareOptions) : AltCover.ValidatedCommandLine = @@ -12,7 +11,6 @@ module PrepareExtension = (AltCover.PrepareOptions.Abstract prepare) .Validate() } -[] module CollectExtension = [] let WhatIf diff --git a/AltCover.Engine/WhatIfExtension.fsi b/AltCover.Engine/WhatIfExtension.fsi index 3677ed932..81918f5a3 100644 --- a/AltCover.Engine/WhatIfExtension.fsi +++ b/AltCover.Engine/WhatIfExtension.fsi @@ -10,7 +10,6 @@ open System.Runtime.CompilerServices /// no doc /// /// `Abstract.IPrepareOptions` extension methods /// -[] module PrepareExtension = begin /// /// Validates the supplied options @@ -23,7 +22,6 @@ end /// /// `Abstract.ICollectOptions` extension methods /// -[] module CollectExtension = begin /// /// Validates the supplied options diff --git a/AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs b/AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs index cc65bd3d3..4f4785698 100644 --- a/AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs +++ b/AltCover.Fake.DotNet.Testing.AltCover/AltCoverCommand.fs @@ -169,12 +169,14 @@ module AltCoverCommand = let parameters = Fake.DotNet.DotNet.TestOptions.Create() |> options + let nullObject : Object = null + let args = - builder.Invoke(null, [| parameters |]) :?> string list + builder.Invoke(nullObject, [| parameters |]) :?> string list let cmdArgs = builder2.Invoke( - null, + nullObject, [| ("test" |> Args.fromWindowsCommandLine |> Seq.toList) diff --git a/AltCover.PowerShell/Accelerator.fs b/AltCover.PowerShell/Accelerator.fs index a5118e08d..c5626fd0a 100644 --- a/AltCover.PowerShell/Accelerator.fs +++ b/AltCover.PowerShell/Accelerator.fs @@ -145,9 +145,10 @@ type AddAcceleratorCommand() = String.Empty) ) then + let nullObject : System.Object = null finalmap |> Seq.iter (fun kv -> - adder.Invoke(null, [| kv.Key :> obj; kv.Value :> obj |]) + adder.Invoke(nullObject, [| kv.Key :> obj; kv.Value :> obj |]) |> ignore) /// @@ -183,8 +184,9 @@ type GetAcceleratorCommand() = acceleratorsType.GetProperty("Get") let result = Hashtable() + let nullObject : System.Object = null - (finder.GetValue(null, [||]) :?> Dictionary) + (finder.GetValue(nullObject, [||]) :?> Dictionary) |> Seq.iter (fun kv -> result.Add(kv.Key, kv.Value)) self.WriteObject result \ No newline at end of file diff --git a/AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj b/AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj index 8afaab159..e723ca8e3 100644 --- a/AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj +++ b/AltCover.Recorder.Tests/AltCover.Recorder.Tests.fsproj @@ -8,6 +8,7 @@ NU1702 NU1702 + --keyfile:$(InfrastructureKey) diff --git a/AltCover.Recorder/AltCover.Recorder.fsproj b/AltCover.Recorder/AltCover.Recorder.fsproj index 3ce0903f5..4be986013 100644 --- a/AltCover.Recorder/AltCover.Recorder.fsproj +++ b/AltCover.Recorder/AltCover.Recorder.fsproj @@ -11,11 +11,12 @@ TRACE - $(OtherFlags) --standalone --staticlink:ICSharpCode.SharpZipLib + --keyfile:$(InfrastructureKey) --standalone --staticlink:ICSharpCode.SharpZipLib TRACE;DEBUG;CODE_ANALYSIS + --keyfile:$(InfrastructureKey) diff --git a/AltCover.Recorder/Base.fs b/AltCover.Recorder/Base.fs index b38bbf7c1..8f4339b11 100644 --- a/AltCover.Recorder/Base.fs +++ b/AltCover.Recorder/Base.fs @@ -228,9 +228,11 @@ module internal Counter = let startTimeNode = root.GetAttributeNode("startTime") + let nullObject : System.Object = null + if format = ReportFormat.NCover - && Object.ReferenceEquals(startTimeNode, null) |> not + && Object.ReferenceEquals(startTimeNode, nullObject) |> not then let startTimeAttr = startTimeNode.Value diff --git a/AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj b/AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj index b5de7c2ad..bc6fa9353 100644 --- a/AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj +++ b/AltCover.Recorder2.Tests/AltCover.Recorder2.Tests.fsproj @@ -7,6 +7,7 @@ false NU1702 NU1702 + --keyfile:$(InfrastructureKey) diff --git a/AltCover.Tests/Runner.Tests.fs b/AltCover.Tests/Runner.Tests.fs index 538102ff3..91b6491c8 100644 --- a/AltCover.Tests/Runner.Tests.fs +++ b/AltCover.Tests/Runner.Tests.fs @@ -2542,7 +2542,7 @@ module AltCoverRunnerTests = .GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static) let returnCode = - main.Invoke(null, [| [| "RuNN"; "-r"; unique |] |]) + main.Invoke(nullObject, [| [| "RuNN"; "-r"; unique |] |]) Assert.That(returnCode, Is.EqualTo 255) @@ -3458,7 +3458,7 @@ module AltCoverRunnerTests = Assert.That(r, Is.EqualTo 4) Assert.That(File.Exists(unique + ".acv")) - Assert.That(counts, Is.EquivalentTo []) + Assert.That(counts, Is.Empty) [] let TrackingPayloadShouldReportAsExpected () = diff --git a/AltCover.Tests/Tests.fs b/AltCover.Tests/Tests.fs index c28dccd23..249f8e64d 100644 --- a/AltCover.Tests/Tests.fs +++ b/AltCover.Tests/Tests.fs @@ -1049,7 +1049,7 @@ module AltCoverTests = [ StaticFilter.AsCovered StaticFilter.Hidden StaticFilter.NoFilter ] - |> List.map (fun k -> Visitor.I.selectExemption k [] Exemption.None) + |> List.map (fun k -> Visitor.I.selectExemption k List.empty Exemption.None) test <@ @@ -2837,7 +2837,7 @@ module AltCoverTests = ) let unique = Guid.NewGuid().ToString() - let op _ = raise <| IOException(unique) + let op _ : Object = raise <| IOException(unique) let x = Assert.Throws(fun () -> diff --git a/AltCover.Tests/Tests2.fs b/AltCover.Tests/Tests2.fs index 6f3bc01ec..0defaf6df 100644 --- a/AltCover.Tests/Tests2.fs +++ b/AltCover.Tests/Tests2.fs @@ -964,10 +964,10 @@ has been prefixed with Ldc_I4_1 (1 byte) let n = i.ToString().Replace("-", "_") s.Constants.Add - <| ConstantDebugInformation("I" + n, primitive, null) + <| ConstantDebugInformation("I" + n, primitive, nullObject) s.Constants.Add - <| ConstantDebugInformation("A" + n, np, null) + <| ConstantDebugInformation("A" + n, np, nullObject) rescope.Scopes.Add s) diff --git a/AltCover.Tests/Tests3.fs b/AltCover.Tests/Tests3.fs index 4e2fc5b2c..eac9cfad4 100644 --- a/AltCover.Tests/Tests3.fs +++ b/AltCover.Tests/Tests3.fs @@ -3682,7 +3682,7 @@ module AltCoverTests3 = .GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static) let returnCode = - main.Invoke(null, [| [| "TargetsPath" |] |]) + main.Invoke(nullObject, [| [| "TargetsPath" |] |]) Assert.That(returnCode, Is.EqualTo 0) test <@ stderr.ToString() |> String.IsNullOrEmpty @> @@ -3728,7 +3728,7 @@ module AltCoverTests3 = .GetMethod("main", BindingFlags.NonPublic ||| BindingFlags.Static) let returnCode = - main.Invoke(null, [| [| "-i"; unique |] |]) + main.Invoke(nullObject, [| [| "-i"; unique |] |]) Assert.That(returnCode, Is.EqualTo 255) diff --git a/AltCover.Tests/XTests.fs b/AltCover.Tests/XTests.fs index f8362604d..3e0c5b034 100644 --- a/AltCover.Tests/XTests.fs +++ b/AltCover.Tests/XTests.fs @@ -1418,7 +1418,7 @@ module AltCoverXTests = let p = t2.GetProperty("value", BindingFlags.NonPublic ||| BindingFlags.Static) - let v = p.GetValue(null) + let v = p.GetValue(nullObject) test <@ v.IsNotNull @> test <@ v.GetType() = typeof>> @> @@ -1426,7 +1426,7 @@ module AltCoverXTests = let m = t2.GetMethod("instance", BindingFlags.NonPublic ||| BindingFlags.Static) - let v2 = m.Invoke(null, [||]) + let v2 = m.Invoke(nullObject, [||]) test <@ v2.IsNotNull @> test <@ v2.GetType() = typeof> @> diff --git a/AltCover.UICommon/CoverageFileTree.fs b/AltCover.UICommon/CoverageFileTree.fs index d04b1e7df..c0481a28c 100644 --- a/AltCover.UICommon/CoverageFileTree.fs +++ b/AltCover.UICommon/CoverageFileTree.fs @@ -552,7 +552,7 @@ module CoverageFileTree = [ (missing, "NotAllSourcePresent") (newer, "SomeSourceModified") ] |> Seq.filter (fun (x, y) -> x |> Seq.isEmpty |> not) - |> Seq.map (fun (x, y) -> Resource.Format(y, [||])) + |> Seq.map (fun (x, y) -> Resource.Format(y, Array.empty)) let pc = pcCover [ navigator ] diff --git a/AltCover.ValidateGendarmeEmulation/Tests.fs b/AltCover.ValidateGendarmeEmulation/Tests.fs index 105612302..d09b7c3bc 100644 --- a/AltCover.ValidateGendarmeEmulation/Tests.fs +++ b/AltCover.ValidateGendarmeEmulation/Tests.fs @@ -132,8 +132,7 @@ module ValidateGendarmeEmulation = let GratuitousCoverage () = let l = Left 23 let r = Right true - let mutable x = Object() - x <- null + let mutable x : Object = null test <@ (23).IsNotNull @> test <@ x.IsNotNull |> not @> diff --git a/AltCover.Visualizer/Visualizer.fs b/AltCover.Visualizer/Visualizer.fs index cca107a2b..91bc4faa5 100644 --- a/AltCover.Visualizer/Visualizer.fs +++ b/AltCover.Visualizer/Visualizer.fs @@ -120,7 +120,7 @@ module private Gui = String.Join( Environment.NewLine, [ AltCover.AssemblyVersionInformation.AssemblyCopyright - Resource.Format("aboutVisualizer.Copyright", []) + Resource.Format("aboutVisualizer.Copyright", List.empty) "https://learn.microsoft.com/en-us/visualstudio/designers/the-visual-studio-image-library?view=vs-2022" ] ) @@ -282,7 +282,7 @@ module private Gui = ResponseType.Ok, Resource.GetResourceString "OpenFile.Cancel", ResponseType.Cancel, - null + nullObject ) let data = @@ -906,7 +906,7 @@ module private Gui = handler.classStructureTree.QueryTooltip |> Event.add (fun (x: QueryTooltipArgs) -> let tip = x.Tooltip - x.RetVal <- null + x.RetVal <- nullObject let mutable path: TreePath = null if handler.classStructureTree.GetPathAtPos(x.X, x.Y, &path) then diff --git a/Build/targets.fs b/Build/targets.fs index c997f9724..c88c7d68d 100644 --- a/Build/targets.fs +++ b/Build/targets.fs @@ -8002,7 +8002,7 @@ module Targets = true) |> List.map fst - Assert.That(coberturaFiles, Is.EquivalentTo [], "coberturaFiles") + Assert.That(coberturaFiles, Is.EquivalentTo List.empty, "coberturaFiles") let cobertura2Files = xml diff --git a/OutputBuildProps.props b/OutputBuildProps.props index 21bb2d75e..569c6d5cf 100644 --- a/OutputBuildProps.props +++ b/OutputBuildProps.props @@ -13,7 +13,7 @@ $(MSBuildThisFileDirectory)Build\ $(KeyDir)Infrastructure.snk $(OutputPath)\$(TargetFramework)\$(MSBuildProjectName).xml - --keyfile:$(InfrastructureKey) + --keyfile:$(InfrastructureKey) --strict-indentation+ Major false true @@ -23,6 +23,7 @@ $(InfrastructureKey) false false + FS3559;FS3560 diff --git a/Samples/Sample25/Sample25.fsproj b/Samples/Sample25/Sample25.fsproj index e12b1ed3f..70a39c504 100644 --- a/Samples/Sample25/Sample25.fsproj +++ b/Samples/Sample25/Sample25.fsproj @@ -4,6 +4,7 @@ net20 Sample25 Sample25 + --keyfile:$(InfrastructureKey)