Skip to content

Commit 33b4bca

Browse files
Merge 17b8bd6 into b80f0c2
2 parents b80f0c2 + 17b8bd6 commit 33b4bca

File tree

4 files changed

+83
-1
lines changed

4 files changed

+83
-1
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1513CSharp9UnitTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
99
using System.Threading.Tasks;
1010
using Microsoft.CodeAnalysis.Testing;
1111
using StyleCop.Analyzers.Test.CSharp8.LayoutRules;
12+
using StyleCop.Analyzers.Test.Verifiers;
1213
using Xunit;
1314
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1415
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
@@ -37,5 +38,34 @@ public void Baz(string arg)
3738

3839
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
3940
}
41+
42+
[Fact]
43+
[WorkItem(3658, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3658")]
44+
public async Task TestInitAccessorAsync()
45+
{
46+
var testCode = @"using System;
47+
48+
public class Foo
49+
{
50+
public int X
51+
{
52+
get
53+
{
54+
return 0;
55+
}
56+
init
57+
{
58+
}
59+
}
60+
}
61+
";
62+
63+
var test = new CSharpTest
64+
{
65+
TestCode = testCode,
66+
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
67+
};
68+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
69+
}
4070
}
4171
}

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp9/LayoutRules/SA1516CSharp9UnitTests.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
1010
using Microsoft.CodeAnalysis;
1111
using Microsoft.CodeAnalysis.Testing;
1212
using StyleCop.Analyzers.Test.CSharp8.LayoutRules;
13+
using StyleCop.Analyzers.Test.Verifiers;
1314
using Xunit;
1415
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
1516
StyleCop.Analyzers.LayoutRules.SA1516ElementsMustBeSeparatedByBlankLine,
@@ -104,6 +105,54 @@ record A();
104105
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
105106
}
106107

108+
[Fact]
109+
[WorkItem(3658, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3658")]
110+
public async Task TestInitAccessorAsync()
111+
{
112+
var testCode = @"using System;
113+
114+
public class Foo
115+
{
116+
public int X
117+
{
118+
get
119+
{
120+
return 0;
121+
}
122+
[| |]init
123+
{
124+
}
125+
}
126+
}
127+
";
128+
129+
var fixedCode = @"using System;
130+
131+
public class Foo
132+
{
133+
public int X
134+
{
135+
get
136+
{
137+
return 0;
138+
}
139+
140+
init
141+
{
142+
}
143+
}
144+
}
145+
";
146+
147+
var test = new CSharpTest
148+
{
149+
TestCode = testCode,
150+
FixedCode = fixedCode,
151+
ReferenceAssemblies = GenericAnalyzerTest.ReferenceAssembliesNet50,
152+
};
153+
await test.RunAsync(CancellationToken.None).ConfigureAwait(false);
154+
}
155+
107156
protected virtual DiagnosticResult[] GetExpectedResultTestUsingAndGlobalStatementSpacingInTopLevelProgram()
108157
{
109158
// NOTE: Seems like a Roslyn bug made diagnostics be reported twice. Fixed in a later version.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace StyleCop.Analyzers.LayoutRules
1515
using Microsoft.CodeAnalysis.Diagnostics;
1616
using Microsoft.CodeAnalysis.Text;
1717
using StyleCop.Analyzers.Helpers;
18+
using StyleCop.Analyzers.Lightup;
1819

1920
/// <summary>
2021
/// A closing brace within a C# element, statement, or expression is not followed by a blank line.
@@ -274,7 +275,8 @@ private void AnalyzeCloseBrace(SyntaxToken token)
274275
if (nextToken.IsKind(SyntaxKind.AddKeyword)
275276
|| nextToken.IsKind(SyntaxKind.RemoveKeyword)
276277
|| nextToken.IsKind(SyntaxKind.GetKeyword)
277-
|| nextToken.IsKind(SyntaxKind.SetKeyword))
278+
|| nextToken.IsKind(SyntaxKind.SetKeyword)
279+
|| nextToken.IsKind(SyntaxKindEx.InitKeyword))
278280
{
279281
// the close brace is followed by an accessor (SA1516 will handle that)
280282
return;

StyleCop.Analyzers/StyleCop.Analyzers/Lightup/SyntaxKindEx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal static class SyntaxKindEx
1212
public const SyntaxKind OrKeyword = (SyntaxKind)8438;
1313
public const SyntaxKind AndKeyword = (SyntaxKind)8439;
1414
public const SyntaxKind NotKeyword = (SyntaxKind)8440;
15+
public const SyntaxKind InitKeyword = (SyntaxKind)8443;
1516
public const SyntaxKind ManagedKeyword = (SyntaxKind)8445;
1617
public const SyntaxKind UnmanagedKeyword = (SyntaxKind)8446;
1718
public const SyntaxKind RequiredKeyword = (SyntaxKind)8447;

0 commit comments

Comments
 (0)