Add EPC37: Warn on argument validation in async methods#312
Merged
SergeyTeplyakov merged 2 commits intomasterfrom Jul 2, 2025
Merged
Add EPC37: Warn on argument validation in async methods#312SergeyTeplyakov merged 2 commits intomasterfrom
SergeyTeplyakov merged 2 commits intomasterfrom
Conversation
Introduces analyzer EPC37 to detect argument validation in public async methods, which can cause exceptions to be thrown only when the returned Task is awaited. Adds documentation, analyzer implementation, tests, and diagnostic descriptor for EPC37. Updates ReadMe and analyzer release notes accordingly.
Contributor
There was a problem hiding this comment.
Pull Request Overview
Adds a new analyzer (EPC37) that warns when public async methods perform argument validation by throwing exceptions, which delays failures until the returned Task is awaited. Also includes descriptor, tests, docs, and a small test harness update to support specifying language version.
- Introduce
DoNotValidateArgumentsInAsyncMethodsAnalyzerwith logic to catch throws and validation invocations in async methods - Add EPC37 diagnostic descriptor, tests, documentation, and release notes
- Extend test verifier to accept an optional
LanguageVersionparameter
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/RoslynNunitTestRunner/CSharpCodeFixVerifier`2+Test.cs | Added LanguageVersion overload and updated test initialization |
| src/ErrorProne.NET.CoreAnalyzers/DiagnosticDescriptors.cs | Added descriptor EPC37 |
| src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotValidateArgumentsInAsyncMethodsAnalyzer.cs | New analyzer implementation for EPC37 |
| src/ErrorProne.NET.CoreAnalyzers/AnalyzerReleases.Unshipped.md | Registered EPC37 in unshipped release notes |
| src/ErrorProne.NET.CoreAnalyzers.Tests/AsyncAnalyzers/DoNotValidateArgumentsInAsyncMethodsAnalyzerTests.cs | Added comprehensive tests for EPC37 |
| docs/Rules/EPC37.md | Documentation and examples for EPC37 |
| ReadMe.md | Updated rule tables to include EPC37 and adjust EPC20 grouping |
src/ErrorProne.NET.CoreAnalyzers/AsyncAnalyzers/DoNotValidateArgumentsInAsyncMethodsAnalyzer.cs
Show resolved
Hide resolved
Replaces a single-line return statement with an explicit if block for checking exception type names. This change improves readability and prepares for potential future extensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces analyzer EPC37 to detect argument validation in public async methods, which can cause exceptions to be thrown only when the returned Task is awaited. Adds documentation, analyzer implementation, tests, and diagnostic descriptor for EPC37. Updates ReadMe and analyzer release notes accordingly.