Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SA1513 to not require a blank line if the closing brace is at the end of a collection expression #3746

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,34 @@

namespace StyleCop.Analyzers.Test.CSharp12.LayoutRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp11.LayoutRules;
using Xunit;

using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1513CodeFixProvider>;

public partial class SA1513CSharp12UnitTests : SA1513CSharp11UnitTests
{
[Fact]
[WorkItem(3720, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3720")]
public async Task TestObjectInitializerInCollectionExpressionAsync()
{
var testCode = @"
public class Foo
{
public Foo[] TestMethod() =>
[
new Foo
{
}
];
}";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ private void AnalyzeCloseBrace(SyntaxToken token)
return;
}

if (nextToken.IsKind(SyntaxKind.CloseBracketToken))
{
// the close brace is for example in an object initializer at the end of a collection expression.
return;
}

if (nextToken.IsKind(SyntaxKind.AddKeyword)
|| nextToken.IsKind(SyntaxKind.RemoveKeyword)
|| nextToken.IsKind(SyntaxKind.GetKeyword)
Expand Down
Loading