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

Allow object initializers and switch expressions in throw statements #3418

Merged
merged 1 commit into from
Dec 8, 2021
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,37 @@

namespace StyleCop.Analyzers.Test.CSharp9.LayoutRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp8.LayoutRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.LayoutRules.SA1513ClosingBraceMustBeFollowedByBlankLine,
StyleCop.Analyzers.LayoutRules.SA1513CodeFixProvider>;

public class SA1513CSharp9UnitTests : SA1513CSharp8UnitTests
{
[Fact]
[WorkItem(3410, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3410")]
public async Task TestThrowSwitchExpressionValueAsync()
{
var testCode = @"using System;

public class Foo
{
public void Baz(string arg)
{
throw arg switch
{
"""" => new ArgumentException(),
_ => new Exception()
};
}
}
";

await VerifyCSharpFixAsync(testCode, DiagnosticResult.EmptyDiagnosticResults, testCode, CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,10 @@ private void AnalyzeCloseBrace(SyntaxToken token)
IsPartOf<EqualsValueClauseSyntax>(token) ||
IsPartOf<AssignmentExpressionSyntax>(token) ||
IsPartOf<ReturnStatementSyntax>(token) ||
IsPartOf<ThrowStatementSyntax>(token) ||
IsPartOf<ObjectCreationExpressionSyntax>(token)))
{
// the close brace is part of a variable initialization statement or a return statement
// the close brace is part of a variable initialization statement or a return/throw statement
return;
}

Expand Down