Skip to content

GC002 — No Nullable Return

This page documents the GC002 rule, which prohibits public methods from returning null or nullable reference types (T?) as a way to signal absence of a value.

Work in Progress

This page is under construction. MonadicLeaf is in active development.

What This Rule Enforces

When this page is complete, it will explain how GC002 analyzes the return type and return statements of public methods to detect cases where null or T? is used to communicate "no value found". This pattern forces callers to perform null checks or risk NullReferenceException, and it makes the absence of a value invisible at the method signature level. GC002 flags both explicit return null statements and methods whose declared return type is a nullable reference type without a deliberate, documented reason.

Suggested Alternative

This section will show how to replace nullable returns with Option<T> from MonadicSharp. Option<T> makes the possibility of absence explicit in the type signature, removes the need for null checks, and integrates with the rest of the functional pipeline via Map, Bind, and Match. The page will include a comparison of before/after patterns for common scenarios such as repository lookups, configuration reads, and parser results.

Auto-Fix

GC002 is supported by ml migrate. This section will describe which nullable return patterns the auto-fix can handle automatically — such as wrapping existing return values in Option.Some() and replacing return null with Option.None<T>() — and where the transformation requires manual review.


← Back to rules index

← Back to home

Released under the MIT License.