Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve S6967: Filter out CancellationToken parameters #9236

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static void ProcessCodeBlock(SonarCodeBlockStartAnalysisContext<SyntaxKi
{
if (codeBlockContext.CodeBlock is MethodDeclarationSyntax methodDeclaration
&& codeBlockContext.OwningSymbol is IMethodSymbol methodSymbol
&& methodSymbol.Parameters.Length > 0
&& methodSymbol.Parameters.Any(x => !x.Type.Is(KnownType.System_Threading_CancellationToken))
&& methodSymbol.IsControllerActionMethod()
&& !HasActionFilterAttribute(methodSymbol))
{
Expand Down
1 change: 1 addition & 0 deletions analyzers/src/SonarAnalyzer.Common/Helpers/KnownType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ public sealed partial class KnownType
public static readonly KnownType System_Text_RegularExpressions_Regex = new("System.Text.RegularExpressions.Regex");
public static readonly KnownType System_Text_RegularExpressions_RegexOptions = new("System.Text.RegularExpressions.RegexOptions");
public static readonly KnownType System_Text_StringBuilder = new("System.Text.StringBuilder");
public static readonly KnownType System_Threading_CancellationToken = new("System.Threading.CancellationToken");
public static readonly KnownType System_Threading_CancellationTokenSource = new("System.Threading.CancellationTokenSource");
public static readonly KnownType System_Threading_Monitor = new("System.Threading.Monitor");
public static readonly KnownType System_Threading_Mutex = new("System.Threading.Mutex");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

Expand Down Expand Up @@ -90,6 +92,9 @@ public string Many([Required, FromQuery, EmailAddress] string email) // N

[HttpGet("/[controller]/list")]
public string[] List() => null; // Compliant

[HttpGet("/[controller]/listasync")]
public Task<string[]> ListAsync(CancellationToken token) => null; // Compliant
}

[ApiController]
Expand Down
Loading