Skip to content

Commit

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

Update SA1500 to also consider init accessors
  • Loading branch information
sharwell committed Jun 21, 2023
2 parents b690c22 + ba96832 commit c991261
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace StyleCop.Analyzers.LayoutRules
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Text;
using StyleCop.Analyzers.Helpers;
using StyleCop.Analyzers.Lightup;
using StyleCop.Analyzers.Settings.ObjectModel;

/// <summary>
Expand Down Expand Up @@ -165,6 +166,7 @@ private static bool IsAccessorWithSingleLineBlock(SyntaxToken previousToken, Syn
{
case SyntaxKind.GetKeyword:
case SyntaxKind.SetKeyword:
case SyntaxKindEx.InitKeyword:
case SyntaxKind.AddKeyword:
case SyntaxKind.RemoveKeyword:
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,49 @@ public async Task TestMultiLineRecordWithParameterAsync(string keyword)
FixedCode = testCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}

[Fact]
[WorkItem(3667, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3667")]
public async Task TestInitAccessorAsync()
{
var testCode = @"
class TestClass
{
int Property1
{
init
[|{|] }
}
int Property2
{
init [|{|]
}
}
}";

var fixedCode = @"
class TestClass
{
int Property1
{
init { }
}
int Property2
{
init
{
}
}
}";

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 @@ -219,6 +219,7 @@ private static void CheckBraces(SyntaxNodeAnalysisContext context, StyleCopSetti
{
case SyntaxKind.GetAccessorDeclaration:
case SyntaxKind.SetAccessorDeclaration:
case SyntaxKindEx.InitAccessorDeclaration:
case SyntaxKind.AddAccessorDeclaration:
case SyntaxKind.RemoveAccessorDeclaration:
case SyntaxKind.UnknownAccessorDeclaration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal static class SyntaxKindEx
public const SyntaxKind OrKeyword = (SyntaxKind)8438;
public const SyntaxKind AndKeyword = (SyntaxKind)8439;
public const SyntaxKind NotKeyword = (SyntaxKind)8440;
public const SyntaxKind InitKeyword = (SyntaxKind)8443;
public const SyntaxKind ManagedKeyword = (SyntaxKind)8445;
public const SyntaxKind UnmanagedKeyword = (SyntaxKind)8446;
public const SyntaxKind RequiredKeyword = (SyntaxKind)8447;
Expand Down

0 comments on commit c991261

Please sign in to comment.