@@ -102,7 +102,9 @@ private static async Task MainAsync(string[] args, CancellationToken cancellatio
102102
103103 stopwatch . Restart ( ) ;
104104
105- var diagnostics = await GetAnalyzerDiagnosticsAsync ( solution , solutionPath , analyzers , cancellationToken ) . ConfigureAwait ( true ) ;
105+ bool force = args . Contains ( "/force" ) ;
106+
107+ var diagnostics = await GetAnalyzerDiagnosticsAsync ( solution , solutionPath , analyzers , force , cancellationToken ) . ConfigureAwait ( true ) ;
106108 var allDiagnostics = diagnostics . SelectMany ( i => i . Value ) . ToImmutableArray ( ) ;
107109
108110 Console . WriteLine ( $ "Found { allDiagnostics . Length } diagnostics in { stopwatch . ElapsedMilliseconds } ms") ;
@@ -384,7 +386,7 @@ private static ImmutableDictionary<FixAllProvider, ImmutableHashSet<string>> Get
384386 return fixAllProviders . ToImmutableDictionary ( ) ;
385387 }
386388
387- private static async Task < ImmutableDictionary < ProjectId , ImmutableArray < Diagnostic > > > GetAnalyzerDiagnosticsAsync ( Solution solution , string solutionPath , ImmutableArray < DiagnosticAnalyzer > analyzers , CancellationToken cancellationToken )
389+ private static async Task < ImmutableDictionary < ProjectId , ImmutableArray < Diagnostic > > > GetAnalyzerDiagnosticsAsync ( Solution solution , string solutionPath , ImmutableArray < DiagnosticAnalyzer > analyzers , bool force , CancellationToken cancellationToken )
388390 {
389391 List < KeyValuePair < ProjectId , Task < ImmutableArray < Diagnostic > > > > projectDiagnosticTasks = new List < KeyValuePair < ProjectId , Task < ImmutableArray < Diagnostic > > > > ( ) ;
390392
@@ -396,7 +398,7 @@ private static async Task<ImmutableDictionary<ProjectId, ImmutableArray<Diagnost
396398 continue ;
397399 }
398400
399- projectDiagnosticTasks . Add ( new KeyValuePair < ProjectId , Task < ImmutableArray < Diagnostic > > > ( project . Id , GetProjectAnalyzerDiagnosticsAsync ( analyzers , project , cancellationToken ) ) ) ;
401+ projectDiagnosticTasks . Add ( new KeyValuePair < ProjectId , Task < ImmutableArray < Diagnostic > > > ( project . Id , GetProjectAnalyzerDiagnosticsAsync ( analyzers , project , force , cancellationToken ) ) ) ;
400402 }
401403
402404 ImmutableDictionary < ProjectId , ImmutableArray < Diagnostic > > . Builder projectDiagnosticBuilder = ImmutableDictionary . CreateBuilder < ProjectId , ImmutableArray < Diagnostic > > ( ) ;
@@ -413,17 +415,22 @@ private static async Task<ImmutableDictionary<ProjectId, ImmutableArray<Diagnost
413415 /// </summary>
414416 /// <param name="analyzers">The list of analyzers that should be used</param>
415417 /// <param name="project">The project that should be analyzed</param>
418+ /// <param name="force"><see langword="true"/> to force the analyzers to be enabled; otherwise,
419+ /// <see langword="false"/> to use the behavior configured for the specified <paramref name="project"/>.</param>
416420 /// <param name="cancellationToken">The cancellation token that the task will observe.</param>
417421 /// <returns>A list of diagnostics inside the project</returns>
418- private static async Task < ImmutableArray < Diagnostic > > GetProjectAnalyzerDiagnosticsAsync ( ImmutableArray < DiagnosticAnalyzer > analyzers , Project project , CancellationToken cancellationToken )
422+ private static async Task < ImmutableArray < Diagnostic > > GetProjectAnalyzerDiagnosticsAsync ( ImmutableArray < DiagnosticAnalyzer > analyzers , Project project , bool force , CancellationToken cancellationToken )
419423 {
420424 var supportedDiagnosticsSpecificOptions = new Dictionary < string , ReportDiagnostic > ( ) ;
421- foreach ( var analyzer in analyzers )
425+ if ( force )
422426 {
423- foreach ( var diagnostic in analyzer . SupportedDiagnostics )
427+ foreach ( var analyzer in analyzers )
424428 {
425- // make sure the analyzers we are testing are enabled
426- supportedDiagnosticsSpecificOptions [ diagnostic . Id ] = ReportDiagnostic . Default ;
429+ foreach ( var diagnostic in analyzer . SupportedDiagnostics )
430+ {
431+ // make sure the analyzers we are testing are enabled
432+ supportedDiagnosticsSpecificOptions [ diagnostic . Id ] = ReportDiagnostic . Default ;
433+ }
427434 }
428435 }
429436
@@ -451,6 +458,7 @@ private static void PrintHelp()
451458 Console . WriteLine ( "/codefixes Test single code fixes" ) ;
452459 Console . WriteLine ( "/fixall Test fix all providers" ) ;
453460 Console . WriteLine ( "/id:<id> Enable analyzer with diagnostic ID < id > (when this is specified, only this analyzer is enabled)" ) ;
461+ Console . WriteLine ( "/force Force an analyzer to be enabled, regardless of the configured rule set(s) for the solution" ) ;
454462 }
455463 }
456464}
0 commit comments