Skip to content

Commit bfd1498

Browse files
Update SA1513 to not require a blank line if the closing brace is at the end of a collection expression
#3720
1 parent f21721e commit bfd1498

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp12/LayoutRules/SA1513CSharp12UnitTests.cs

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

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

816
public partial class SA1513CSharp12UnitTests : SA1513CSharp11UnitTests
917
{
18+
[Fact]
19+
[WorkItem(3720, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3720")]
20+
public async Task TestObjectInitializerInCollectionExpressionAsync()
21+
{
22+
var testCode = @"
23+
public class Foo
24+
{
25+
public Foo[] TestMethod() =>
26+
[
27+
new Foo
28+
{
29+
}
30+
];
31+
}";
32+
33+
await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
34+
}
1035
}
1136
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ private void AnalyzeCloseBrace(SyntaxToken token)
272272
return;
273273
}
274274

275+
if (nextToken.IsKind(SyntaxKind.CloseBracketToken))
276+
{
277+
// the close brace is for example in an object initializer at the end of a collection expression.
278+
return;
279+
}
280+
275281
if (nextToken.IsKind(SyntaxKind.AddKeyword)
276282
|| nextToken.IsKind(SyntaxKind.RemoveKeyword)
277283
|| nextToken.IsKind(SyntaxKind.GetKeyword)

0 commit comments

Comments
 (0)