@@ -125,10 +125,7 @@ private static void HandleSectionOrBlockXmlElement(SyntaxNodeAnalysisContext con
125125
126126 if ( ! string . IsNullOrEmpty ( textWithoutTrailingWhitespace ) )
127127 {
128- if ( ! textWithoutTrailingWhitespace . EndsWith ( "." , StringComparison . Ordinal )
129- && ! textWithoutTrailingWhitespace . EndsWith ( ".)" , StringComparison . Ordinal )
130- && ( startingWithFinalParagraph || ! textWithoutTrailingWhitespace . EndsWith ( ":" , StringComparison . Ordinal ) )
131- && ! textWithoutTrailingWhitespace . EndsWith ( "-or-" , StringComparison . Ordinal ) )
128+ if ( IsMissingRequiredPeriod ( textWithoutTrailingWhitespace , startingWithFinalParagraph ) )
132129 {
133130 int spanStart = textToken . SpanStart + textWithoutTrailingWhitespace . Length ;
134131 ImmutableDictionary < string , string > properties = null ;
@@ -162,10 +159,15 @@ void SetReplaceChar()
162159 }
163160 else if ( xmlElement . Content [ i ] . IsInlineElement ( ) && ! currentParagraphDone )
164161 {
165- // Treat empty XML elements as a "word not ending with a period"
166- var location = Location . Create ( xmlElement . SyntaxTree , new TextSpan ( xmlElement . Content [ i ] . Span . End , 1 ) ) ;
167- context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
168- currentParagraphDone = true ;
162+ var lastTextElement = XmlCommentHelper . TryGetLastTextElementWithContent ( xmlElement . Content [ i ] ) ;
163+
164+ if ( lastTextElement is null // Treat empty XML elements as a "word not ending with a period"
165+ || IsMissingRequiredPeriod ( lastTextElement . TextTokens . Last ( ) . Text . TrimEnd ( ' ' , '\r ' , '\n ' ) , startingWithFinalParagraph ) )
166+ {
167+ var location = Location . Create ( xmlElement . SyntaxTree , new TextSpan ( xmlElement . Content [ i ] . Span . End , 1 ) ) ;
168+ context . ReportDiagnostic ( Diagnostic . Create ( Descriptor , location ) ) ;
169+ currentParagraphDone = true ;
170+ }
169171 }
170172 else if ( xmlElement . Content [ i ] is XmlElementSyntax childXmlElement )
171173 {
@@ -198,5 +200,13 @@ void SetReplaceChar()
198200 }
199201 }
200202 }
203+
204+ private static bool IsMissingRequiredPeriod ( string textWithoutTrailingWhitespace , bool startingWithFinalParagraph )
205+ {
206+ return ! textWithoutTrailingWhitespace . EndsWith ( "." , StringComparison . Ordinal )
207+ && ! textWithoutTrailingWhitespace . EndsWith ( ".)" , StringComparison . Ordinal )
208+ && ( startingWithFinalParagraph || ! textWithoutTrailingWhitespace . EndsWith ( ":" , StringComparison . Ordinal ) )
209+ && ! textWithoutTrailingWhitespace . EndsWith ( "-or-" , StringComparison . Ordinal ) ;
210+ }
201211 }
202212}
0 commit comments