Skip to content

Instantly share code, notes, and snippets.

@Krzysztof-Cieslak
Created September 14, 2018 19:29
Show Gist options
  • Save Krzysztof-Cieslak/42829ce7b5dcc937bece698a5af9ff2b to your computer and use it in GitHub Desktop.
Save Krzysztof-Cieslak/42829ce7b5dcc937bece698a5af9ff2b to your computer and use it in GitHub Desktop.
Option Analyzer
[<Analyzer>]
let optionValueAnalyzer : Analyzer =
fun ctx ->
let state = ResizeArray<range>()
let handler (range: range) (m: FSharpMemberOrFunctionOrValue) =
let name = String.Join(".", m.DeclaringEntity.Value.FullName, m.DisplayName)
if name = "Microsoft.FSharp.Core.FSharpOption`1.Value" then
state.Add range
ctx.TypedTree.Declarations |> List.iter (visitDeclaration handler)
state
|> Seq.map (fun r ->
{ Type = "Option.Value analyzer"
Message = "Option.Value shouldn't be used"
Code = "OV001"
Severity = Warning
Range = r
Fixes = []}
)
|> Seq.toList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment