From 6ac3fe9b2b143ce13a719609fe2011eadebd6694 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Mon, 6 Aug 2018 06:12:00 -0500 Subject: [PATCH] Add initial documentation for IncludeCancellationParameter Fixes #44 --- AsyncUsageAnalyzers.sln | 1 + documentation/IncludeCancellationParameter.md | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 documentation/IncludeCancellationParameter.md diff --git a/AsyncUsageAnalyzers.sln b/AsyncUsageAnalyzers.sln index 8aa6e0d..c977dc1 100644 --- a/AsyncUsageAnalyzers.sln +++ b/AsyncUsageAnalyzers.sln @@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "documentation", "documentat ProjectSection(SolutionItems) = preProject documentation\AvoidAsyncSuffix.md = documentation\AvoidAsyncSuffix.md documentation\AvoidAsyncVoid.md = documentation\AvoidAsyncVoid.md + documentation\IncludeCancellationParameter.md = documentation\IncludeCancellationParameter.md documentation\UseAsyncSuffix.md = documentation\UseAsyncSuffix.md documentation\UseConfigureAwait.md = documentation\UseConfigureAwait.md EndProjectSection diff --git a/documentation/IncludeCancellationParameter.md b/documentation/IncludeCancellationParameter.md new file mode 100644 index 0000000..b0f02ad --- /dev/null +++ b/documentation/IncludeCancellationParameter.md @@ -0,0 +1,43 @@ +## IncludeCancellationParameter + + + + + + + + + + + + + + +
TypeNameIncludeCancellationParameterAnalyzer
CheckIdIncludeCancellationParameter
CategoryUsage Rules
+ +## Cause + +An asynchronous method does not include a `CancellationToken` parameter. + +## Rule description + +This diagnostic identifies asynchronous methods which do not include a `CancellationToken` parameter in their signature. + +## How to fix violations + +To fix a violation of this rule, add a `CancellationToken` parameter to the signature of the method. + +## How to suppress violations + +```csharp +[SuppressMessage("AsyncUsage.CSharp.Usage", "IncludeCancellationParameter", Justification = "Reviewed.")] +``` + +```csharp +#pragma warning disable IncludeCancellationParameter // Include CancellationToken parameter +public Task ThisMethodCannotBeCancelled() +#pragma warning restore IncludeCancellationParameter // Include CancellationToken parameter +{ + return Task.FromResult(0); +} +```