Skip to content

task(lint): enable ThrowIf* analyzers (CA1510–CA1513) #539

Open

Description

@currantw

Description

Enable the following .NET code-quality analyzers, which modernize argument/state guard
clauses to the concise ThrowIf* helpers introduced in .NET 8:

  • CA1510 —
    Use ArgumentNullException.ThrowIfNull instead of if (x is null) throw new ArgumentNullException(...).
  • CA1511 —
    Use ArgumentException.ThrowIfNullOrEmpty instead of if (string.IsNullOrEmpty(x)) throw new ArgumentException(...).
  • CA1512 —
    Use ArgumentOutOfRangeException.ThrowIf* (e.g. ThrowIfNegative, ThrowIfGreaterThan) instead of
    if (x < 0) throw new ArgumentOutOfRangeException(...).
  • CA1513 —
    Use ObjectDisposedException.ThrowIf instead of if (disposed) throw new ObjectDisposedException(...).

Enabling them only requires setting their severity in .editorconfig:

# CA1510: Use ArgumentNullException.ThrowIfNull
dotnet_diagnostic.CA1510.severity = error
# CA1511: Use ArgumentException.ThrowIfNullOrEmpty
dotnet_diagnostic.CA1511.severity = error
# CA1512: Use ArgumentOutOfRangeException.ThrowIf*
dotnet_diagnostic.CA1512.severity = error
# CA1513: Use ObjectDisposedException.ThrowIf
dotnet_diagnostic.CA1513.severity = error

Checklist

  • Add the four dotnet_diagnostic.CA151{0,1,2,3}.severity = error entries to .editorconfig.
  • Replace existing guard clauses with the corresponding ThrowIf* helpers.
  • Confirm the Lint build is green.

Activity

  1. added this to the 1.3 milestone on Aug 22, 2026
  2. added
    triageNeeds triage — not yet reviewed
    coreCore library (`sources/Valkey.Glide/`)
    devInternal changes like cleanup, refactoring, or developer tools.
    on Aug 22, 2026
  3. self-assigned this
    on Aug 22, 2026
  4. removed
    triageNeeds triage — not yet reviewed
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreCore library (`sources/Valkey.Glide/`)devInternal changes like cleanup, refactoring, or developer tools.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions