Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File specific configuration should be respected over global configuration. #1066

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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