Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/AutoFactories.Tests/AutoFactories.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.9" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="Ninject" Version="3.3.6" />
<PackageReference Include="Seed.IO" Version="2.0.1" />
<PackageReference Include="SourceGenerator.Foundations.Contracts" Version="2.0.14" />
<PackageReference Include="Seed.IO" Version="2.0.3" />
<PackageReference Include="SourceGenerator.Foundations.Contracts" Version="2.0.16" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
8 changes: 4 additions & 4 deletions src/AutoFactories.Tests/DiagnosticsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class Human

""",
assertAnalyzerResult: d => d.Should()
.OnlyContain(d => d.Id == DiagnosticIdentifier.ExposedAsIsNotDerivedType));
.OnlyContain(d => d.Id == DiagnosticIdentifier.ExposedAsIsNotDerivedType.Value));


[Fact]
Expand Down Expand Up @@ -57,7 +57,7 @@ public UntaggedFactory([FromFactory] string name)
{}
}
""",
assertAnalyzerResult: d => d.Should().OnlyContain(d => d.Id == DiagnosticIdentifier.UnmarkedFactory));
assertAnalyzerResult: d => d.Should().OnlyContain(d => d.Id == DiagnosticIdentifier.UnmarkedFactory.Value));

public Task PublicFactory_WithInternalClass_EmitsInconsistentFactoryAccessibility()
=> Compose($$"""
Expand All @@ -71,7 +71,7 @@ internal class Chair
{}
""",
assertAnalyzerResult: d => d.Should()
.OnlyContain(d => d.Id == DiagnosticIdentifier.InconsistentFactoryAccessibility));
.OnlyContain(d => d.Id == DiagnosticIdentifier.InconsistentFactoryAccessibility.Value));

