Skip to content

Commit

Permalink
fix: ensure that not implemented events raise Uno0001
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Jan 16, 2024
1 parent 0dbdf7e commit 25b9c71
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
74 changes: 74 additions & 0 deletions src/Uno.Analyzers.Tests/UnoNotImplementedTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,80 @@ public TypeName()
await Verify.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task When_EventAddNotImplemented()
{
var test =
"""
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Uno
{
public class TestClass
{
[NotImplemented]
public event Action MyEvent;
}
}

namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
[|a.MyEvent|] += delegate { };
}
}
}
""" + UnoNotImplementedAtribute;

await Verify.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task When_EventRemoveNotImplemented()
{
var test =
"""
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

namespace Uno
{
public class TestClass
{
[NotImplemented]
public event Action MyEvent;
}
}

namespace ConsoleApplication1
{
class TypeName
{
public TypeName()
{
var a = new Uno.TestClass();
[|a.MyEvent|] -= delegate { };
}
}
}
""" + UnoNotImplementedAtribute;

await Verify.VerifyAnalyzerAsync(test);
}

[TestMethod]
public async Task When_SinglePlatform_Included()
{
Expand Down
9 changes: 8 additions & 1 deletion src/Uno.Analyzers/UnoNotImplementedAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ public override void Initialize(AnalysisContext context)
return;
}
context.RegisterOperationAction(c => AnalyzeOperation(c, notImplementedSymbol), OperationKind.Invocation, OperationKind.ObjectCreation, OperationKind.FieldReference, OperationKind.PropertyReference);
context.RegisterOperationAction(c =>
AnalyzeOperation(c, notImplementedSymbol)
, OperationKind.Invocation
, OperationKind.ObjectCreation
, OperationKind.FieldReference
, OperationKind.PropertyReference
, OperationKind.EventReference);
});
}

Expand Down Expand Up @@ -85,6 +91,7 @@ private void AnalyzeOperation(OperationAnalysisContext context, INamedTypeSymbol
IObjectCreationOperation objectCreation => objectCreation.Type,
IFieldReferenceOperation fieldReferenceOperation => fieldReferenceOperation.Field,
IPropertyReferenceOperation propertyReferenceOperation => propertyReferenceOperation.Property,
IEventReferenceOperation eventReferenceOperation => eventReferenceOperation.Event,
_ => throw new InvalidOperationException("This code path is unreachable.")
};

Expand Down

0 comments on commit 25b9c71

Please sign in to comment.