dotnet / roslynator

Roslynator is a set of code analysis tools for C#, powered by Roslyn.
https://josefpihrt.github.io/docs/roslynator
Other
3.09k stars 258 forks source link

Support duck-typed awaitables and task-like types for Task/Async-related analyzers #1535

Closed Govorunb closed 1 month ago

Govorunb commented 1 month ago

Description

These changes add the same logic for checking duck-typed awaitables and task-like types that is currently in Roslyn.

This resolves #1529 - specifically, these analyzers/refactorings become aware of custom awaitables/custom task-like types:

Remarks

RCS1090's behaviour is less obvious here - it seems there is no official stance for duck-typing ConfigureAwait (even Roslyn isn't perfectly consistent), but I'm of the opinion that if the rest of the ducks are quacking, it's better to join the flock 😄 The result is that these checks are relaxed from the Task-specific ConfiguredTaskAwaitable(`1) return type to any awaitable return type.

I noticed there were some checks for WinRT async interfaces, these are covered as there's an extension GetAwaiter() method available on those types.

I'm not experienced with analyzers and their edge cases so it's possible I've missed writing some obvious tests, I'd love to get your feedback.

Govorunb commented 1 month ago

@dotnet-policy-service agree

josefpihrt commented 1 month ago

@Govorunb build failed

josefpihrt commented 1 month ago

@Govorunb Please update changelog.

josefpihrt commented 1 month ago

@Govorunb Great PR! Thanks for the contribution.