Skip to content

Commit

Permalink
Merge branch 'master' of github.com:RocketSurgeonsGuild/Conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
david-driscoll committed Feb 15, 2022
2 parents dfe70e9 + 67bcba5 commit a568351
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 64 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<PackageVersion Include="FakeItEasy" Version="7.3.0" />
<PackageVersion Include="FakeItEasy.Analyzer.CSharp" Version="6.1.0" />
<PackageVersion Include="FluentAssertions" Version="6.5.1" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.15.0" />
<PackageVersion Include="FluentAssertions.Analyzers" Version="0.16.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.FakeItEasy" Version="6.1.0" />
<PackageVersion Include="Rocket.Surgery.Extensions.Testing.XUnit" Version="6.1.0" />
Expand Down
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"devDependencies": {
"@prettier/plugin-xml": "^1.2.0",
"husky": "^7.0.4",
"lint-staged": "^12.3.3",
"lint-staged": "^12.3.4",
"prettier": "^2.5.1"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/Conventions.Analyzers/ConventionAttributesGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ namespace Rocket.Surgery.Conventions;
[Generator]
public class ConventionAttributesGenerator : IIncrementalGenerator
{
private static readonly ConventionConfigurationData _exportsDefaultConfiguration = new(false, true, "", "Exports", "GetConventions");
private static readonly ConventionConfigurationData _importsDefaultConfiguration = new(false, true, "", "Imports", "GetConventions");
private static readonly ConventionConfigurationData _exportsDefaultConfiguration = new(false, true, "", "Exports", "GetConventions") { Postfix = true };
private static readonly ConventionConfigurationData _importsDefaultConfiguration = new(false, true, "", "Imports", "GetConventions") { Postfix = true };

public void Initialize(IncrementalGeneratorInitializationContext context)
{
Expand Down
21 changes: 6 additions & 15 deletions src/Conventions.Analyzers/ConventionConfigurationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ namespace Rocket.Surgery.Conventions;

internal record ConventionConfigurationData(bool WasConfigured, bool Assembly, string? Namespace, string ClassName, string MethodName)
{
public bool Postfix { get; init; }

private record InnerConventionConfigurationData(bool Assembly, string? Namespace, string ClassName, string MethodName)
{
public bool Postfix { get; init; } = true;
public bool DefinedNamespace { get; init; }
public bool WasConfigured { get; init; }

Expand Down Expand Up @@ -49,13 +50,6 @@ ConventionConfigurationData defaults
data = data with { Assembly = bool.TryParse(value, out var b) && b, WasConfigured = true };
}

if (config.GlobalOptions.TryGetValue(
$"build_property.{attributeName}{nameof(InnerConventionConfigurationData.Postfix)}", out value
))
{
data = data with { Postfix = bool.TryParse(value, out var b) && b, WasConfigured = true };
}

return data;
}
);
Expand Down Expand Up @@ -108,10 +102,6 @@ syntaxContext.Node is AttributeListSyntax attributeListSyntax
{
Assembly = (bool)syntax.Token.Value!
},
nameof(InnerConventionConfigurationData.Postfix) => data with
{
Postfix = (bool)syntax.Token.Value!
},
_ => data
};
}
Expand All @@ -128,11 +118,12 @@ syntaxContext.Node is AttributeListSyntax attributeListSyntax
(tuple, token) => new ConventionConfigurationData(
tuple.Left.WasConfigured,
tuple.Left.Assembly,
tuple.Left.DefinedNamespace ? tuple.Left.Namespace! : GetNamespaceForCompilation(tuple.Right, tuple.Left.Postfix),
tuple.Left.DefinedNamespace ? tuple.Left.Namespace! : GetNamespaceForCompilation(tuple.Right, defaults.Postfix),
tuple.Left.ClassName,
tuple.Left.MethodName
)
);
)
.Select((data, token) => data with { Namespace = data.Namespace == "global" ? "" : data.Namespace });
}

public static ConventionConfigurationData FromAssemblyAttributes(IAssemblySymbol assemblySymbol, ConventionConfigurationData defaults)
Expand Down Expand Up @@ -184,7 +175,7 @@ public SyntaxList<AttributeListSyntax> ToAttributes(string type)
);
}

