Skip to content

Commit

Permalink
Promote UNT0033, UNT0015 and UNT0006 from Info to Warning s…
Browse files Browse the repository at this point in the history
…everity. (#253)

* Promote `UNT0033`, `UNT0015` and `UNT0006` from Info to Warning diagnostics.

* Fix our diagnostic verifier to properly handle severity
  • Loading branch information
sailro authored Nov 23, 2022
1 parent aee89c2 commit 7a68fa6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected async Task<Diagnostic[]> GetSortedDiagnosticsFromDocumentsAsync(Analyz

// Force all tested and related diagnostics to be enabled
foreach (var descriptor in analyzers.SelectMany(a => a.SupportedDiagnostics))
specificDiagnosticOptions = specificDiagnosticOptions.SetItem(descriptor.Id, ReportDiagnostic.Info);
specificDiagnosticOptions = specificDiagnosticOptions.SetItem(descriptor.Id, GetReportDiagnostic(descriptor));

var compilationWithAnalyzers = compilation
.WithOptions(compilationOptions.WithSpecificDiagnosticOptions(specificDiagnosticOptions))
Expand Down Expand Up @@ -283,6 +283,17 @@ protected async Task<Diagnostic[]> GetSortedDiagnosticsFromDocumentsAsync(Analyz
return results;
}

private static ReportDiagnostic GetReportDiagnostic(DiagnosticDescriptor descriptor)
{
return descriptor.DefaultSeverity switch
{
DiagnosticSeverity.Error => ReportDiagnostic.Error,
DiagnosticSeverity.Warning => ReportDiagnostic.Warn,
DiagnosticSeverity.Info or DiagnosticSeverity.Hidden => ReportDiagnostic.Info,
_ => throw new ArgumentOutOfRangeException()
};
}

protected static Diagnostic[] FilterDiagnostics(IEnumerable<Diagnostic> diagnostics, ImmutableArray<string> filters)
{
return diagnostics
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Unity.Analyzers/ImproperMessageCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ImproperMessageCaseAnalyzer : DiagnosticAnalyzer
title: Strings.ImproperMessageCaseDiagnosticTitle,
messageFormat: Strings.ImproperMessageCaseDiagnosticMessageFormat,
category: DiagnosticCategory.Correctness,
defaultSeverity: DiagnosticSeverity.Info,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: Strings.ImproperMessageCaseDiagnosticDescription);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Unity.Analyzers/LoadAttributeMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class LoadAttributeMethodAnalyzer : DiagnosticAnalyzer
title: Strings.LoadAttributeMethodDiagnosticTitle,
messageFormat: Strings.LoadAttributeMethodDiagnosticMessageFormat,
category: DiagnosticCategory.TypeSafety,
defaultSeverity: DiagnosticSeverity.Info,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: Strings.LoadAttributeMethodDiagnosticDescription);

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Unity.Analyzers/MessageSignature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MessageSignatureAnalyzer : DiagnosticAnalyzer
title: Strings.MessageSignatureDiagnosticTitle,
messageFormat: Strings.MessageSignatureDiagnosticMessageFormat,
category: DiagnosticCategory.TypeSafety,
defaultSeverity: DiagnosticSeverity.Info,
defaultSeverity: DiagnosticSeverity.Warning,
isEnabledByDefault: true,
description: Strings.MessageSignatureDiagnosticDescription);

Expand Down

0 comments on commit 7a68fa6

Please sign in to comment.