Skip to content

Commit

Permalink
Merge pull request #390 from ThomasSkyldahl/bugfix/389
Browse files Browse the repository at this point in the history
fixed issue with VoFilter not matching the generic ValueObjectAttribute
  • Loading branch information
SteveDunn authored Apr 14, 2023
2 parents f3f91c7 + 0ef29db commit 1514d61
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
24 changes: 4 additions & 20 deletions src/Vogen/VoFilter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.CodeAnalysis;
Expand Down Expand Up @@ -53,23 +54,6 @@ public static IEnumerable<AttributeData> TryGetValueObjectAttributes(INamedTypeS
return null;
}

public static bool IsTarget(INamedTypeSymbol? voClass)
{
if (voClass == null)
{
return false;
}

ImmutableArray<AttributeData> attributes = voClass.GetAttributes();

if (attributes.Length == 0)
{
return false;
}

AttributeData? voAttribute =
attributes.SingleOrDefault(a => a.AttributeClass?.FullName() is "Vogen.ValueObjectAttribute");

return voAttribute is not null;
}
public static bool IsTarget(INamedTypeSymbol? voClass) =>
voClass is not null && TryGetValueObjectAttributes(voClass).Any();
}
22 changes: 22 additions & 0 deletions tests/AnalyzerTests/DoNotUseNewAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,29 @@ public async Task NoDiagnosticsForEmptyCode()
var test = @"";
await VerifyCS.VerifyAnalyzerAsync(test);
}
#if NET7_0_OR_GREATER
[Theory(DisplayName = "Bug https://github.com/SteveDunn/Vogen/issues/389")]
[ClassData(typeof(Types))]
public async Task Disallow_new_for_creating_value_objects_using_generic_attribute(string type)
{
var source = $@"using Vogen;
namespace Whatever;
[ValueObject<int>()]
public {type} MyVo {{ }}
public class Test {{
public Test() {{
var c = {{|#0:new MyVo()|}};
MyVo c2 = {{|#1:new()|}};
}}
}}
";
await Run(
source,
WithDiagnostics("VOG010", DiagnosticSeverity.Error, "MyVo", 0, 1));
}
#endif
[Theory]
[ClassData(typeof(Types))]
public async Task Disallow_new_for_creating_value_objects(string type)
Expand Down

0 comments on commit 1514d61

Please sign in to comment.