Header menu logo ionide-analyzers

HandleOptionGracefullyAnalyzer

Problem

The option type is used to model a potentially missing value. Unwrapping an 'a option into an 'a by using Option.get or option.Value circumvents the graceful handling of the None case. You should unwrap the value using a function like Option.defaultValue or pattern matching instead.

let option = None
let value = Option.get option // Triggers analyzer 
let value' = option.Value // Triggers analyzer

Fix

Gracefully handle the option value by accounting for both cases.

let option = None

match option with
| Some value -> ()
| None -> ()

// or
Option.defaultValue () option
Multiple items
val option: 'a option

--------------------
type 'T option = Option<'T>
union case Option.None: Option<'T>
val value: obj
module Option from Microsoft.FSharp.Core
val get: option: 'T option -> 'T
val value': obj
union case Option.Some: Value: 'T -> Option<'T>
val defaultValue: value: 'T -> option: 'T option -> 'T

Type something to start searching.