Skip to content

MA0050: improve Throw* argument validation detection#1100

Merged
meziantou merged 1 commit intomainfrom
meziantou/plan-ma0050-throwif-support
Apr 22, 2026
Merged

MA0050: improve Throw* argument validation detection#1100
meziantou merged 1 commit intomainfrom
meziantou/plan-ma0050-throwif-support

Conversation

@meziantou
Copy link
Copy Markdown
Owner

Why

MA0050 should recognize modern argument-validation helpers used before iterator execution. The previous check matched any method name containing Throw, which was broader than needed and could match unrelated method names.

What changed

  • Updated MA0050 invocation detection to require static methods on ArgumentException (or derived types) whose names start with Throw.
  • Added test coverage for:
    • ArgumentException.ThrowIfNullOrEmpty
    • custom ArgumentException-derived ThrowIf(...)
    • custom ArgumentException-derived Throw(...)
  • Updated MA0050 rule documentation to describe support for static Throw* helpers on ArgumentException-derived types.

Notes

This keeps support for ArgumentNullException.ThrowIfNull and related helpers, while avoiding the old Contains("Throw") behavior.

Validation

dotnet CLI is not available in this environment, so tests and doc generation could not be executed locally in this session.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@meziantou meziantou enabled auto-merge (squash) April 22, 2026 18:18
@meziantou meziantou merged commit d22e814 into main Apr 22, 2026
13 checks passed
@meziantou meziantou deleted the meziantou/plan-ma0050-throwif-support branch April 22, 2026 18:19
IhateTrains pushed a commit to ParadoxGameConverters/ImperatorToCK3 that referenced this pull request Apr 23, 2026
Updated
[Meziantou.Analyzer](https://github.com/meziantou/Meziantou.Analyzer)
from 3.0.50 to 3.0.52.

<details>
<summary>Release notes</summary>

_Sourced from [Meziantou.Analyzer's
releases](https://github.com/meziantou/Meziantou.Analyzer/releases)._

## 3.0.52

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.52>

## What's Changed
* Expand documentation for MA0065, MA0066, and MA0069 by @​meziantou in
meziantou/Meziantou.Analyzer#1099
* MA0050: improve Throw* argument validation detection by @​meziantou in
meziantou/Meziantou.Analyzer#1100


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.51...3.0.52

## 3.0.51

NuGet package:
<https://www.nuget.org/packages/Meziantou.Analyzer/3.0.51>

## What's Changed
* Extend MA0067 detection for empty Guid patterns by @​meziantou in
meziantou/Meziantou.Analyzer#1098


**Full Changelog**:
meziantou/Meziantou.Analyzer@3.0.50...3.0.51

Commits viewable in [compare
view](meziantou/Meziantou.Analyzer@3.0.50...3.0.52).
</details>

[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Meziantou.Analyzer&package-manager=nuget&previous-version=3.0.50&new-version=3.0.52)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.

1 participant