diff --git a/ChangeLog.md b/ChangeLog.md index 26f4e63410..6171a20476 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix code fix for CS0164 ([#1031](https://github.com/JosefPihrt/Roslynator/pull/1031)). - Do not report `System.Windows.DependencyPropertyChangedEventArgs` as unused parameter ([RCS1163](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1163.md)) ([#1068](https://github.com/JosefPihrt/Roslynator/pull/1068)). - Fix ([RCS1032](https://github.com/JosefPihrt/Roslynator/blob/main/docs/analyzers/RCS1032.md)) ([#1064](https://github.com/JosefPihrt/Roslynator/pull/1064)). +- Update processing of .globalconfig file to prioritize file-specific diagnostic severities over global diagnostic severities. [#1066](https://github.com/JosefPihrt/Roslynator/pull/1066/files) ## [4.2.0] - 2022-11-27 diff --git a/src/Core/Extensions/DiagnosticsExtensions.cs b/src/Core/Extensions/DiagnosticsExtensions.cs index 2809cd6540..51ba37c4d3 100644 --- a/src/Core/Extensions/DiagnosticsExtensions.cs +++ b/src/Core/Extensions/DiagnosticsExtensions.cs @@ -551,15 +551,12 @@ internal static bool IsEffective( CompilationOptions compilationOptions, CancellationToken cancellationToken = default) { - var reportDiagnostic = Microsoft.CodeAnalysis.ReportDiagnostic.Default; - SyntaxTreeOptionsProvider provider = compilationOptions.SyntaxTreeOptionsProvider; - if (provider is not null - && !provider.TryGetGlobalDiagnosticValue(descriptor.Id, cancellationToken, out reportDiagnostic) - && !provider.TryGetDiagnosticValue(syntaxTree, descriptor.Id, cancellationToken, out reportDiagnostic)) + if (provider?.TryGetDiagnosticValue(syntaxTree, descriptor.Id, cancellationToken, out ReportDiagnostic reportDiagnostic) != true + && !compilationOptions.SpecificDiagnosticOptions.TryGetValue(descriptor.Id, out reportDiagnostic)) { - reportDiagnostic = compilationOptions.SpecificDiagnosticOptions.GetValueOrDefault(descriptor.Id); + provider?.TryGetGlobalDiagnosticValue(descriptor.Id, cancellationToken, out reportDiagnostic); } return reportDiagnostic switch @@ -577,19 +574,16 @@ internal static ReportDiagnostic GetEffectiveSeverity( CancellationToken cancellationToken = default) { SyntaxTreeOptionsProvider provider = compilationOptions.SyntaxTreeOptionsProvider; - - if (provider is not null) - { - if (provider.TryGetGlobalDiagnosticValue(descriptor.Id, cancellationToken, out ReportDiagnostic globalReportDiagnostic)) - return globalReportDiagnostic; - - if (provider.TryGetDiagnosticValue(syntaxTree, descriptor.Id, cancellationToken, out ReportDiagnostic treeReportDiagnostic)) - return treeReportDiagnostic; - } - + + if (provider?.TryGetDiagnosticValue(syntaxTree, descriptor.Id, cancellationToken, out ReportDiagnostic treeReportDiagnostic) == true) + return treeReportDiagnostic; + if (compilationOptions.SpecificDiagnosticOptions.TryGetValue(descriptor.Id, out ReportDiagnostic reportDiagnostic)) return reportDiagnostic; + if (provider?.TryGetGlobalDiagnosticValue(descriptor.Id, cancellationToken, out ReportDiagnostic globalReportDiagnostic) == true) + return globalReportDiagnostic; + return (descriptor.IsEnabledByDefault) ? descriptor.DefaultSeverity.ToReportDiagnostic() : Microsoft.CodeAnalysis.ReportDiagnostic.Suppress;