Skip to content

Commit

Permalink
File specific configuration should be respected over global configura…
Browse files Browse the repository at this point in the history
…tion. (dotnet#1066)

Co-authored-by: Josef Pihrt <[email protected]>
  • Loading branch information
2 people authored and JochemHarmes committed Oct 30, 2023
1 parent d181dfe commit 7837ef1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 10 additions & 16 deletions src/Core/Extensions/DiagnosticsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 7837ef1

Please sign in to comment.