Table of Contents

TRLS017 — Don't compare Result or Maybe to null

  • Severity: Warning
  • Category: Trellis

What it detects

Flags == null, != null, is null, and is not null when the checked value is a Trellis Result<T> or Maybe<T>.

Why it matters

These are structs. Presence and success are represented by state members such as HasValue, HasNoValue, IsSuccess, and IsFailure, not by nullability.

Warning

A null check can look harmless, but it asks the wrong question and hides the actual success or optionality rule.

Bad example

using Trellis;

static class Example
{
    public static string Bad(Maybe<string> nickname) =>
        nickname == null ? "Anonymous" : nickname.Value;
}

Good example

using Trellis;

static class Example
{
    public static string Good(Maybe<string> nickname) =>
        nickname.HasNoValue ? "Anonymous" : nickname.Value;
}

Code fix available

No.

Configuration

Use standard Roslyn configuration if you need to suppress this rule in a specific scope.

dotnet_diagnostic.TRLS017.severity = none
#pragma warning disable TRLS017
// Intentional: documented exception or test-only pattern.
#pragma warning restore TRLS017
Tip

Check the state you actually care about: HasValue for Maybe<T>, IsSuccess or IsFailure for Result<T>.