navigation

FavourNamedMembers (FL0094)

Introduced in 0.26.12

Cause

Discriminated union case field is unnamed.

Rationale

Fields in discriminated union cases can be declared either named or unnamed.

Unnamed:

type Data =
    | TwoParts of string * string
    | OnePart of string

Named:

type Data =
    | TwoParts of part1: string * part2: string
    | OnePart of part1: string

The latter is preferable because it conveys the purpose of each field and helps differentiate between fields, especially if they are of the same type.

An exception is for DUs with single case with one field.

Example: Named:

type Foo =
    | Foo of int

How To Fix

Add a field name to the discriminated union case field.

Rule Settings

{
    "favourNamedMembers": {
        "enabled": false
    }
}