Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions samples/OptionAnalyzer/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,47 @@ let notUsed () =
let option: Option<int> = None
option.Value

[<CliAnalyzer "OptionAnalyzer">]
let optionValueAnalyzer: Analyzer<CliContext> =
fun ctx ->
async {
let state = ResizeArray<range>()
let handler typeTree =
async {
let state = ResizeArray<range>()

let walker =
{ new TypedTreeCollectorBase() with
override _.WalkCall _ m _ _ _ range =
let name = String.Join(".", m.DeclaringEntity.Value.FullName, m.DisplayName)
let walker =
{ new TypedTreeCollectorBase() with
override _.WalkCall _ m _ _ _ range =
m.DeclaringEntity
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you believe the analyzer itself was violating it's own premise?

|> Option.iter (fun de ->
let name = String.Join(".", de.FullName, m.DisplayName)

if name = "Microsoft.FSharp.Core.FSharpOption`1.Value" then
state.Add range

)

}

match typeTree with
| None -> ()
| Some typedTree -> walkTast walker typedTree

return
state
|> 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
}


match ctx.TypedTree with
| None -> ()
| Some typedTree -> walkTast walker typedTree

return
state
|> 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
}
[<EditorAnalyzerAttribute "OptionAnalyzer">]
let analyzerEditorContext : Analyzer<EditorContext> =
fun ctx -> handler ctx.TypedTree

[<CliAnalyzer "OptionAnalyzer">]
let optionValueAnalyzer: Analyzer<CliContext> =
fun ctx -> handler ctx.TypedTree