Skip to content

Commit 478e85b

Browse files
committed
AsynchronousFunctionNames: check typed tree
If there is no explicit return type.
1 parent 6ca4ebe commit 478e85b

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/FSharpLint.Core/Rules/Conventions/Naming/AsynchronousFunctionNames.fs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open FSharpLint.Framework.Ast
77
open FSharpLint.Framework.Rules
88
open FSharpLint.Rules.Utilities.LibraryHeuristics
99
open Helper.Naming.Asynchronous
10+
open Utilities.TypedTree
1011
open 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 checkAsyncFunction () =
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 checkTaskFunction () =
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 -> checkAsyncFunction()
77+
| Some ReturnsTask -> checkTaskFunction()
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 -> checkAsyncFunction()
85+
| FSharpTypeTask
86+
| FSharpTypeTaskNonGeneric -> checkTaskFunction()
87+
| FSharpTypeNonAsync -> Array.empty
88+
| None -> Array.empty
89+
| None -> Array.empty
7690
| _ ->
7791
Array.empty
7892
| _ -> Array.empty

0 commit comments

Comments
 (0)