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

Fix AD0001 for IDE0076 #45613

Merged
1 commit merged into from
Jul 2, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#nullable enable

using System.Threading.Tasks;
using Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
Expand Down Expand Up @@ -182,5 +183,23 @@ public void M() {{ }}
}}";
await VerifyCS.VerifyCodeFixAsync(input, input);
}

[Fact, WorkItem(45465, "https://github.com/dotnet/roslyn/issues/45465")]
public async Task LegacyModeGlobalSuppressionWithNamespaceAndDescendantsScope()
{
var target = "N:N.InvalidChild";
var input = $@"
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(""Category"", ""Id: Title"", Scope = ""namespaceanddescendants"", Target = {{|#0:""{target}""|}})]

namespace N
{{
class C {{ }}
}}";
var expectedDiagnostic = VerifyCS.Diagnostic(AbstractRemoveUnnecessaryAttributeSuppressionsDiagnosticAnalyzer.LegacyFormatTargetDescriptor)
.WithLocation(0)
.WithArguments(target);

await VerifyCS.VerifyCodeFixAsync(input, expectedDiagnostic, input);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public bool HasValidTarget(
// Compilation wide suppression with a non-null target is considered invalid.
return targetSymbolString == null;
}
else if (targetScope == TargetScope.NamespaceAndDescendants)
{
// TargetSymbolResolver expects the callers to normalize 'NamespaceAndDescendants' and 'Namespace' scopes to 'Namespace' scope.
targetScope = TargetScope.Namespace;
}

var resolver = new TargetSymbolResolver(_compilation, targetScope, targetSymbolString);
resolvedSymbols = resolver.Resolve(out targetHasDocCommentIdFormat);
Expand Down