Skip to content

Commit

Permalink
AnalyzerFormatter: add support for DiagnosticSuppressor
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood committed Nov 23, 2023
1 parent 89fff84 commit fa99c15
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Analyzers/AnalyzerFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,17 @@ static bool ContainsFixableId(CodeFixProvider fixer, string id)

// Filter analyzers by project's language
var filteredAnalyzer = projectAnalyzersAndFixers[projectId].Analyzers
.Where(analyzer => DoesAnalyzerSupportLanguage(analyzer, project.Language));
.Where(analyzer => DoesAnalyzerSupportLanguage(analyzer, project.Language))
.ToImmutableArray();

foreach (var analyzer in filteredAnalyzer)
{
// We'll deal with these after we have a list of diagnostics
if (analyzer is DiagnosticSuppressor)
{
continue;
}

// Filter by excluded diagnostics
if (!excludeDiagnostics.IsEmpty &&
analyzer.SupportedDiagnostics.All(descriptor => excludeDiagnostics.Contains(descriptor.Id)))
Expand Down Expand Up @@ -340,6 +348,21 @@ static bool ContainsFixableId(CodeFixProvider fixer, string id)
}
}

var analyzerDiagnostics = analyzers
.SelectMany(analyzer => analyzer.SupportedDiagnostics)
.Select(descriptor => descriptor.Id)
.ToImmutableHashSet();

foreach (var analyzer in filteredAnalyzer)
{
if (analyzer is DiagnosticSuppressor suppressor &&
suppressor.SupportedSuppressions.Any(
descriptor => analyzerDiagnostics.Contains(descriptor.SuppressedDiagnosticId)))
{
analyzers.Add(analyzer);
}
}

projectAnalyzers.Add(projectId, analyzers.ToImmutableArray());
}

Expand Down

0 comments on commit fa99c15

Please sign in to comment.