Skip to content

Commit 513b215

Browse files
committed
Use DiagnosticDescriptor.GetEffectiveSeverity to check for suppressions
Closes #976
1 parent b1a92b6 commit 513b215

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers/Helpers/DiagnosticOptionsHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal static bool IsAnalyzerSuppressed(this Compilation compilation, Diagnost
5656
/// <returns>True if the diagnostic is currently suppressed.</returns>
5757
internal static bool IsAnalyzerSuppressed(this CompilationOptions compilationOptions, DiagnosticDescriptor descriptor)
5858
{
59-
switch (compilationOptions.SpecificDiagnosticOptions.GetValueOrDefault(descriptor.Id))
59+
switch (descriptor.GetEffectiveSeverity(compilationOptions))
6060
{
6161
case ReportDiagnostic.Suppress:
6262
return true;

StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1304NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ internal class SA1304NonPrivateReadonlyFieldsMustBeginWithUpperCaseLetter : Diag
4545

4646
private static readonly Action<SyntaxNodeAnalysisContext> FieldDeclarationAction = HandleFieldDeclaration;
4747

48+
private static readonly DiagnosticDescriptor SA1307Descriptor =
49+
new SA1307AccessibleFieldsMustBeginWithUpperCaseLetter().SupportedDiagnostics.Single();
50+
4851
/// <inheritdoc/>
4952
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } =
5053
ImmutableArray.Create(Descriptor);
@@ -84,8 +87,7 @@ private static void HandleFieldDeclaration(SyntaxNodeAnalysisContext context)
8487
{
8588
// SA1307 is taken precedence here. SA1307 should be reported if the field is accessible.
8689
// So if SA1307 is enabled this diagnostic will only be reported for internal fields.
87-
if (context.SemanticModel.Compilation.Options.SpecificDiagnosticOptions
88-
.GetValueOrDefault(SA1307AccessibleFieldsMustBeginWithUpperCaseLetter.DiagnosticId, ReportDiagnostic.Default) != ReportDiagnostic.Suppress)
90+
if (!context.IsAnalyzerSuppressed(SA1307Descriptor))
8991
{
9092
return;
9193
}

0 commit comments

Comments
 (0)