sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

New rule: Async methods with yield statements should have a decorated cancelation token

Open Corniel opened this issue 3 years ago • 2 comments

Fixes #6003

As proposed at the community, when having an async yielding method, the cancellation token should exist and be decorated. #6003

async IAsyncEnumerable<int> Yields([EnumeratorCancellation] CancellationToken token)
{
    yield return 13;
}

As far as I know, this can not be achieved in VB.NET as the compiler forbids to have both the Async and the Iterator modifier on an method.

Corniel avatar Jul 20 '22 07:07 Corniel

Hi @Corniel, can you please open an issue first with the usual rule specification proposal?

VB.NET doesn't have yield so it should not be relevant there as you've mentioned.

Hi @Corniel, can you please open an issue first with the usual rule specification proposal?

VB.NET doesn't have yield so it should not be relevant there as you've mentioned.

I was hoping the reporter would do that, but it seems pretty silent from there.

Corniel avatar Aug 15 '22 13:08 Corniel