Skip to content

Commit e65f52d

Browse files
committed
Update SA1500 for property initializer
1 parent 0d3e41c commit e65f52d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp14/LayoutRules/SA1500CSharp14UnitTests.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.SA1500BracesForMultiLineStatementsMustNotShareLine,
13+
StyleCop.Analyzers.LayoutRules.SA1500CodeFixProvider>;
714

815
public partial class SA1500CSharp14UnitTests : SA1500CSharp13UnitTests
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 SA1500 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/SA1500BracesForMultiLineStatementsMustNotShareLine.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ private static void CheckBraceToken(SyntaxNodeAnalysisContext context, StyleCopS
300300
case SyntaxKind.CommaToken:
301301
case SyntaxKind.SemicolonToken:
302302
case SyntaxKind.DotToken:
303+
case SyntaxKind.EqualsToken:
303304
// these are allowed to appear on the same line
304305
return;
305306

0 commit comments

Comments
 (0)