@@ -108,21 +108,18 @@ public override void Initialize(AnalysisContext context)
108
108
private static void HandleSyntaxTree ( SyntaxTreeAnalysisContext context )
109
109
{
110
110
var syntaxRoot = context . Tree . GetRoot ( context . CancellationToken ) ;
111
- var previousCommentNotOnOwnLine = false ;
112
111
113
112
foreach ( var trivia in syntaxRoot . DescendantTrivia ( ) . Where ( trivia => trivia . IsKind ( SyntaxKind . SingleLineCommentTrivia ) ) )
114
113
{
115
114
if ( trivia . FullSpan . Start == 0 )
116
115
{
117
116
// skip the trivia if it is at the start of the file
118
- previousCommentNotOnOwnLine = false ;
119
117
continue ;
120
118
}
121
119
122
120
if ( trivia . ToString ( ) . StartsWith ( "////" , StringComparison . Ordinal ) )
123
121
{
124
122
// ignore commented out code
125
- previousCommentNotOnOwnLine = false ;
126
123
continue ;
127
124
}
128
125
@@ -132,26 +129,21 @@ private static void HandleSyntaxTree(SyntaxTreeAnalysisContext context)
132
129
if ( ! IsOnOwnLine ( triviaList , triviaIndex ) )
133
130
{
134
131
// ignore comments after other code elements.
135
- previousCommentNotOnOwnLine = true ;
136
132
continue ;
137
133
}
138
134
139
135
if ( IsPrecededByBlankLine ( triviaList , triviaIndex ) )
140
136
{
141
137
// allow properly formatted blank line comments.
142
- previousCommentNotOnOwnLine = false ;
143
138
continue ;
144
139
}
145
140
146
- if ( ! previousCommentNotOnOwnLine && IsPrecededBySingleLineCommentOrDocumentation ( triviaList , triviaIndex ) )
141
+ if ( IsPrecededBySingleLineCommentOnOwnLineOrDocumentation ( triviaList , triviaIndex ) )
147
142
{
148
143
// allow consecutive single line comments.
149
- previousCommentNotOnOwnLine = false ;
150
144
continue ;
151
145
}
152
146
153
- previousCommentNotOnOwnLine = false ;
154
-
155
147
if ( IsAtStartOfScope ( trivia ) )
156
148
{
157
149
// allow single line comment at scope start.
@@ -185,7 +177,7 @@ private static bool IsOnOwnLine<T>(T triviaList, int triviaIndex)
185
177
return false ;
186
178
}
187
179
188
- private static bool IsPrecededBySingleLineCommentOrDocumentation < T > ( T triviaList , int triviaIndex )
180
+ private static bool IsPrecededBySingleLineCommentOnOwnLineOrDocumentation < T > ( T triviaList , int triviaIndex )
189
181
where T : IReadOnlyList < SyntaxTrivia >
190
182
{
191
183
var eolCount = 0 ;
@@ -206,6 +198,8 @@ private static bool IsPrecededBySingleLineCommentOrDocumentation<T>(T triviaList
206
198
break ;
207
199
208
200
case SyntaxKind . SingleLineCommentTrivia :
201
+ return IsOnOwnLine ( triviaList , triviaIndex ) ;
202
+
209
203
case SyntaxKind . SingleLineDocumentationCommentTrivia :
210
204
return true ;
211
205
0 commit comments