navigation

UsedUnderscorePrefixedElements (FL0082)

Introduced in 0.23.0

Cause

An underscore-prefixed element is being used.

Rationale

Underscore (_) or underscore-prefixed elements are normally used for things that are not being used.

To understand this better, let's examine what happens when we have the below pattern match and we enable warning FS1182:

let SomeFunction (someDuParam: SomeDU) =
    match someDuParam with
    | FirstDuMemberWithNoArgs -> true
    | SecondDuMemberWithTuple(tupleElement1, tupleElement2) ->
        if tupleElement2.SomeProperty then
            false
        else
            true

The F# compiler would start yelling with the warning FS1182: The value 'tupleElement1' is unused.

One way to fix the warning would be to simply rename the tupleElement1 symbol to '_', but a better way would be to leave the name, just adding an underscore to denote that the value is not used (yet?): _tupleElement1.

This reasoning, of course, only works if we know for sure that no elements prefixed with underscores are ever used, but unfortunately this fact is not enforced by the F# compiler, because the addition of an underscore prefix is just a convention (so this is where this rule comes in to help).

How To Fix

Remove the underscore prefix or avoid using that element in the code.

Rule Settings

{
    "usedUnderscorePrefixedElements": {
        "enabled": true
    }
}