Skip to content

Commit

Permalink
When reportDiagnostic is Default return descriptor default severity (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jsliwinski committed Feb 23, 2024
1 parent 243c71c commit 32a2e9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions ChangeLog.md
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
Expand Up @@ -484,14 +484,14 @@ internal static bool IsEffective(this DiagnosticDescriptor descriptor, SyntaxNod
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;
}
}

0 comments on commit 32a2e9c

Please sign in to comment.