private static string GetNamespaceForCompilation(Compilation compilation, bool postfix)
private static string GetNamespaceForCompilation(Compilation compilation, bool postfix = false)
{
var @namespace = compilation.AssemblyName ?? "";
if (postfix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ public abstract class ConventionsConfigurationAttribute : Attribute
/// </summary>
public bool Assembly { get; set; }

/// <summary>
/// Should the default namespace has a the .Conventions postfix
/// </summary>
/// <returns></returns>
public bool Postfix { get; set; } = true;

/// <summary>
/// The desired namespace for the emitted classes to go
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
<CompilerVisibleProperty Include="ImportConventionsNamespace" />
<CompilerVisibleProperty Include="ImportConventionsClassName" />
<CompilerVisibleProperty Include="ImportConventionsMethodName" />
<CompilerVisibleProperty Include="ImportConventionsPostfix" />
<CompilerVisibleProperty Include="ExportConventionsAssembly" />
<CompilerVisibleProperty Include="ExportConventionsNamespace" />
<CompilerVisibleProperty Include="ExportConventionsClassName" />
<CompilerVisibleProperty Include="ExportConventionsMethodName" />
<CompilerVisibleProperty Include="ExportConventionsPostfix" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,25 @@
Condition="'$(_ConventionApplicationDetected)' == '' and ('$(OutputType)' != 'Library' or '$(OutputType)' != 'library')"
>true</_ConventionApplicationDetected>
<_ConventionApplicationDetected Condition="'$(_ConventionApplicationDetected)' == ''">false</_ConventionApplicationDetected>
</PropertyGroup>
<PropertyGroup Condition="'$(_ConventionApplicationDetected)' == 'true'">
<ImportConventionsAssembly Condition="'$(ImportConventionsAssembly)' == ''">true</ImportConventionsAssembly>

<ImportConventionsNamespace Condition="'$(ImportConventionsNamespace)' == ''">$(RootNamespace)</ImportConventionsNamespace>
<ImportConventionsClassName Condition="'$(ImportConventionsClassName)' == ''">Imports</ImportConventionsClassName>
<ImportConventionsMethodName Condition="'$(ImportConventionsMethodName)' == ''">GetConventions</ImportConventionsMethodName>
<ImportConventionsPostfix Condition="'$(ImportConventionsPostfix)' == ''">false</ImportConventionsPostfix>
<ImportConventionsMethodName Condition="'$(ImportConventionsMethodName)' == ''">GetConventions</ImportConventionsMethodName>

<ExportConventionsAssembly Condition="'$(ExportConventionsAssembly)' == ''">false</ExportConventionsAssembly>
<ExportConventionsNamespace Condition="'$(ExportConventionsNamespace)' == ''">$(RootNamespace).Conventions</ExportConventionsNamespace>
<ExportConventionsClassName Condition="'$(ExportConventionsClassName)' == ''">Exports</ExportConventionsClassName>
<ExportConventionsMethodName Condition="'$(ExportConventionsMethodName)' == ''">GetConventions</ExportConventionsMethodName>
<ExportConventionsPostfix Condition="'$(ExportConventionsPostfix)' == ''">true</ExportConventionsPostfix>
<ExportConventionsMethodName Condition="'$(ExportConventionsMethodName)' == ''">GetConventions</ExportConventionsMethodName>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<ImportConventionsAssembly Condition="'$(ImportConventionsAssembly)' == ''">true</ImportConventionsAssembly>
<ExportConventionsAssembly Condition="'$(ExportConventionsAssembly)' == ''">true</ExportConventionsAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(_ConventionApplicationDetected)' == 'true'">
<ImportConventionsAssembly Condition="'$(ImportConventionsAssembly)' == ''">true</ImportConventionsAssembly>
<ExportConventionsAssembly Condition="'$(ExportConventionsAssembly)' == ''">false</ExportConventionsAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(_ConventionApplicationDetected)' != 'true'">
<ImportConventionsAssembly Condition="'$(ImportConventionsAssembly)' == ''">false</ImportConventionsAssembly>
<ImportConventionsClassName Condition="'$(ImportConventionsClassName)' == ''">Imports</ImportConventionsClassName>
<ImportConventionsMethodName Condition="'$(ImportConventionsMethodName)' == ''">GetConventions</ImportConventionsMethodName>
<ImportConventionsPostfix Condition="'$(ImportConventionsPostfix)' == ''">false</ImportConventionsPostfix>

<ImportConventionsAssembly Condition="'$(ImportConventionsAssembly)' == ''">false</ImportConventionsAssembly>
<ExportConventionsAssembly Condition="'$(ExportConventionsAssembly)' == ''">true</ExportConventionsAssembly>
<ExportConventionsClassName Condition="'$(ExportConventionsClassName)' == ''">Exports</ExportConventionsClassName>
<ExportConventionsMethodName Condition="'$(ExportConventionsMethodName)' == ''">GetConventions</ExportConventionsMethodName>
<ExportConventionsPostfix Condition="'$(ExportConventionsPostfix)' == ''">true</ExportConventionsPostfix>
</PropertyGroup>
</Project>
9 changes: 3 additions & 6 deletions test/Conventions.Tests/StaticConventionTests.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Rocket.Surgery.Conventions;
using Xunit;

[assembly: ImportConventions]

namespace Rocket.Surgery.Conventions.Tests;

[ImportConventions]
Expand All @@ -21,8 +18,8 @@ public void Should_Have_Exports_Method_Defined()
[Fact]
public void Should_Have_Imports_Method_Defined_On_Assembly()
{
var list = Conventions.Imports.GetConventions(new ServiceCollection().BuildServiceProvider())
.Should().NotBeNull().And.Subject;
var list = Imports.GetConventions(new ServiceCollection().BuildServiceProvider())
.Should().NotBeNull().And.Subject;
list.As<IEnumerable<IConventionWithDependencies>>().Should().NotBeNull();
}

Expand All @@ -35,7 +32,7 @@ public void Should_Have_Imports_Method_Defined_On_Assembly_Into_Provider()
var items = list.As<IEnumerable<IConventionWithDependencies>>().Should().NotBeNull().And.Subject;

var provider = new ConventionProvider(HostType.Undefined, items, Array.Empty<object>(), Array.Empty<object>());
Func<IEnumerable<object>> a = () => provider.GetAll();
var a = () => provider.GetAll();

a.Should().NotThrow();

Expand Down
4 changes: 2 additions & 2 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<Import Project="$(MSBuildThisFileDirectory)../src/Conventions.Attributes/build/Rocket.Surgery.Conventions.Attributes.props" />
<PropertyGroup>
<MergeCoverage>true</MergeCoverage>
<IncludeTestAssembly>true</IncludeTestAssembly>
<NoWarn>$(NoWarn);CA1812</NoWarn>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>
</Project>

0 comments on commit a568351

Please sign in to comment.