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

Use MEM0001, MEM0002, MEM0003 error codes #9

Merged
merged 1 commit into from
Oct 24, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class MemoryAnalyzersCodeFixProvider : CodeFixProvider
{
public sealed override ImmutableArray<string> FixableDiagnosticIds
{
get { return ImmutableArray.Create(MemoryAnalyzer.MA0001, MemoryAnalyzer.MA0002, MemoryAnalyzer.MA0003); }
get { return ImmutableArray.Create(MemoryAnalyzer.MEM0001, MemoryAnalyzer.MEM0002, MemoryAnalyzer.MEM0003); }
}

public sealed override FixAllProvider GetFixAllProvider()
Expand All @@ -37,7 +37,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
if (parent is null)
return;

if (diagnostic.Id == MemoryAnalyzer.MA0001)
if (diagnostic.Id == MemoryAnalyzer.MEM0001)
{
var declaration = parent.AncestorsAndSelf().OfType<EventFieldDeclarationSyntax>().First();
context.RegisterCodeFix(
Expand All @@ -53,7 +53,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
equivalenceKey: nameof(CodeFixResources.AddUnconditionalSuppressMessage)),
diagnostic);
}
else if (diagnostic.Id == MemoryAnalyzer.MA0002)
else if (diagnostic.Id == MemoryAnalyzer.MEM0002)
{
var declaration = parent.AncestorsAndSelf().OfType<MemberDeclarationSyntax>().First();
context.RegisterCodeFix(
Expand All @@ -75,7 +75,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
equivalenceKey: nameof(CodeFixResources.MakeWeak)),
diagnostic);
}
else if (diagnostic.Id == MemoryAnalyzer.MA0003)
else if (diagnostic.Id == MemoryAnalyzer.MEM0003)
{
var declaration = parent.AncestorsAndSelf().OfType<AssignmentExpressionSyntax>().First();
if (declaration.Parent is null)
Expand Down
44 changes: 22 additions & 22 deletions MemoryAnalyzers/MemoryAnalyzers.Test/CodeFixUnitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace MemoryAnalyzers.Test
public class CodeFixUnitTests
{
[TestMethod]
public async Task MA0001_Remove()
public async Task MEM0001_Remove()
{
var test = """
class Foo : NSObject
Expand All @@ -26,12 +26,12 @@ class Foo : NSObject
}
""";

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

[TestMethod]
public async Task MA0001_UnconditionalSuppressMessage()
public async Task MEM0001_UnconditionalSuppressMessage()
{
var test = """
class Foo : NSObject
Expand All @@ -43,17 +43,17 @@ class Foo : NSObject
var codefix = """
class Foo : NSObject
{
[UnconditionalSuppressMessage("Memory", "MA0001", Justification = "Proven safe in test: XYZ")]
[UnconditionalSuppressMessage("Memory", "MEM0001", Justification = "Proven safe in test: XYZ")]
public event EventHandler {|#0:EventName|};
}
""";

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

[TestMethod]
public async Task MA0002_Remove()
public async Task MEM0002_Remove()
{
var test = """
class Foo : NSObject
Expand All @@ -69,12 +69,12 @@ class Foo : NSObject
}
""";

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

[TestMethod]
public async Task MA0002_UnconditionalSuppressMessage()
public async Task MEM0002_UnconditionalSuppressMessage()
{
var test = """
class Foo : NSObject
Expand All @@ -86,17 +86,17 @@ class Foo : NSObject
var codefix = """
class Foo : NSObject
{
[UnconditionalSuppressMessage("Memory", "MA0002", Justification = "Proven safe in test: XYZ")]
[UnconditionalSuppressMessage("Memory", "MEM0002", Justification = "Proven safe in test: XYZ")]
public UIView {|#0:FieldName|};
}
""";

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

[TestMethod]
public async Task MA0002_MakeWeak_Field()
public async Task MEM0002_MakeWeak_Field()
{
var test = """
class Foo : NSObject
Expand All @@ -112,12 +112,12 @@ class Foo : NSObject
}
""";

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

[TestMethod]
public async Task MA0002_MakeWeak_Property()
public async Task MEM0002_MakeWeak_Property()
{
var test = """
class Foo : NSObject
Expand All @@ -133,20 +133,20 @@ class Foo : NSObject
}
""";

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

[TestMethod]
public async Task MA0003_Remove()
public async Task MEM0003_Remove()
{
var test = """
using System.Diagnostics.CodeAnalysis;

[Register("UITextField", true)]
class UITextField
{
[UnconditionalSuppressMessage("Memory", "MA0001")]
[UnconditionalSuppressMessage("Memory", "MEM0001")]
public event EventHandler EditingDidBegin;
}

Expand All @@ -169,7 +169,7 @@ void OnEditingDidBegin(object sender, EventArgs e)
[Register("UITextField", true)]
class UITextField
{
[UnconditionalSuppressMessage("Memory", "MA0001")]
[UnconditionalSuppressMessage("Memory", "MEM0001")]
public event EventHandler EditingDidBegin;
}

Expand All @@ -186,20 +186,20 @@ void OnEditingDidBegin(object sender, EventArgs e)
}
""";

var expected = VerifyCS.Diagnostic("MA0003").WithLocation(0).WithArguments("OnEditingDidBegin");
var expected = VerifyCS.Diagnostic("MEM0003").WithLocation(0).WithArguments("OnEditingDidBegin");
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 0);
}

[TestMethod]
public async Task MA0003_MakeStatic()
public async Task MEM0003_MakeStatic()
{
var test = """
using System.Diagnostics.CodeAnalysis;

[Register("UITextField", true)]
class UITextField
{
[UnconditionalSuppressMessage("Memory", "MA0001")]
[UnconditionalSuppressMessage("Memory", "MEM0001")]
public event EventHandler EditingDidBegin;
}

Expand All @@ -222,7 +222,7 @@ void OnEditingDidBegin(object sender, EventArgs e)
[Register("UITextField", true)]
class UITextField
{
[UnconditionalSuppressMessage("Memory", "MA0001")]
[UnconditionalSuppressMessage("Memory", "MEM0001")]
public event EventHandler EditingDidBegin;
}

Expand All @@ -239,7 +239,7 @@ static void OnEditingDidBegin(object sender, EventArgs e)
}
""";

var expected = VerifyCS.Diagnostic("MA0003").WithLocation(0).WithArguments("OnEditingDidBegin");
var expected = VerifyCS.Diagnostic("MEM0003").WithLocation(0).WithArguments("OnEditingDidBegin");
await VerifyCS.VerifyCodeFixAsync(test, expected, codefix, index: 1);
}
}
Expand Down