A method that receives a CancellationToken passes CancellationToken.None or default on to another call
What it finds
When a method accepts a token and then calls on with CancellationToken.None, the work it starts can no longer be cancelled by the caller who asked for it. Passing the received token on keeps cancellation working along the chain.
From the rule's source, token_none_despite_parameter.rs.
using System.Threading;using System.Threading.Tasks; class Sync{ async Task Run(CancellationToken token) { await Task.Delay(100, CancellationToken.None);tx0 reports: CancellationToken.None is passed although the method received a token await Task.Delay(100, token); }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:token-none-despite-parameter" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:token-none-despite-parameter] reason="..."tx0 explain tx0/csharp:token-none-despite-parameter shows the same in the terminal. Found a false positive? Report it.