Skip to content

Commit 9b946ab

Browse files
committed
Update SA1513 for property initializer
1 parent e65f52d commit 9b946ab

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp14/LayoutRules/SA1513CSharp14UnitTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,39 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp14.LayoutRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.CodeAnalysis.Testing;
69
using StyleCop.Analyzers.Test.CSharp13.LayoutRules;
10+
using Xunit;
11+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
12+
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
13+
StyleCop.Analyzers.LayoutRules.SA1513CodeFixProvider>;
714

815
public partial class SA1513CSharp14UnitTests : SA1513CSharp13UnitTests
916
{
17+
/// <summary>
18+
/// Verifies that no diagnostics are reported for the valid properties defined in this test.
19+
/// </summary>
20+
/// <remarks>
21+
/// <para>These are valid for SA1513 only, some will report other diagnostics.</para>
22+
/// </remarks>
23+
/// <returns>A <see cref="Task"/> representing the asynchronous unit test.</returns>
24+
[Fact]
25+
public async Task TestPropertyDefaultValueAssignmentValidAsync()
26+
{
27+
var testCode = @"using System;
28+
29+
public class Foo
30+
{
31+
public bool Property1
32+
{
33+
get { return field; }
34+
set { field = value; }
35+
} = default;
36+
}";
37+
38+
await VerifyCSharpDiagnosticAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
39+
}
1040
}
1141
}

StyleCop.Analyzers/StyleCop.Analyzers/LayoutRules/SA1513ClosingBraceMustBeFollowedByBlankLine.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ private void AnalyzeCloseBrace(SyntaxToken token)
318318
return;
319319
}
320320

321+
if (token.Parent is AccessorListSyntax && nextToken.IsKind(SyntaxKind.EqualsToken))
322+
{
323+
// the close brace is followed by a property initializer
324+
return;
325+
}
326+
321327
if ((nextToken.IsKind(SyntaxKind.PrivateKeyword)
322328
|| nextToken.IsKind(SyntaxKind.ProtectedKeyword)
323329
|| nextToken.IsKind(SyntaxKind.InternalKeyword))

0 commit comments

Comments
 (0)