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

When reportDiagnostic is Default return descriptor default severity #1411

Merged
merged 1 commit into from
Feb 23, 2024
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 @@ -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

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