Skip to content
Open
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 @@ -13,6 +13,8 @@ namespace StyleCop.Analyzers.Helpers

internal static class TaskHelper
{
public static readonly Task CompletedTask = Task.FromResult(0);

public static bool IsTaskReturningMethod(SemanticModel semanticModel, MethodDeclarationSyntax methodDeclarationSyntax, CancellationToken cancellationToken)
{
return IsTaskType(semanticModel, methodDeclarationSyntax.ReturnType, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.NamingRules
{
using System.Collections.Immutable;
using System.Composition;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp;
using StyleCop.Analyzers.Helpers;

/// <summary>
/// Implements a code fix for <see cref="SA1317IdentifierShouldBeNamedOnlyWithLatinLetters"/>.
/// </summary>
/// <remarks>
/// <para>To fix a violation of this rule, replace non-Latin letters with appropriate Latin letters.</para>
/// </remarks>
[ExportCodeFixProvider(LanguageNames.CSharp, Name = nameof(SA1317CodeFixProvider))]
[Shared]
internal class SA1317CodeFixProvider : CodeFixProvider
{
/// <inheritdoc/>
public override ImmutableArray<string> FixableDiagnosticIds { get; } =
ImmutableArray.Create(SA1317IdentifierShouldBeNamedOnlyWithLatinLetters.DiagnosticId);

/// <inheritdoc/>
public override FixAllProvider GetFixAllProvider()
{
return null;
}

/// <inheritdoc/>
public override async Task RegisterCodeFixesAsync(CodeFixContext context)
{
await TaskHelper.CompletedTask.ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp10.NamingRules
{
using StyleCop.Analyzers.Test.CSharp9.NamingRules;

public partial class SA1317CSharp10UnitTests : SA1317CSharp9UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp11.NamingRules
{
using StyleCop.Analyzers.Test.CSharp10.NamingRules;

public partial class SA1317CSharp11UnitTests : SA1317CSharp10UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp12.NamingRules
{
using StyleCop.Analyzers.Test.CSharp11.NamingRules;

public partial class SA1317CSharp12UnitTests : SA1317CSharp11UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp13.NamingRules
{
using StyleCop.Analyzers.Test.CSharp12.NamingRules;

public partial class SA1317CSharp13UnitTests : SA1317CSharp12UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp7.NamingRules
{
using StyleCop.Analyzers.Test.NamingRules;

public partial class SA1317CSharp7UnitTests : SA1317UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp8.NamingRules
{
using StyleCop.Analyzers.Test.CSharp7.NamingRules;

public partial class SA1317CSharp8UnitTests : SA1317CSharp7UnitTests
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Tunnel Vision Laboratories, LLC. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#nullable disable

namespace StyleCop.Analyzers.Test.CSharp9.NamingRules
{
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.NamingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.NamingRules.SA1317IdentifierShouldBeNamedOnlyWithLatinLetters,
StyleCop.Analyzers.NamingRules.SA1317CodeFixProvider>;

public partial class SA1317CSharp9UnitTests : SA1317CSharp8UnitTests
{
[Fact]
public async Task TestRecordNameDoesNotContainNonLatinLettersAsync()
{
var testCode = @"public record RecordName {}";

await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestRecordNameContainsNonLatinLettersAsync()
{
var testCode = @"public record RеcоrdNаmе {}";

Console.WriteLine("Test");

var expected = new DiagnosticResult[]
{
Diagnostic().WithArguments("RеcоrdNаmе", 1).WithLocation(1, 15),
Diagnostic().WithArguments("RеcоrdNаmе", 3).WithLocation(1, 15),
Diagnostic().WithArguments("RеcоrdNаmе", 7).WithLocation(1, 15),
Diagnostic().WithArguments("RеcоrdNаmе", 9).WithLocation(1, 15),
};

await VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
}
}
}
Loading
Loading