Skip to content

Commit

Permalink
Simplify/manual linting
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveGilham committed Jun 8, 2023
1 parent a821751 commit aa6f5b8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
3 changes: 1 addition & 2 deletions AltCover.Engine/ProgramDatabase.fs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@ module internal ProgramDatabase =

let folder =
foldername :: (Seq.toList symbolFolders)
|> Seq.map (I.getSymbolsByFolder filename)
|> Seq.choose id
|> Seq.choose (I.getSymbolsByFolder filename)
|> Seq.tryFind (I.symbolMatch tokens)

sprintf
Expand Down
9 changes: 4 additions & 5 deletions AltCover.Engine/Visitor.fs
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ module internal Visitor =
+ name

CoverageParameters.trackingNames
|> Seq.map (fun n ->
|> Seq.choose (fun n ->
if n.Chars(0) = '[' then
let stripped = n.Trim([| '['; ']' |])

Expand All @@ -844,7 +844,6 @@ module internal Visitor =
Some n
else
None)
|> Seq.choose id
|> Seq.tryFind (fun _ -> true)
|> Option.map (fun n ->
let id = methodNumber + 1
Expand Down Expand Up @@ -1649,18 +1648,18 @@ module internal Visitor =
"AvoidMessageChainsRule",
Scope = "member",
Target =
"AltCover.Visitor/I/generated@1380::Invoke(Mono.Cecil.Cil.Instruction)",
"AltCover.Visitor/I/generated@1379::Invoke(Mono.Cecil.Cil.Instruction)",
Justification = "No direct call available")>]
[<assembly: SuppressMessage("Gendarme.Rules.Exceptions",
"InstantiateArgumentExceptionCorrectlyRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/start@1230::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
"AltCover.Visitor/I/start@1229::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
Justification = "Inlined library code")>]
[<assembly: SuppressMessage("Gendarme.Rules.Exceptions",
"InstantiateArgumentExceptionCorrectlyRule",
Scope = "member", // MethodDefinition
Target =
"AltCover.Visitor/I/finish@1233::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
"AltCover.Visitor/I/finish@1232::Invoke(Microsoft.FSharp.Core.FSharpFunc`2<Mono.Cecil.Cil.Instruction,System.Int32>,Microsoft.FSharp.Collections.FSharpList`1<Mono.Cecil.Cil.Instruction>)",
Justification = "Inlined library code")>]
()
18 changes: 6 additions & 12 deletions AltCover.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,8 +1845,7 @@ module AltCoverTests =

Assert.That(
methods
|> Seq.map Visitor.I.containingMethod
|> Seq.choose id
|> Seq.choose Visitor.I.containingMethod
|> Seq.filter (fun m -> m.Name = "G3"),
Is.EquivalentTo [ g3; g3; g3 ]
)
Expand All @@ -1855,8 +1854,7 @@ module AltCoverTests =

Assert.That(
methods
|> Seq.map Visitor.I.containingMethod
|> Seq.choose id
|> Seq.choose Visitor.I.containingMethod
|> Seq.filter (fun m -> m.Name = "G1"),
Is.EquivalentTo [ g1; g1 ]
)
Expand Down Expand Up @@ -2970,8 +2968,7 @@ module AltCoverTests =
let tracks =
def.MainModule.GetAllTypes()
|> Seq.collect (fun t -> t.Methods)
|> Seq.map (Visitor.I.track)
|> Seq.choose id
|> Seq.choose (Visitor.I.track)
|> Seq.toList

Assert.That(tracks, Is.EquivalentTo [ (1, "[Test"); (2, "[Test") ])
Expand Down Expand Up @@ -3029,8 +3026,7 @@ module AltCoverTests =
let tracks =
def.MainModule.GetAllTypes()
|> Seq.collect (fun t -> t.Methods)
|> Seq.map (Visitor.I.track)
|> Seq.choose id
|> Seq.choose (Visitor.I.track)
|> Seq.toList

Assert.That(
Expand Down Expand Up @@ -3069,8 +3065,7 @@ module AltCoverTests =
let tracks =
def.MainModule.GetAllTypes()
|> Seq.collect (fun t -> t.Methods)
|> Seq.map (Visitor.I.track)
|> Seq.choose id
|> Seq.choose (Visitor.I.track)
|> Seq.toList

Assert.That(
Expand Down Expand Up @@ -4661,11 +4656,10 @@ module AltCoverTests =
Inspection = Inspections.Instrument
Track = None
DefaultVisitCount = Exemption.None }
|> Seq.map (fun n ->
|> Seq.choose (fun n ->
match n with
| BranchPoint b -> Some b
| _ -> None)
|> Seq.choose id
|> Seq.toList
// The only overt branching in this function are the 4 match cases
// Internal IL conditional branching is a compiler thing from inlining "string"
Expand Down
9 changes: 3 additions & 6 deletions AltCover.Tests/Tests2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2109,11 +2109,10 @@ has been prefixed with Ldc_I4_1 (1 byte)
Inspection = Inspections.Instrument
Track = None
DefaultVisitCount = Exemption.None }
|> Seq.map (fun n ->
|> Seq.choose (fun n ->
match n with
| BranchPoint b -> Some b
| _ -> None)
|> Seq.choose id
|> Seq.take 2 // start of a switch
|> Seq.toList

Expand Down Expand Up @@ -2207,11 +2206,10 @@ has been prefixed with Ldc_I4_1 (1 byte)
Inspection = Inspections.Instrument
Track = None
DefaultVisitCount = Exemption.None }
|> Seq.map (fun n ->
|> Seq.choose (fun n ->
match n with
| BranchPoint b -> Some b
| _ -> None)
|> Seq.choose id
|> Seq.skip 2
|> Seq.take 2 // first of "switch"
|> Seq.toList
Expand Down Expand Up @@ -2298,11 +2296,10 @@ has been prefixed with Ldc_I4_1 (1 byte)
Inspection = Inspections.Instrument
Track = None
DefaultVisitCount = Exemption.None }
|> Seq.map (fun n ->
|> Seq.choose (fun n ->
match n with
| BranchPoint b -> Some b
| _ -> None)
|> Seq.choose id
|> Seq.take 2 // start of a switch
|> Seq.toList

Expand Down
6 changes: 2 additions & 4 deletions Demo/inspector/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,8 @@ let inspect (def: AssemblyDefinition) =
[<EntryPoint>]
let main argv =
argv
|> Seq.map getFileExists
|> Seq.choose id
|> Seq.map loadInCecil
|> Seq.choose id
|> Seq.choose getFileExists
|> Seq.choose loadInCecil
|> Seq.iter inspect

0 // return an integer exit code

0 comments on commit aa6f5b8

Please sign in to comment.