Skip to content

Commit

Permalink
Update SA1137 to also consider init accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
bjornhellander committed Jun 17, 2023
1 parent b80f0c2 commit 70abd32
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.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 { }
";

var test = new CSharpTest
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net50,
TestCode = testCode,
FixedCode = fixedCode,
};
await test.RunAsync().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 70abd32

Please sign in to comment.