Home > Back-end >  C# linter add custom warning if cancellation token is not used (IDE: Rider)
C# linter add custom warning if cancellation token is not used (IDE: Rider)

Time:02-24

I'm wishing to add a warning if cancellation token is not used, for example:

var content = await File.ReadAllTextAsync(path)

since in our case, cancellation token should be used, as follows:

var content = await File.ReadAllTextAsync(path, _cancellation_token)

I'm using Rider as my IDE if that's important

Is there any simple way to do this?

Thanks

CodePudding user response:

Rider (and Resharper) have a refactoring "MethodSupportsCancellation". You can change the severity to warning error in the settings.

In addition, there is also a Code analysis rule (CA2016) about this, so if you run the code analysis tool (I think Rider incorporates them by default) you can also change the severity of that.

Search the inspection settings for cancel:

Rider settings

  • Related