@@ -326,6 +326,26 @@ private static string FormatDiagnostics(ImmutableArray<DiagnosticAnalyzer> analy
326326 return builder . ToString ( ) ;
327327 }
328328
329+ private static bool IsSubjectToExclusion ( DiagnosticResult result )
330+ {
331+ if ( result . Id . StartsWith ( "CS" , StringComparison . Ordinal ) )
332+ {
333+ return false ;
334+ }
335+
336+ if ( result . Id . StartsWith ( "AD" , StringComparison . Ordinal ) )
337+ {
338+ return false ;
339+ }
340+
341+ if ( result . Locations . Length == 0 )
342+ {
343+ return false ;
344+ }
345+
346+ return true ;
347+ }
348+
329349 /// <summary>
330350 /// General method that gets a collection of actual <see cref="Diagnostic"/>s found in the source after the
331351 /// analyzer is run, then verifies each of them.
@@ -346,12 +366,13 @@ private async Task VerifyDiagnosticsAsync(string[] sources, string language, Imm
346366 if ( filenames == null )
347367 {
348368 // Also check if the analyzer honors exclusions
349- if ( expected . Any ( x => x . Id . StartsWith ( "SA" , StringComparison . Ordinal ) || x . Id . StartsWith ( "SX" , StringComparison . Ordinal ) ) )
369+ if ( expected . Any ( IsSubjectToExclusion ) )
350370 {
351- // We want to look at non-stylecop diagnostics only. We also insert a new line at the beginning
352- // so we have to move all diagnostic location down by one line
371+ // Diagnostics reported by the compiler and analyzer diagnostics which don't have a location will
372+ // still be reported. We also insert a new line at the beginning so we have to move all diagnostic
373+ // locations which have a specific position down by one line.
353374 var expectedResults = expected
354- . Where ( x => ! x . Id . StartsWith ( "SA" , StringComparison . Ordinal ) && ! x . Id . StartsWith ( "SX" , StringComparison . Ordinal ) )
375+ . Where ( x => ! IsSubjectToExclusion ( x ) )
355376 . Select ( x => x . WithLineOffset ( 1 ) )
356377 . ToArray ( ) ;
357378
0 commit comments