From 7b45efdbbdb4dcd83675cbae0ad09657c7f24a1d Mon Sep 17 00:00:00 2001 From: Jakub Sliwinski Date: Thu, 22 Feb 2024 11:01:22 +0100 Subject: [PATCH] When reportDiagnostic is Default return descriptor default serverity --- ChangeLog.md | 1 + src/Core/Extensions/DiagnosticsExtensions.cs | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index c9d4d5c3ba..2b7bd9b7e7 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix analyzer [RCS1267](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1267) ([PR](https://github.com/dotnet/roslynator/pull/1412)) +- Fix "Unknown value 'Default'" exception ([PR](https://github.com/dotnet/roslynator/pull/1411)) ## [4.11.0] - 2024-02-19 diff --git a/src/Core/Extensions/DiagnosticsExtensions.cs b/src/Core/Extensions/DiagnosticsExtensions.cs index ff24ef1a60..8b57198b9e 100644 --- a/src/Core/Extensions/DiagnosticsExtensions.cs +++ b/src/Core/Extensions/DiagnosticsExtensions.cs @@ -484,14 +484,14 @@ internal static ReportDiagnostic GetEffectiveSeverity( if (syntaxTree is not null && provider?.TryGetDiagnosticValue(syntaxTree, descriptor.Id, cancellationToken, out ReportDiagnostic treeReportDiagnostic) == true) { - return treeReportDiagnostic; + return ReportDiagnosticOrDescriptorDefaultSeverity(treeReportDiagnostic, descriptor); } if (compilationOptions.SpecificDiagnosticOptions.TryGetValue(descriptor.Id, out ReportDiagnostic reportDiagnostic)) - return reportDiagnostic; + return ReportDiagnosticOrDescriptorDefaultSeverity(reportDiagnostic, descriptor); if (provider?.TryGetGlobalDiagnosticValue(descriptor.Id, cancellationToken, out ReportDiagnostic globalReportDiagnostic) == true) - return globalReportDiagnostic; + return ReportDiagnosticOrDescriptorDefaultSeverity(globalReportDiagnostic, descriptor); } return (descriptor.IsEnabledByDefault) @@ -513,4 +513,11 @@ internal static bool IsEffective(this DiagnosticDescriptor descriptor, Compilati _ => true, }; } + + private static ReportDiagnostic ReportDiagnosticOrDescriptorDefaultSeverity(ReportDiagnostic reportDiagnostic, DiagnosticDescriptor descriptor) + { + return (reportDiagnostic == Microsoft.CodeAnalysis.ReportDiagnostic.Default) + ? descriptor.DefaultSeverity.ToReportDiagnostic() + : reportDiagnostic; + } }