Skip to content

Commit

Permalink
Remove auto-using System.Diagnostics.CodeAnalysis
Browse files Browse the repository at this point in the history
I think this causes IDEs to act strangely when you apply the code fix.
  • Loading branch information
jonathanpeppers committed Jul 26, 2023
1 parent 73743b3 commit 01083b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ async Task<Solution> AddUnconditionalSuppressMessage(Diagnostic diagnostic, Docu
if (root is null)
return document.Project.Solution;

if (root is CompilationUnitSyntax unit)
{
root = unit.AddUsingsIfNotExist("System.Diagnostics.CodeAnalysis");
}
// FIXME: I believe this causes IDEs to act strangely, removing to test that theory
//if (root is CompilationUnitSyntax unit)
//{
// root = unit.AddUsingsIfNotExist("System.Diagnostics.CodeAnalysis");
//}

// Used: http://roslynquoter.azurewebsites.net/
var attributes = member.AttributeLists.Add(
Expand Down
8 changes: 2 additions & 6 deletions MemoryAnalyzers/MemoryAnalyzers.Test/CodeFixUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class Foo : NSObject
""";

var codefix = """
using System.Diagnostics.CodeAnalysis;

class Foo : NSObject
{
[UnconditionalSuppressMessage("Memory", "MA0001", Justification = "Proven safe in test: XYZ")]
Expand All @@ -51,7 +49,7 @@ class Foo : NSObject
""";

var expected = VerifyCS.Diagnostic("MA0001").WithLocation(0).WithArguments("EventName");
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 1, iterations: 2);
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 1);
}

[TestMethod]
Expand Down Expand Up @@ -86,8 +84,6 @@ class Foo : NSObject
""";

var codefix = """
using System.Diagnostics.CodeAnalysis;

class Foo : NSObject
{
[UnconditionalSuppressMessage("Memory", "MA0002", Justification = "Proven safe in test: XYZ")]
Expand All @@ -96,7 +92,7 @@ class Foo : NSObject
""";

var expected = VerifyCS.Diagnostic("MA0002").WithLocation(0).WithArguments("FieldName");
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 1, iterations: 2);
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 1);
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public static async Task VerifyAnalyzerAsync(string source, params DiagnosticRes

AddTestCode(test.TestState);

// Intentionally left out of codefix tests
test.TestState.Sources.Add("global using System.Diagnostics.CodeAnalysis;");

test.ExpectedDiagnostics.AddRange(expected);
await test.RunAsync(CancellationToken.None);
}
Expand Down Expand Up @@ -75,6 +72,7 @@ static void AddTestCode(SolutionState testState)
{
// Global usings
testState.Sources.Add("global using System;");
testState.Sources.Add("global using System.Diagnostics.CodeAnalysis;");
testState.Sources.Add("global using CoreAnimation;");
testState.Sources.Add("global using Foundation;");
testState.Sources.Add("global using UIKit;");
Expand Down

0 comments on commit 01083b0

Please sign in to comment.