@@ -11,6 +11,7 @@ namespace StyleCop.Analyzers.SpacingRules
1111 using Microsoft . CodeAnalysis . CSharp ;
1212 using Microsoft . CodeAnalysis . Diagnostics ;
1313 using StyleCop . Analyzers . Helpers ;
14+ using StyleCop . Analyzers . Lightup ;
1415
1516 /// <summary>
1617 /// An opening square bracket within a C# statement is not spaced correctly.
@@ -98,15 +99,16 @@ private static void HandleOpenBracketToken(SyntaxTreeAnalysisContext context, Sy
9899 }
99100 }
100101
101- bool followedBySpace = token . IsFollowedByWhitespace ( ) ;
102- bool lastInLine = token . IsLastInLine ( ) ;
103-
104- if ( ! firstInLine && precededBySpace && ! ignorePrecedingSpaceProblem && ! IsPartOfIndexInitializer ( token ) )
102+ if ( ! firstInLine && precededBySpace && ! ignorePrecedingSpaceProblem &&
103+ ! IsPartOfIndexInitializer ( token ) && ! IsPartOfListPattern ( token ) )
105104 {
106105 // Opening square bracket should {not be preceded} by a space.
107106 context . ReportDiagnostic ( Diagnostic . Create ( DescriptorNotPreceded , token . GetLocation ( ) , TokenSpacingProperties . RemovePreceding ) ) ;
108107 }
109108
109+ bool followedBySpace = token . IsFollowedByWhitespace ( ) ;
110+ bool lastInLine = token . IsLastInLine ( ) ;
111+
110112 if ( ! lastInLine && followedBySpace )
111113 {
112114 // Opening square bracket should {not be followed} by a space.
@@ -121,5 +123,10 @@ private static bool IsPartOfIndexInitializer(SyntaxToken token)
121123 return token . Parent . IsKind ( SyntaxKind . BracketedArgumentList )
122124 && token . Parent . Parent . IsKind ( SyntaxKind . ImplicitElementAccess ) ;
123125 }
126+
127+ private static bool IsPartOfListPattern ( SyntaxToken token )
128+ {
129+ return token . Parent . IsKind ( SyntaxKindEx . ListPattern ) ;
130+ }
124131 }
125132}
0 commit comments