-
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
Analyzer + Fixer: Forward cancellation token to method invocations #3641
Analyzer + Fixer: Forward cancellation token to method invocations #3641
Conversation
Why the focus on whether awaits exist? This rule should apply to synchronous methods just as much as async ones. If you search dotnet/runtime#33774 for the term "async" you'll find a few discussion items on this question where @stephentoub agreed with this assertion. |
...rp/Microsoft.NetCore.Analyzers/Runtime/CSharpForwardCancellationTokenToAsyncMethods.Fixer.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
I would like to read what people think about the "Potential future improvements" section in the main description - is it ok to get them addressed later, or do you think I should address them now? |
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethodsTests.cs
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
src/NetAnalyzers/Core/Microsoft.NetCore.Analyzers/MicrosoftNetCoreAnalyzersResources.resx
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToAsyncMethods.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...s/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Analyzer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Fixer.cs
Outdated
Show resolved
Hide resolved
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Fixer.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Outdated
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Show resolved
Hide resolved
.../UnitTests/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocationsTests.cs
Show resolved
Hide resolved
...c/Microsoft.NetCore.Analyzers/Runtime/BasicForwardCancellationTokenToInvocations.Analyzer.vb
Show resolved
Hide resolved
...asic/Microsoft.NetCore.Analyzers/Runtime/BasicForwardCancellationTokenToInvocations.Fixer.vb
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.
Overall, looks great to me! Thanks for the extensive test suite! I have some suggestions around certain conditions that seem always false in the analyzer and other minor nit comments.
I am really looking forward to enabling this analyzer in all our repos!! Thanks.
...zers/Core/Microsoft.NetCore.Analyzers/Runtime/ForwardCancellationTokenToInvocations.Fixer.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.
Thanks!
CA2016: Forward CancellationToken to methods.
Fixes dotnet/runtime#33774
Summary
The rule should try to identify places where a
CancellationToken
(ct) should have been passed but wasn't. For example, in a method that takes a ct, a method is called that has an overload that takes a ct but a shorter overload that doesn't take a ct was used instead.Conditions for positive cases
The node to analyze is an awaited invocation, or is the origin invocation of aConfigureAwait
.and there's an awaited invocation inside it.Conditions for negative cases
The node to analyze is not an awaited invocation.awaitedinvocation is already receiving a ct argument.default
ordefault(CancellationToken)
in C#,Nothing
in VB, orCancellationToken.None
, or the token from aCancellationTokenSource
, or something else.Pending to address
CancellationToken
is renamed among the usings directives (is it called an alias?).Potential future improvements
ContinueWith
overloads have the ct in the middle.