@@ -5,11 +5,9 @@ open FSharpLint.Framework
55open FSharpLint.Framework .Suggestion
66open FSharpLint.Framework .Ast
77open FSharpLint.Framework .Rules
8- open Helper.Naming .Asynchronous
98open FSharp.Compiler .Syntax
10- open FSharp.Compiler .Symbols
11-
12- let asyncSuffixOrPrefix = " Async"
9+ open Helper.Naming .Asynchronous
10+ open Utilities.TypedTree
1311
1412let runner ( args : AstNodeRuleParams ) =
1513 let emitWarning range ( newFunctionName : string ) =
@@ -21,28 +19,38 @@ let runner (args: AstNodeRuleParams) =
2119 TypeChecks = List.empty
2220 }
2321
22+ let checkIdentifier ( funcIdent : SynLongIdent ) identRange =
23+ match funcIdent with
24+ | HasAsyncPrefix name ->
25+ let startsWithLowercase = Char.IsLower name.[ 0 ]
26+ let nameWithoutAsync = name.Substring asyncSuffixOrPrefix.Length
27+ let suggestedName =
28+ if startsWithLowercase then
29+ sprintf " %c%s " ( Char.ToLowerInvariant nameWithoutAsync.[ 0 ]) ( nameWithoutAsync.Substring 1 )
30+ else
31+ nameWithoutAsync
32+ emitWarning identRange suggestedName
33+ | HasAsyncSuffix name ->
34+ let nameWithoutAsync = name.Substring( 0 , name.Length - asyncSuffixOrPrefix.Length)
35+ emitWarning identRange nameWithoutAsync
36+ | HasNoAsyncPrefixOrSuffix _ -> Array.empty
37+
2438 match args.AstNode with
2539 | AstNode.Binding ( SynBinding (_, _, _, _, attributes, _, _, SynPat.LongIdent( funcIdent, _, _, _, _, identRange), returnInfo, _, _, _, _))
2640 when not <| Helper.Naming.isAttribute " Obsolete" attributes ->
2741 match returnInfo with
2842 | Some ReturnsNonAsync ->
29- match funcIdent with
30- | HasAsyncPrefix name ->
31- let startsWithLowercase = Char.IsLower name.[ 0 ]
32- let nameWithoutAsync = name.Substring asyncSuffixOrPrefix.Length
33- let suggestedName =
34- if startsWithLowercase then
35- sprintf " %c%s " ( Char.ToLowerInvariant nameWithoutAsync.[ 0 ]) ( nameWithoutAsync.Substring 1 )
36- else
37- nameWithoutAsync
38- emitWarning identRange suggestedName
39- | HasAsyncSuffix name ->
40- let nameWithoutAsync = name.Substring( 0 , name.Length - asyncSuffixOrPrefix.Length)
41- emitWarning identRange nameWithoutAsync
42- | HasNoAsyncPrefixOrSuffix _ -> Array.empty
43+ checkIdentifier funcIdent identRange
4344 | None ->
44- // TODO: get type using typed tree in args.CheckInfo
45- Array.empty
45+ match args.CheckInfo with
46+ | Some checkInfo ->
47+ match getFunctionReturnType checkInfo args.Lines funcIdent with
48+ | Some returnType ->
49+ match returnType with
50+ | FSharpTypeNonAsync -> checkIdentifier funcIdent identRange
51+ | _ -> Array.empty
52+ | None -> Array.empty
53+ | None -> Array.empty
4654 | _ ->
4755 Array.empty
4856 | _ -> Array.empty
0 commit comments