Skip to content

Commit

Permalink
HACK: combine style and analyzer passes
Browse files Browse the repository at this point in the history
  • Loading branch information
corngood committed Nov 23, 2023
1 parent 8f3e8a0 commit 89fff84
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 15 deletions.
18 changes: 9 additions & 9 deletions src/Analyzers/AnalyzerFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ namespace Microsoft.CodeAnalysis.Tools.Analyzers
{
internal class AnalyzerFormatter : ICodeFormatter
{
public static AnalyzerFormatter CodeStyleFormatter => new AnalyzerFormatter(
Resources.Code_Style,
FixCategory.CodeStyle,
includeCompilerDiagnostics: false,
new CodeStyleInformationProvider(),
new AnalyzerRunner(),
new SolutionCodeFixApplier());

public static AnalyzerFormatter ThirdPartyFormatter => new AnalyzerFormatter(
// public static ICodeFormatter CodeStyleFormatter => new AnalyzerFormatter(
// Resources.Code_Style,
// FixCategory.CodeStyle,
// includeCompilerDiagnostics: false,
// new CodeStyleInformationProvider(),
// new AnalyzerRunner(),
// new SolutionCodeFixApplier());

public static ICodeFormatter Default => new AnalyzerFormatter(
Resources.Analyzer_Reference,
FixCategory.Analyzers,
includeCompilerDiagnostics: true,
Expand Down
14 changes: 13 additions & 1 deletion src/Analyzers/AnalyzerReferenceInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ public ImmutableDictionary<ProjectId, AnalyzersAndFixers> GetAnalyzersAndFixers(
FormatOptions formatOptions,
ILogger logger)
{
return solution.Projects
var output = solution.Projects
.ToImmutableDictionary(project => project.Id, GetAnalyzersAndFixers);

var style = new CodeStyleInformationProvider().GetAnalyzersAndFixers(solution, formatOptions, logger);

return output
.Concat(style)
.GroupBy(x => x.Key, x => x.Value)
.ToDictionary(
x => x.Key,
x => new AnalyzersAndFixers(
x.SelectMany(x => x.Analyzers).ToImmutableArray(),
x.SelectMany(x => x.Fixers).ToImmutableArray()))
.ToImmutableDictionary();
}

private AnalyzersAndFixers GetAnalyzersAndFixers(Project project)
Expand Down
3 changes: 1 addition & 2 deletions src/CodeFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ internal static class CodeFormatter
new EndOfLineFormatter(),
new CharsetFormatter(),
new OrganizeImportsFormatter(),
AnalyzerFormatter.CodeStyleFormatter,
AnalyzerFormatter.ThirdPartyFormatter);
AnalyzerFormatter.Default);

public static async Task<WorkspaceFormatResult> FormatWorkspaceAsync(
FormatOptions formatOptions,
Expand Down
2 changes: 1 addition & 1 deletion tests/Analyzers/CodeStyleAnalyzerFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.CodeAnalysis.Tools.Tests.Analyzers
{
public class CodeStyleAnalyzerFormatterTests : CSharpFormatterTests
{
private protected override ICodeFormatter Formatter => AnalyzerFormatter.CodeStyleFormatter;
private protected override ICodeFormatter Formatter => AnalyzerFormatter.Default;

public CodeStyleAnalyzerFormatterTests(ITestOutputHelper output)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Analyzers/ThirdPartyAnalyzerFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ThirdPartyAnalyzerFormatterTests : CSharpFormatterTests, IAsyncLife
{
private static readonly string s_analyzerProjectFilePath = Path.Combine("for_analyzer_formatter", "analyzer_project", "analyzer_project.csproj");

private protected override ICodeFormatter Formatter => AnalyzerFormatter.ThirdPartyFormatter;
private protected override ICodeFormatter Formatter => AnalyzerFormatter.Default;

private Project _analyzerReferencesProject;

Expand Down
2 changes: 1 addition & 1 deletion tests/Formatters/UnnecessaryImportsFormatterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class UnnecessaryImportsFormatterTests : CSharpFormatterTests
private const string RemoveUnnecessaryImportCategoryKey =
AnalyzerOptionsExtensions.DotnetAnalyzerDiagnosticPrefix + "." + AnalyzerOptionsExtensions.CategoryPrefix + "-" + Style + "." + AnalyzerOptionsExtensions.SeveritySuffix;

private protected override ICodeFormatter Formatter => AnalyzerFormatter.CodeStyleFormatter;
private protected override ICodeFormatter Formatter => AnalyzerFormatter.Default;

public UnnecessaryImportsFormatterTests(ITestOutputHelper output)
{
Expand Down

0 comments on commit 89fff84

Please sign in to comment.