Do not report CA2007 for pattern-based await using and await foreach - #55036
Conversation
|
May I have a review here please? |
tannergooding
left a comment
There was a problem hiding this comment.
This needs a secondary sign-off, I've tagged some folks internally
There was a problem hiding this comment.
Pull request overview
Updates the CA2007 (DoNotDirectlyAwaitATask) analyzer to avoid reporting diagnostics for pattern-based await using and await foreach constructs where ConfigureAwait cannot be applied (e.g., duck-typed async disposal/enumeration), addressing #53461.
Changes:
- Refines
await usingandawait foreachanalysis to only report when the resource/collection is implicitly convertible toIAsyncDisposable/IAsyncEnumerable<T>, excluding pattern-based-only types. - Adds unit tests covering pattern-based
await using(statement + declaration) and pattern-basedawait foreachto ensure no CA2007 diagnostic is reported.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATask.cs | Narrows CA2007 reporting for await using/await foreach to interface-convertible cases to avoid flagging pattern-only types. |
| src/Microsoft.CodeAnalysis.NetAnalyzers/tests/Microsoft.CodeAnalysis.NetAnalyzers.UnitTests/Microsoft.CodeQuality.Analyzers/ApiDesignGuidelines/DoNotDirectlyAwaitATaskTests.cs | Adds regression tests ensuring no diagnostic for pattern-based await using/await foreach. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 1
| } | ||
| } No newline at end of file | ||
| } |
There was a problem hiding this comment.
I'll leave this up to you, feel free to ignore and close if you don't think its meaningful enough to provide.
There was a problem hiding this comment.
@DoctorKrolic if you could consider this, possibly for a follow up, that'd be great. I didn't feel it worth blocking on but would be add a little more robustness
There was a problem hiding this comment.
I am currently on vacation, will look at it when I return
Fixes: #53461