-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44440 from mavasani/RemoveLegacySuppressions
Add analyzer/fixer to convert legacy FxCop format suppressions to Ros…
- Loading branch information
Showing
42 changed files
with
548 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/Analyzers/CSharp/Tests/UpdateLegacySuppressions/UpdateLegacySuppressionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
#nullable enable | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions; | ||
using Microsoft.CodeAnalysis.Test.Utilities; | ||
using Roslyn.Test.Utilities; | ||
using Xunit; | ||
using VerifyCS = Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions.CSharpCodeFixVerifier< | ||
Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessarySuppressionsDiagnosticAnalyzer, | ||
Microsoft.CodeAnalysis.UpdateLegacySuppressions.UpdateLegacySuppressionsCodeFixProvider>; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.UpdateLegacySuppressions | ||
{ | ||
[Trait(Traits.Feature, Traits.Features.CodeActionsUpdateLegacySuppressions)] | ||
[WorkItem(44362, "https://github.com/dotnet/roslyn/issues/44362")] | ||
public class UpdateLegacySuppressionsTests | ||
{ | ||
[Fact] | ||
public void TestStandardProperties() | ||
=> VerifyCS.VerifyStandardProperties(); | ||
|
||
// Namespace | ||
[InlineData("namespace", "N", "~N:N")] | ||
// Type | ||
[InlineData("type", "N.C+D", "~T:N.C.D")] | ||
// Field | ||
[InlineData("member", "N.C.#F", "~F:N.C.F")] | ||
// Property | ||
[InlineData("member", "N.C.#P", "~P:N.C.P")] | ||
// Method | ||
[InlineData("member", "N.C.#M", "~M:N.C.M")] | ||
// Generic method with parameters | ||
[InlineData("member", "N.C.#M2(!!0)", "~M:N.C.M2``1(``0)~System.Int32")] | ||
// Event | ||
[InlineData("member", "e:N.C.#E", "~E:N.C.E")] | ||
[Theory] | ||
public async Task LegacySuppressions(string scope, string target, string fixedTarget) | ||
{ | ||
var input = $@" | ||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(""Category"", ""Id: Title"", Scope = ""{scope}"", Target = {{|#0:""{target}""|}})] | ||
namespace N | ||
{{ | ||
class C | ||
{{ | ||
private int F; | ||
public int P {{ get; set; }} | ||
public void M() {{ }} | ||
public int M2<T>(T t) => 0; | ||
public event System.EventHandler<int> E; | ||
class D | ||
{{ | ||
}} | ||
}} | ||
}}"; | ||
|
||
var expectedDiagnostic = VerifyCS.Diagnostic(AbstractRemoveUnnecessarySuppressionsDiagnosticAnalyzer.LegacyFormatTargetDescriptor) | ||
.WithLocation(0) | ||
.WithArguments(target); | ||
|
||
var fixedCode = $@" | ||
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(""Category"", ""Id: Title"", Scope = ""{scope}"", Target = ""{fixedTarget}"")] | ||
namespace N | ||
{{ | ||
class C | ||
{{ | ||
private int F; | ||
public int P {{ get; set; }} | ||
public void M() {{ }} | ||
public int M2<T>(T t) => 0; | ||
public event System.EventHandler<int> E; | ||
class D | ||
{{ | ||
}} | ||
}} | ||
}}"; | ||
await VerifyCS.VerifyCodeFixAsync(input, expectedDiagnostic, fixedCode); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.