From 2773f1efb0a66f8ba21d9d71cbafae78f944bff2 Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 20 Sep 2023 11:29:49 +0200 Subject: [PATCH] Assert function signature. --- src/FSharp.Analyzers/StringAnalyzers.fs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/FSharp.Analyzers/StringAnalyzers.fs b/src/FSharp.Analyzers/StringAnalyzers.fs index 4304e9b..5570e42 100644 --- a/src/FSharp.Analyzers/StringAnalyzers.fs +++ b/src/FSharp.Analyzers/StringAnalyzers.fs @@ -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 + [] let endsWithAnalyzer (ctx : CliContext) : Async = invalidStringFunctionUseAnalyzer @@ -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") [] let startsWithAnalyzer (ctx : CliContext) : Async = @@ -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")