Skip to content

Commit

Permalink
Merge pull request #3669 from bjornhellander/feature/sa1137-init-acce…
Browse files Browse the repository at this point in the history
…ssor

Update SA1137 to also consider init accessors
  • Loading branch information
sharwell authored Jun 21, 2023
2 parents e2f3451 + 89174f9 commit b690c22
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,61 @@

namespace StyleCop.Analyzers.Test.CSharp9.ReadabilityRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.ReadabilityRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.ReadabilityRules.SA1137ElementsShouldHaveTheSameIndentation,
StyleCop.Analyzers.ReadabilityRules.IndentationCodeFixProvider>;

public class SA1137CSharp9UnitTests : SA1137CSharp8UnitTests
{
[Fact]
[WorkItem(3668, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3668")]
public async Task TestInitAccessorAttributeListAsync()
{
string testCode = @"
using System;
class TestClass
{
int Property
{
[My]
[| |][My]
init { }
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
class MyAttribute : Attribute { }
";

string fixedCode = @"
using System;
class TestClass
{
int Property
{
[My]
[My]
init { }
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true)]
class MyAttribute : Attribute { }
";

await new CSharpTest
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
TestCode = testCode,
FixedCode = fixedCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ internal static class SyntaxKindEx
public const SyntaxKind NullableDirectiveTrivia = (SyntaxKind)9055;
public const SyntaxKind FunctionPointerType = (SyntaxKind)9056;
public const SyntaxKind FunctionPointerParameter = (SyntaxKind)9057;
public const SyntaxKind InitAccessorDeclaration = (SyntaxKind)9060;
public const SyntaxKind WithExpression = (SyntaxKind)9061;
public const SyntaxKind WithInitializerExpression = (SyntaxKind)9062;
public const SyntaxKind RecordDeclaration = (SyntaxKind)9063;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ private static void AddMemberAndAttributes(ImmutableList<SyntaxNode>.Builder ele

case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.SetAccessorDeclaration:
case SyntaxKindEx.InitAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration:
case SyntaxKind.UnknownAccessorDeclaration:
Expand Down

0 comments on commit b690c22

Please sign in to comment.