Skip to main content
ai-slop/csharp-null-forgivingmanual fix

Null-forgiving operator.

A postfix `!` (`user!.Name`, `GetValue()!`) that tells the compiler a value is not null. It silences the nullable warning without checking anything.

Flagged shape and clean shape.

Each example shows the exact code shape the rule is looking for, then the smallest version that keeps the intent without hiding risk or adding noise.

csharp-null-forgiving.cs
✗ Flagged
public string ShippingLabel(Order order)
{
    var address = _addresses.Find(order.AddressId);
    return address!.FormatLabel();
}
Why this trips

Deterministic line match on masked source: flags `!` directly after an identifier, `)` or `]` when followed by whitespace, `.`, `;`, `,`, a closing bracket, or the end of the line.

csharp-null-forgiving.cs
✓ Clean
public string ShippingLabel(Order order)
{
    var address = _addresses.Find(order.AddressId)
        ?? throw new InvalidOperationException($"Order {order.Id} has no address");
    return address.FormatLabel();
}
What changed

Handle the null: guard and throw with context, use `??` with a real default, or restructure so the type is non-nullable. Use `!` only where non-null is provable, and say why.

When nullable analysis flags a possible null, the quickest route to a clean build is one character. The null check the warning asked for never gets written.

How this rule is justified.

Rule id

ai-slop/csharp-null-forgiving

Enforcing engine

ai-slop

Detector strategy

Deterministic line match on masked source: flags `!` directly after an identifier, `)` or `]` when followed by whitespace, `.`, `;`, `,`, a closing bracket, or the end of the line.

Legitimate code that is NOT flagged

`!=` comparisons, logical-not prefixes such as `!isValid`, and `!` inside strings or comments are not flagged.

Evidence

Part of aislop's C# rule set. First-class C# support, including C#-specific AI-slop rules, arrived in aislop v0.14.1.