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

Update SA1206 to handle c# 11 modifier "required" #3535

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 @@ -6,6 +6,7 @@ namespace StyleCop.Analyzers.Test.CSharp11.OrderingRules
using System.Threading;
using System.Threading.Tasks;
using StyleCop.Analyzers.Test.CSharp10.OrderingRules;
using StyleCop.Analyzers.Test.Verifiers;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.OrderingRules.SA1206DeclarationKeywordsMustFollowOrder,
Expand All @@ -23,5 +24,36 @@ public async Task VerifyFileKeywordReorderingInClassDeclarationAsync()
var expected = Diagnostic().WithLocation(0).WithArguments("file", "unsafe");
await VerifyCSharpFixAsync(testCode, expected, fixedTestCode, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3527, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3527")]
public async Task VerifyRequiredKeywordReorderingInPropertiesAndFieldsAsync()
{
var testCode = @"
internal struct SomeStruct
{
required {|#0:public|} int Prop { get; set; }
required {|#1:public|} int Field;
}";

var fixedCode = @"
internal struct SomeStruct
{
public required int Prop { get; set; }
public required int Field;
}";

await new CSharpTest()
{
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet70,
TestCode = testCode,
FixedCode = fixedCode,
ExpectedDiagnostics =
{
Diagnostic().WithLocation(0).WithArguments("public", "required"),
Diagnostic().WithLocation(1).WithArguments("public", "required"),
},
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ namespace StyleCop.Analyzers.Test.Verifiers
{
using System;
using System.Collections.Immutable;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
Expand All @@ -23,6 +22,8 @@ internal static class GenericAnalyzerTest

internal static readonly ReferenceAssemblies ReferenceAssembliesNet60;

internal static readonly ReferenceAssemblies ReferenceAssembliesNet70;

private static readonly Lazy<IExportProviderFactory> ExportProviderFactory;

static GenericAnalyzerTest()
Expand All @@ -44,15 +45,11 @@ static GenericAnalyzerTest()
ReferenceAssembliesNet50 = ReferenceAssemblies.Net.Net50.AddPackages(ImmutableArray.Create(
new PackageIdentity("Microsoft.CodeAnalysis.CSharp", codeAnalysisTestVersion)));

ReferenceAssembliesNet60 =
new ReferenceAssemblies(
"net6.0",
new PackageIdentity(
"Microsoft.NETCore.App.Ref",
"6.0.0"),
Path.Combine("ref", "net6.0"))
.AddPackages(ImmutableArray.Create(
new PackageIdentity("Microsoft.CodeAnalysis.CSharp", codeAnalysisTestVersion)));
ReferenceAssembliesNet60 = ReferenceAssemblies.Net.Net60.AddPackages(ImmutableArray.Create(
new PackageIdentity("Microsoft.CodeAnalysis.CSharp", codeAnalysisTestVersion)));

ReferenceAssembliesNet70 = ReferenceAssemblies.Net.Net70.AddPackages(ImmutableArray.Create(
new PackageIdentity("Microsoft.CodeAnalysis.CSharp", codeAnalysisTestVersion)));

ExportProviderFactory = new Lazy<IExportProviderFactory>(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ internal static ModifierType GetModifierType(SyntaxToken modifier)
case SyntaxKind.AsyncKeyword:
case SyntaxKind.PartialKeyword:
case SyntaxKind.RefKeyword:
case SyntaxKindEx.RequiredKeyword:
result = ModifierType.Other;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static class SyntaxKindEx
public const SyntaxKind NotKeyword = (SyntaxKind)8440;
public const SyntaxKind ManagedKeyword = (SyntaxKind)8445;
public const SyntaxKind UnmanagedKeyword = (SyntaxKind)8446;
public const SyntaxKind RequiredKeyword = (SyntaxKind)8447;
public const SyntaxKind FileKeyword = (SyntaxKind)8449;
public const SyntaxKind NullableKeyword = (SyntaxKind)8486;
public const SyntaxKind EnableKeyword = (SyntaxKind)8487;
Expand Down