Skip to content

Commit 158c480

Browse files
committed
Fix StyleCopTester not running disabled rules even with /id
1 parent 310bb4e commit 158c480

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

StyleCop.Analyzers/StyleCopTester/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private static async Task MainAsync(string[] args, CancellationToken cancellatio
7777

7878
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
7979
string solutionPath = args.SingleOrDefault(i => !i.StartsWith("/", StringComparison.Ordinal));
80-
Solution solution = workspace.OpenSolutionAsync(solutionPath, cancellationToken).Result;
80+
Solution solution = await workspace.OpenSolutionAsync(solutionPath, cancellationToken).ConfigureAwait(false);
8181

8282
Console.WriteLine($"Loaded solution in {stopwatch.ElapsedMilliseconds}ms");
8383

@@ -373,7 +373,22 @@ private static async Task<ImmutableDictionary<ProjectId, ImmutableArray<Diagnost
373373
/// <returns>A list of diagnostics inside the project</returns>
374374
private static async Task<ImmutableArray<Diagnostic>> GetProjectAnalyzerDiagnosticsAsync(ImmutableArray<DiagnosticAnalyzer> analyzers, Project project, CancellationToken cancellationToken)
375375
{
376-
Compilation compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
376+
var supportedDiagnosticsSpecificOptions = new Dictionary<string, ReportDiagnostic>();
377+
foreach (var analyzer in analyzers)
378+
{
379+
foreach (var diagnostic in analyzer.SupportedDiagnostics)
380+
{
381+
// make sure the analyzers we are testing are enabled
382+
supportedDiagnosticsSpecificOptions[diagnostic.Id] = ReportDiagnostic.Default;
383+
}
384+
}
385+
386+
// update the project compilation options
387+
var modifiedSpecificDiagnosticOptions = supportedDiagnosticsSpecificOptions.ToImmutableDictionary().SetItems(project.CompilationOptions.SpecificDiagnosticOptions);
388+
var modifiedCompilationOptions = project.CompilationOptions.WithSpecificDiagnosticOptions(modifiedSpecificDiagnosticOptions);
389+
var processedProject = project.WithCompilationOptions(modifiedCompilationOptions);
390+
391+
Compilation compilation = await processedProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
377392
CompilationWithAnalyzers compilationWithAnalyzers = compilation.WithAnalyzers(analyzers, cancellationToken: cancellationToken);
378393

379394
var allDiagnostics = await compilationWithAnalyzers.GetAllDiagnosticsAsync().ConfigureAwait(false);

0 commit comments

Comments
 (0)