@@ -7,6 +7,7 @@ open FSharpLint.Framework.Ast
77open FSharpLint.Framework .Rules
88open FSharpLint.Rules .Utilities .LibraryHeuristics
99open Helper.Naming .Asynchronous
10+ open Utilities.TypedTree
1011open FSharp.Compiler .Syntax
1112
1213[<RequireQualifiedAccess>]
@@ -41,6 +42,24 @@ let runner (config: Config) (args: AstNodeRuleParams) =
4142 match args.AstNode with
4243 | AstNode.Binding ( SynBinding (_, _, _, _, attributes, _, _, SynPat.LongIdent( funcIdent, _, _, _, accessibility, identRange), returnInfo, _, _, _, _))
4344 when isAccessibilityLevelApplicable accessibility && not <| Helper.Naming.isAttribute " Obsolete" attributes ->
45+ let checkAsync () =
46+ match funcIdent with
47+ | HasAsyncPrefix _ ->
48+ Array.empty
49+ | HasAsyncSuffix name
50+ | HasNoAsyncPrefixOrSuffix name ->
51+ let nameWithAsync = asyncSuffixOrPrefix + name
52+ emitWarning identRange nameWithAsync " Async"
53+
54+ let checkTask () =
55+ match funcIdent with
56+ | HasAsyncSuffix _ ->
57+ Array.empty
58+ | HasAsyncPrefix name
59+ | HasNoAsyncPrefixOrSuffix name ->
60+ let nameWithAsync = name + asyncSuffixOrPrefix
61+ emitWarning identRange nameWithAsync " Task"
62+
4463 let parents = args.GetParents args.NodeIndex
4564 let hasEnclosingFunctionOrMethod =
4665 parents
@@ -54,25 +73,20 @@ let runner (config: Config) (args: AstNodeRuleParams) =
5473 Array.empty
5574 else
5675 match returnInfo with
57- | Some ReturnsAsync ->
58- match funcIdent with
59- | HasAsyncPrefix _ ->
60- Array.empty
61- | HasAsyncSuffix name
62- | HasNoAsyncPrefixOrSuffix name ->
63- let nameWithAsync = asyncSuffixOrPrefix + name
64- emitWarning identRange nameWithAsync " Async"
65- | Some ReturnsTask ->
66- match funcIdent with
67- | HasAsyncSuffix _ ->
68- Array.empty
69- | HasAsyncPrefix name
70- | HasNoAsyncPrefixOrSuffix name ->
71- let nameWithAsync = name + asyncSuffixOrPrefix
72- emitWarning identRange nameWithAsync " Task"
76+ | Some ReturnsAsync -> checkAsync()
77+ | Some ReturnsTask -> checkTask()
7378 | None ->
74- // TODO: get type using typed tree in args.CheckInfo
75- Array.empty
79+ match args.CheckInfo with
80+ | Some checkInfo ->
81+ match getFunctionReturnType checkInfo args.Lines funcIdent with
82+ | Some returnType ->
83+ match returnType with
84+ | FSharpTypeAsync -> checkAsync()
85+ | FSharpTypeTask
86+ | FSharpTypeTaskNonGeneric -> checkTask()
87+ | FSharpTypeNonAsync -> Array.empty
88+ | None -> Array.empty
89+ | None -> Array.empty
7690 | _ ->
7791 Array.empty
7892 | _ -> Array.empty
0 commit comments