Skip to content

Commit e9874ef

Browse files
committed
feat: add new rule SA1317
- add a diagnostic - add an empty CodeFixProvider - add unit tests - add documentation #2057
1 parent f5843ae commit e9874ef

File tree

8 files changed

+794
-0
lines changed

8 files changed

+794
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/Helpers/TaskHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace StyleCop.Analyzers.Helpers
1313

1414
internal static class TaskHelper
1515
{
16+
public static readonly Task CompletedTask = Task.FromResult(0);
17+
1618
public static bool IsTaskReturningMethod(SemanticModel semanticModel, MethodDeclarationSyntax methodDeclarationSyntax, CancellationToken cancellationToken)
1719
{
1820
return IsTaskType(semanticModel, methodDeclarationSyntax.ReturnType, cancellationToken);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
#nullable disable
5+
6+
namespace StyleCop.Analyzers.NamingRules
7+
{
8+
using System.Collections.Immutable;
9+
using System.Composition;
10+
using System.Threading.Tasks;
11+
using Microsoft.CodeAnalysis;
12+
using Microsoft.CodeAnalysis.CodeActions;
13+
using Microsoft.CodeAnalysis.CodeFixes;
14+
using Microsoft.CodeAnalysis.CSharp;
15+
using StyleCop.Analyzers.Helpers;
16+
17+
/// <summary>
18+
/// Implements a code fix for <see cref="SA1317IdentifierShouldBeNamedOnlyWithLatinLetters"/>.
19+
/// </summary>
20+
/// <remarks>
21+
/// <para>To fix a violation of this rule, replace non-Latin letters with appropriate Latin letters.</para>
22+
/// </remarks>
23+
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SA1317CodeFixProvider))]
24+
[Shared]
25+
internal class SA1317CodeFixProvider : CodeFixProvider
26+
{
27+
/// <inheritdoc/>
28+
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
29+
ImmutableArray.Create(SA1317IdentifierShouldBeNamedOnlyWithLatinLetters.DiagnosticId);
30+
31+
/// <inheritdoc/>
32+
public override FixAllProvider GetFixAllProvider()
33+
{
34+
return null;
35+
}
36+
37+
/// <inheritdoc/>
38+
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
39+
{
40+
await TaskHelper.CompletedTask.ConfigureAwait(false);
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)