Skip to content

Commit

Permalink
Revert "Add support for Vogen validations (#47)" (#53)
Browse files Browse the repository at this point in the history
This reverts commit 4579db0.
  • Loading branch information
viceroypenguin authored Jun 5, 2024
1 parent c6fd417 commit 0c7cfa0
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 225 deletions.
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
<PackageVersion Include="Verify.SourceGenerators" Version="2.2.0" />
<PackageVersion Include="Verify.Xunit" Version="25.0.1" />
<PackageVersion Include="Vogen" Version="4.0.8" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
</ItemGroup>
Expand Down
20 changes: 0 additions & 20 deletions src/Immediate.Validations.Generators/ITypeSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,6 @@ typeSymbol is
},
};

public static bool IsVogenAttribute(this INamedTypeSymbol? typeSymbol) =>
typeSymbol is
{
Name: "ValueObjectAttribute",
ContainingNamespace:
{
Name: "Vogen",
ContainingNamespace.IsGlobalNamespace: true,
},
}
or
{
MetadataName: "ValueObjectAttribute`1",
ContainingNamespace:
{
Name: "Vogen",
ContainingNamespace.IsGlobalNamespace: true,
},
};

public static bool IsValidatorAttribute(this INamedTypeSymbol? typeSymbol) =>
typeSymbol is
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,8 @@ CancellationToken token

token.ThrowIfCancellationRequested();

var isValidationProperty =
propertyType
.GetAttributes()
.Any(v => v.AttributeClass.IsValidateAttribute());

var isVogenProperty =
propertyType
.GetAttributes()
.Any(v => v.AttributeClass.IsVogenAttribute())
&& propertyType
.GetMembers()
.Any(m => m is
{
Name: "Validate",
IsStatic: true,
});
var isValidationProperty = propertyType.GetAttributes()
.Any(v => v.AttributeClass.IsValidateAttribute());

token.ThrowIfCancellationRequested();

Expand Down Expand Up @@ -340,7 +326,6 @@ CancellationToken token
if (
(isNullable || !isReferenceType)
&& !isValidationProperty
&& !isVogenProperty
&& collectionPropertyDetails is null
&& validations is []
)
Expand All @@ -357,11 +342,9 @@ CancellationToken token
IsNullable = isNullable,

IsValidationProperty = isValidationProperty,
IsVogenProperty = isVogenProperty,
ValidationTypeFullName =
(isValidationProperty || isVogenProperty)
? baseType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
: null,
ValidationTypeFullName = isValidationProperty
? baseType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
: null,

CollectionPropertyDetails = collectionPropertyDetails,

Expand Down
1 change: 0 additions & 1 deletion src/Immediate.Validations.Generators/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public sealed record ValidationTargetProperty
public required bool IsReferenceType { get; init; }
public required bool IsNullable { get; init; }
public required bool IsValidationProperty { get; init; }
public required bool IsVogenProperty { get; init; }
public required string? ValidationTypeFullName { get; init; }
public required ValidationTargetProperty? CollectionPropertyDetails { get; init; }
public required EquatableReadOnlyList<PropertyValidation> Validations { get; init; }
Expand Down
12 changes: 0 additions & 12 deletions src/Immediate.Validations.Generators/Templates/Validations.sbntxt
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ partial {{ class.type }} {{ class.name }}
PropertyName = $"{{ get_prop_name(p.name, depth) }}.{error.PropertyName}",
});
}
{{~ else if p.is_vogen_property ~}}
{
var validation = {{ p.validation_type_full_name }}.Validate(t.Value);
if (!string.IsNullOrWhiteSpace(validation.ErrorMessage))
{
errors.Add(new()
{
PropertyName = $"{{ get_prop_name(p.name, depth) }}",
ErrorMessage = validation.ErrorMessage,
});
}
}
{{~ end ~}}

{{~ if p.collection_property_details ~}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PackageReference Include="Immediate.Handlers" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Vogen" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -412,37 +412,4 @@ public partial class SubClass : BaseClass, IValidationTarget<SubClass>;

_ = await Verify(result);
}

[Fact]
public async Task VogenValidation()
{
var driver = GeneratorTestHelper.GetDriver(
"""
#nullable enable
using System.Collections.Generic;
using Immediate.Validations.Shared;
using Vogen;
[ValueObject]
public readonly partial struct UserId
{
public static Validation Validate(int value) =>
value > 0 ? Validation.Ok : Validation.Invalid("Must be greater than zero.");
}
[Validate]
public partial class ValidateClass : IValidationTarget<ValidateClass>
{
public required UserId UserId { get; init; }
}
""");

var result = driver.GetRunResult();

Assert.Empty(result.Diagnostics);
_ = Assert.Single(result.GeneratedTrees);

_ = await Verify(result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Verify.SourceGenerators" />
<PackageReference Include="Verify.Xunit" />
<PackageReference Include="Vogen" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion tests/Immediate.Validations.Tests/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public static MetadataReference[] GetMetadataReferences() =>
[
MetadataReference.CreateFromFile("./Immediate.Handlers.Shared.dll"),
MetadataReference.CreateFromFile("./Immediate.Validations.Shared.dll"),
MetadataReference.CreateFromFile("./Vogen.SharedTypes.dll"),
];
}

0 comments on commit 0c7cfa0

Please sign in to comment.