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 SA1011 to forbid trailing space before the end of a switch case #3674

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,55 @@

namespace StyleCop.Analyzers.Test.CSharp11.SpacingRules
{
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Testing;
using StyleCop.Analyzers.Test.CSharp10.SpacingRules;
using Xunit;
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
StyleCop.Analyzers.SpacingRules.SA1011ClosingSquareBracketsMustBeSpacedCorrectly,
StyleCop.Analyzers.SpacingRules.TokenSpacingCodeFixProvider>;

public class SA1011CSharp11UnitTests : SA1011CSharp10UnitTests
{
[Fact]
[WorkItem(3673, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3673")]
public async Task TestListPatternInSwitchCaseAsync()
{
var testCode = @"public class TestClass
{
public void TestMethod(object[] arg)
{
switch (arg)
{
case [string s{|#0:]|} :
break;
}
}}
";

var fixedCode = @"public class TestClass
{
public void TestMethod(object[] arg)
{
switch (arg)
{
case [string s]:
break;
}
}}
";

await new CSharpTest
{
ReferenceAssemblies = ReferenceAssemblies.Net.Net70,
TestCode = testCode,
ExpectedDiagnostics =
{
Diagnostic().WithLocation(0).WithArguments(" not", "followed"),
},
FixedCode = fixedCode,
}.RunAsync(CancellationToken.None).ConfigureAwait(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private static void HandleCloseBracketToken(SyntaxTreeAnalysisContext context, S
break;

case SyntaxKind.ColonToken:
precedesSpecialCharacter = nextToken.Parent.IsKind(SyntaxKind.InterpolationFormatClause);
precedesSpecialCharacter =
nextToken.Parent.IsKind(SyntaxKind.InterpolationFormatClause) ||
nextToken.Parent.IsKind(SyntaxKindEx.CasePatternSwitchLabel);
suppressFollowingSpaceError = false;
break;

Expand Down