提交 ebca4ff5 编写于 作者: M mavasani

Fix IsDiagnosticAnalyzerSuppressed check for analyzers that have...

Fix IsDiagnosticAnalyzerSuppressed check for analyzers that have NotConfigurable diagnostics which are disabled by default.

Current logic didn't account for the fact that even though these descriptors are non-configurable, they might be turned off by default and hence be suppressed.
上级 9f7f3cbd
......@@ -568,10 +568,11 @@ internal class FullyDisabledAnalyzer : DiagnosticAnalyzer
{
public static DiagnosticDescriptor desc1 = new DiagnosticDescriptor("XX001", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: false);
public static DiagnosticDescriptor desc2 = new DiagnosticDescriptor("XX002", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: false);
public static DiagnosticDescriptor desc3 = new DiagnosticDescriptor("XX003", "DummyDescription", "DummyMessage", "DummyCategory", DiagnosticSeverity.Warning, isEnabledByDefault: false, customTags: WellKnownDiagnosticTags.NotConfigurable);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get { return ImmutableArray.Create(desc1, desc2); }
get { return ImmutableArray.Create(desc1, desc2, desc3); }
}
public override void Initialize(AnalysisContext context)
......@@ -631,6 +632,10 @@ private void TestDisabledAnalyzers()
options = TestOptions.ReleaseDll.WithSpecificDiagnosticOptions(specificDiagOptions);
Assert.False(fullyDisabledAnalyzer.IsDiagnosticAnalyzerSuppressed(options));
Assert.True(partiallyDisabledAnalyzer.IsDiagnosticAnalyzerSuppressed(options));
specificDiagOptions = new Dictionary<string, ReportDiagnostic>();
specificDiagOptions.Add(FullyDisabledAnalyzer.desc3.Id, ReportDiagnostic.Warn);
Assert.False(fullyDisabledAnalyzer.IsDiagnosticAnalyzerSuppressed(options));
}
[Fact, WorkItem(1008059)]
......
......@@ -265,12 +265,6 @@ internal bool IsSupportedDiagnostic(DiagnosticAnalyzer analyzer, Diagnostic diag
foreach (var diag in supportedDiagnostics)
{
if (HasNotConfigurableTag(diag.CustomTags))
{
// If diagnostic descriptor is not configurable, then diagnostics created through it cannot be suppressed.
return false;
}
// Is this diagnostic suppressed by default (as written by the rule author)
var isSuppressed = !diag.IsEnabledByDefault;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册