-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathLibrary.fs
More file actions
43 lines (37 loc) · 1.31 KB
/
Library.fs
File metadata and controls
43 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module OptionAnalyzer.V1
open FSharp.Analyzers.SDK.V1
open FSharp.Analyzers.SDK.V1.TASTCollecting
let rec private findOptionValue (expr: TypedExpr) (results: ResizeArray<SourceRange>) =
match expr with
| TypedExpr.Call(_, m, _, _, _, range) ->
m.DeclaringEntity
|> Option.iter (fun de ->
let name = System.String.Join(".", de.FullName, m.DisplayName)
if name = "Microsoft.FSharp.Core.FSharpOption`1.Value" then
results.Add range
)
| _ -> ()
[<CliAnalyzer "OptionAnalyzer">]
let optionValueAnalyzer: Analyzer =
fun ctx ->
async {
let results = ResizeArray()
match ctx.TypedTree with
| None -> ()
| Some handle ->
let tree = convertTast handle
visitTypedTree (fun expr -> findOptionValue expr results) tree
return
results
|> Seq.map (fun r ->
{
Type = "Option.Value analyzer"
Message = "Option.Value shouldn't be used"
Code = "OV001"
Severity = Severity.Warning
Range = r
Fixes = []
}
)
|> Seq.toList
}