File tree Expand file tree Collapse file tree
StyleCop.Analyzers.Test.CSharp7/LayoutRules
StyleCop.Analyzers/LayoutRules Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33
44namespace StyleCop . Analyzers . Test . CSharp7 . LayoutRules
55{
6+ using System . Threading ;
7+ using System . Threading . Tasks ;
68 using StyleCop . Analyzers . Test . LayoutRules ;
9+ using Xunit ;
710
811 public class SA1515CSharp7UnitTests : SA1515UnitTests
912 {
13+ [ Fact ]
14+ public async Task TestCommentAfterCasePatternSwitchLabelAsync ( )
15+ {
16+ var testCode = @"
17+ public class ClassName
18+ {
19+ public void Method()
20+ {
21+ switch (new object())
22+ {
23+ case int x:
24+ // Single line comment after pattern-matching case statement is valid
25+ break;
26+ }
27+ }
28+ }
29+ " ;
30+
31+ await this . VerifyCSharpDiagnosticAsync ( testCode , EmptyDiagnosticResults , CancellationToken . None ) . ConfigureAwait ( false ) ;
32+ }
1033 }
1134}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ namespace StyleCop.Analyzers.LayoutRules
1212 using Microsoft . CodeAnalysis . Diagnostics ;
1313 using Microsoft . CodeAnalysis . Text ;
1414 using StyleCop . Analyzers . Helpers ;
15+ using StyleCop . Analyzers . Lightup ;
1516
1617 /// <summary>
1718 /// A single-line comment within C# code is not preceded by a blank line.
@@ -259,6 +260,7 @@ private static bool IsAtStartOfScope(SyntaxTrivia trivia)
259260 var prevToken = token . GetPreviousToken ( ) ;
260261 return prevToken . IsKind ( SyntaxKind . OpenBraceToken )
261262 || prevToken . Parent . IsKind ( SyntaxKind . CaseSwitchLabel )
263+ || prevToken . Parent . IsKind ( SyntaxKindEx . CasePatternSwitchLabel )
262264 || prevToken . Parent . IsKind ( SyntaxKind . DefaultSwitchLabel ) ;
263265 }
264266
You can’t perform that action at this time.
0 commit comments