Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# linter add custom warning if cancellation token is not used (IDE: Rider)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there any simple way to do this?

Thanks

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading