Skip to content

docs: explain using CA1062 with guard clauses - #420

Merged
ardalis merged 1 commit into
ardalis:mainfrom
XakimovNosirbek:docs/ca1062-readme
Nov 17, 2026
Merged

ardalis merged 1 commit into
ardalis:mainfrom
XakimovNosirbek:docs/ca1062-readme

Conversation

@XakimovNosirbek

Copy link
Copy Markdown
Contributor

Closes #165

Adds a README section on using CA1062 to find public methods that don't guard their parameters, as suggested in the issue.

It turns out no null_check_validation_methods configuration is needed. Null, NullOrEmpty, NullOrWhiteSpace and NotFound already mark their input with [ValidatedNotNull], and CA1062 honours that attribute. Enabling the rule is enough.

I checked this with Ardalis.GuardClauses 5.0.0 on net8.0 and dotnet_diagnostic.CA1062.severity = warning:

case CA1062
Guard.Against.Null(order); order.Name none
Guard.Against.NullOrEmpty(s); s.Trim() none
order.Name with no guard reported
same project, <Nullable>enable</Nullable> none (non-nullable parameters are skipped)
custom guard in another project, input marked [ValidatedNotNull] none
custom guard in another project, no attribute reported

The last two rows are why the section suggests [ValidatedNotNull] for custom guards in a shared library.

@sonarqubecloud

Copy link
Copy Markdown

@ardalis
ardalis merged commit 514f157 into ardalis:main Nov 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Analyzers that verify this is used in all public methods

2 participants