Skip to content

Commit

Permalink
Assert function signature.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Oct 4, 2023
1 parent 016665a commit 2773f1e
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/FSharp.Analyzers/StringAnalyzers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@ module StringAnalyzers =
)
}

let hasMatchingSignature (expectedSignature : string) (mfv : FSharpMemberOrFunctionOrValue) : bool =
let rec visit (fsharpType : FSharpType) =
if fsharpType.GenericArguments.Count = 0 then
fsharpType.ErasedType.BasicQualifiedName
else
fsharpType.GenericArguments |> Seq.map visit |> String.concat " -> "

visit mfv.FullType = expectedSignature

[<CliAnalyzer>]
let endsWithAnalyzer (ctx : CliContext) : Async<Message list> =
invalidStringFunctionUseAnalyzer
Expand All @@ -146,11 +155,7 @@ module StringAnalyzers =
(function
| SingleStringArgumentExpr _ -> true
| _ -> false)
(fun mfv ->
mfv.CurriedParameterGroups.Count = 1
&& mfv.CurriedParameterGroups.[0].Count = 1
&& mfv.CurriedParameterGroups.[0].[0].Type.ErasedType.BasicQualifiedName = "System.String"
)
(hasMatchingSignature "System.String -> System.Boolean")

[<CliAnalyzer>]
let startsWithAnalyzer (ctx : CliContext) : Async<Message list> =
Expand All @@ -165,8 +170,4 @@ module StringAnalyzers =
(function
| SingleStringArgumentExpr _ -> true
| _ -> false)
(fun mfv ->
mfv.CurriedParameterGroups.Count = 1
&& mfv.CurriedParameterGroups.[0].Count = 1
&& mfv.CurriedParameterGroups.[0].[0].Type.ErasedType.BasicQualifiedName = "System.String"
)
(hasMatchingSignature "System.String -> System.Boolean")

0 comments on commit 2773f1e

Please sign in to comment.