[Fact]
public Task Parameter_With_Unresolved_Type_EmitsUnresolvedParameterType()
Expand All @@ -98,7 +98,7 @@ public Provider(IExternalType externalType)
}
""",
assertAnalyzerResult:
d => d.Should().OnlyContain(d => d.Id == DiagnosticIdentifier.UnresolvedParameterType));
d => d.Should().OnlyContain(d => d.Id == DiagnosticIdentifier.UnresolvedParameterType.Value));
}
}
}
39 changes: 12 additions & 27 deletions src/AutoFactories/AutoFactories.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>12</LangVersion>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<PackageIcon>Icon.jpg</PackageIcon>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
<ItemGroup>
<Content Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
Expand All @@ -14,41 +15,25 @@
<Pack>True</Pack>
<PackagePath>\</PackagePath>
</None>
<PackageReference Include="AutoInterface" />
<PackageReference Include="Boxed.Mapping" Version="7.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.9.2" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" PrivateAssets="all" ExcludeAssets="runtime"/>
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="CodeCasing" Version="3.0.3" />
<PackageReference Include="Handlebars.Net" Version="2.1.6" />
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.4.5" />
<PackageReference Include="SourceGenerator.Foundations" />
<PackageReference Include="Vogen" Version="4.0.19" />
<PackageReference Update="AutoInterface" Version="2.4.0">
<PackageReference Include="Boxed.Mapping" Version="7.0.0" PrivateAssets="all" />
<PackageReference Include="Handlebars.Net" Version="2.1.6" PrivateAssets="all" />
<PackageReference Include="AutoInterface" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nullable" Version="1.3.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- Bug Fix: https://github.com/ByronMayne/Ninject.Extensions.AutoFactories/issues/11 -->
<PackageReference Update="*" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="CodeCasing" Version="4.0.5" />
<PackageReference Update="GitVersion.MsBuild" Version="6.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Update="Handlebars.Net.Helpers.Humanizer" Version="2.4.7" />
<PackageReference Update="Microsoft.CodeAnalysis.Common" Version="5.3.0" />
<PackageReference Update="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageReference Update="NugetInsights.Connector" Version="1.0.*">
<PackageReference Include="CodeCasing" Version="4.0.5" />
<PackageReference Include="GitVersion.MsBuild" Version="6.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Comment on lines +28 to 32
<PackageReference Update="SourceGenerator.Foundations" Version="2.0.13" />
<PackageReference Update="Vogen" Version="7.0.3" />
<PackageReference Include="Handlebars.Net.Helpers.Humanizer" Version="2.4.7" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" PrivateAssets="all" />
Comment on lines +33 to +34
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="5.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="5.3.0" />
<PackageReference Include="SourceGenerator.Foundations" Version="2.0.16" />
Comment on lines +35 to +37
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/AutoFactories/Diagnostics/DiagnosticBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected DiagnosticBuilder(DiagnosticIdentifier id, string title, string catego
/// </summary>
/// <returns></returns>
protected virtual DiagnosticDescriptor CreateDescriptor()
=> new DiagnosticDescriptor(Id, Title, MessageFormat, Category, Severity, true, Description);
=> new DiagnosticDescriptor(Id.Value, Title, MessageFormat, Category, Severity, true, Description);

protected static string FormatId(int number)
=> $"AF{number + 100}";
Expand Down
39 changes: 28 additions & 11 deletions src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
using Vogen;

namespace AutoFactories.Diagnostics
namespace AutoFactories.Diagnostics
{
[Instance("UnmarkedFactory", "AF1001")]
[Instance("InconsistentFactoryAccessibility", "AF1002")]
[Instance("ExposedAsIsNotDerivedType", "AF1003")]
[Instance("UnresolvedParameterType", "AF1004")]
[ValueObject<string>(conversions: Conversions.None, toPrimitiveCasting: CastOperator.Implicit)]
internal partial record DiagnosticIdentifier
{}
}

internal struct DiagnosticIdentifier

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Ninject)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Ninject)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Ninject)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Ninject)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Microsoft.DependencyInjection)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Microsoft.DependencyInjection)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Microsoft.DependencyInjection)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.GetHashCode()

Check warning on line 4 in src/AutoFactories/Diagnostics/DiagnosticIdentifier.cs

View workflow job for this annotation

GitHub Actions / Build (AutoFactories.Microsoft.DependencyInjection)

'DiagnosticIdentifier' defines operator == or operator != but does not override Object.Equals(object o)
{
public static DiagnosticIdentifier UnmarkedFactory = new DiagnosticIdentifier("AF1001");
public static DiagnosticIdentifier InconsistentFactoryAccessibility = new DiagnosticIdentifier("AF1002");
public static DiagnosticIdentifier ExposedAsIsNotDerivedType = new DiagnosticIdentifier("AF1003");
public static DiagnosticIdentifier UnresolvedParameterType = new DiagnosticIdentifier("AF1004");

public readonly string Value;

private DiagnosticIdentifier(string value)
{
Value = value;
}

public static bool operator ==(DiagnosticIdentifier left, DiagnosticIdentifier right)
=> left.Value == right.Value;

public static bool operator !=(DiagnosticIdentifier left, DiagnosticIdentifier right)
=> left.Value != right.Value;

public static bool operator ==(DiagnosticIdentifier left, string right)
=> left.Value == right;

public static bool operator !=(DiagnosticIdentifier left, string right) => left.Value != right;
}
Comment on lines +4 to +28
}
25 changes: 17 additions & 8 deletions src/AutoFactories/ViewKey.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
using System;
using System.IO;
using Vogen;
using System.IO;

namespace AutoFactories
{
[Instance("Factory", "FactoryView")]
[Instance("FactoryInterface", "FactoryInterfaceView")]
[Instance("ClassAttribute", "ClassAttribute")]
[Instance("ParameterAttribute", "ParameterAttribute")]
[ValueObject<string>(conversions: Conversions.None)]
public readonly partial struct ViewKey
{
public static ViewKey Factory = new ViewKey("FactoryView");
public static ViewKey FactoryInterface = new ViewKey("FactoryInterfaceView");
public static ViewKey ClassAttribute = new ViewKey("ClassAttribute");
Comment on lines 5 to +9
public static ViewKey ParameterAttribute = new ViewKey("ParameterAttribute");


public readonly string Value;

private ViewKey(string value)
{
Value = value;
}

public static ViewKey From(string input)
=> new ViewKey(NormalizeInput(input));

private static string NormalizeInput(string input)
=> Path.GetFileNameWithoutExtension(input);

Expand Down
14 changes: 0 additions & 14 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,4 @@
<ImportGroup Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
<Import Project="Nuget.props"/>
</ImportGroup>

<!--
SourceGenerator.Foundations (SGF_EmbedDependencies) embeds every referenced assembly as a resource.
The Roslyn assemblies (Microsoft.CodeAnalysis*, e.g. Microsoft.CodeAnalysis.dll and
Microsoft.CodeAnalysis.CSharp.dll) are provided by the compiler host at runtime, so embedding them
bloats the analyzer and risks loading a version that conflicts with the host. Remove those assemblies
while leaving the other embedded resources (such as the Handlebars templates) intact.
-->
<Target Name="RemoveCodeAnalyzers" AfterTargets="SGF_EmbedDependencies">
<ItemGroup>
<_EmbeddedCodeAnalysisAssembly Include="@(EmbeddedResource)" Condition="$([System.String]::Copy('%(FileName)').StartsWith('Microsoft.CodeAnalysis'))" />
<EmbeddedResource Remove="@(_EmbeddedCodeAnalysisAssembly)" />
</ItemGroup>
</Target>
</Project>
Loading