-
Notifications
You must be signed in to change notification settings - Fork 467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CA2024: Do not use 'StreamReader.EndOfStream' in async methods #7390
Conversation
This analyzer detects when 'StreamReader.EndOfStream' is used in an async method, which can prevent I/O from being done asynchronously.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7390 +/- ##
========================================
Coverage 96.50% 96.50%
========================================
Files 1448 1450 +2
Lines 346895 347319 +424
Branches 11404 11409 +5
========================================
+ Hits 334755 335186 +431
+ Misses 9250 9242 -8
- Partials 2890 2891 +1 |
...zers/UnitTests/Microsoft.NetCore.Analyzers/Runtime/DoNotUseEndOfStreamInAsyncMethodsTests.cs
Outdated
Show resolved
Hide resolved
...zers/UnitTests/Microsoft.NetCore.Analyzers/Runtime/DoNotUseEndOfStreamInAsyncMethodsTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than some changes for the tests, this LGTM. Thanks for working on this.
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotUseEndOfStreamInAsyncMethods.cs
Outdated
Show resolved
Hide resolved
Using the Stream type, or more specifically, the EndOfStream property of the Stream type, should be much rarer than async methods in general, so we check the symbols first.
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotUseEndOfStreamInAsyncMethods.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/Runtime/DoNotUseEndOfStreamInAsyncMethods.cs
Outdated
Show resolved
Hide resolved
I've addressed your feedback, thanks for the review! |
thanks! |
Fixes dotnet/runtime#98834.
This analyzer detects when
StreamReader.EndOfStream
is used in an async method, which can prevent I/O from being done asynchronously.I've tested against
dotnet/runtime
,dotnet/roslyn
anddotnet/aspnetcore
and found no violations.I've also added a reference to
EndOfStream
in an async method in runtime for testing, which leads to the following message:warning CA2024: Do not use 'sr.EndOfStream' in an async method
.