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
8 changes: 0 additions & 8 deletions .net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@
<AdditionalFiles Include="props/**" />
<AdditionalFiles Include="dictionary.dic" />
</ItemGroup>

<ItemGroup>
<None Include=".build/.npmrc" />
<None Include=".build/build-package-template-v2.yaml" />
<None Include=".build/build-package.yaml" />
<None Include=".build/gitleaks.toml" />
<None Include=".build/trivy-html.tpl" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="DotNetProjectFile.Analyzers.Sdk" PrivateAssets="all" />
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageVersion Include="Microsoft.Sbom.Targets" Version="3.1.0" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="NUnit" Version="4.3.2" />
<PackageVersion Include="NUnit.Analyzers" Version="4.7.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="5.0.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="Qowaiv" Version="7.3.0-rc.1" />

Check warning on line 23 in Directory.Packages.props

View workflow job for this annotation

GitHub Actions / build

Use a stable version of 'Qowaiv', instead of '7.3.0-rc.1' (https://dotnet-project-file-analyzers.github.io/rules/Proj1101.html)

Check warning on line 23 in Directory.Packages.props

View workflow job for this annotation

GitHub Actions / build

Use a stable version of 'Qowaiv', instead of '7.3.0-rc.1' (https://dotnet-project-file-analyzers.github.io/rules/Proj1101.html)
<PackageVersion Include="Qowaiv.Analyzers.CSharp" Version="2.0.5" />
<PackageVersion Include="Qowaiv.Diagnostics.Contracts" Version="2.0.5" />
<PackageVersion Include="Qowaiv.TestTools" Version="8.0.0" />
Expand All @@ -28,4 +29,4 @@
<PackageVersion Include="SonarAnalyzer.CSharp" Version="10.8.0.113526" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556" />
</ItemGroup>
</Project>
</Project>
1 change: 1 addition & 0 deletions props/package.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageIcon>package-icon.png</PackageIcon>
<PackageIconUrl>https://github.com/Qowaiv/qowaiv-codegeneration/blob/master/design/package-icon.png</PackageIconUrl>
<PackageProjectUrl>http://www.github.com/Qowaiv/qowaiv-codegeneration</PackageProjectUrl>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageReadmeFile>README.md</PackageReadmeFile>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Qowaiv/qowaiv-codegeneration</RepositoryUrl>
Expand Down
2 changes: 1 addition & 1 deletion src/Qowaiv.CodeGeneration.SingleValueObjects/Embedded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Qowaiv.CodeGeneration.SingleValueObjects;

public static class Embedded
internal static class Embedded
{
[Pure]
public static CodeSnippet Snippet(string name)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

Check warning on line 1 in src/Qowaiv.CodeGeneration.SingleValueObjects/Qowaiv.CodeGeneration.SingleValueObjects.csproj

View workflow job for this annotation

GitHub Actions / build

Enable SBOM generation with <GenerateSBOM> is 'true' or define the <IsPackable> node with value 'false' (https://dotnet-project-file-analyzers.github.io/rules/Proj0243.html)

<Import Project="../../props/package.props" />

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<DevelopmentDependency>true</DevelopmentDependency>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeSymbols>false</IncludeSymbols>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IsPackable>true</IsPackable>

Check warning on line 11 in src/Qowaiv.CodeGeneration.SingleValueObjects/Qowaiv.CodeGeneration.SingleValueObjects.csproj

View workflow job for this annotation

GitHub Actions / build

Property <IsPackable> has been previously defined with the same value (https://dotnet-project-file-analyzers.github.io/rules/Proj0012.html)
<PackageId>Qowaiv.CodeGeneration.SingleValueObjects</PackageId>
<Version>1.0.0</Version>
<PackageReleaseNotes>
Expand Down Expand Up @@ -43,10 +46,11 @@
<ItemGroup Label="CompileTimeDependencies">
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" PrivateAssets="all" />
<PackageReference Include="Microsoft.Sbom.Targets" PrivateAssets="all" />
</ItemGroup>

<ItemGroup Label="DependencyPackaging">
<None Include="$(OutputPath)/netstandard2.0/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="$(OutputPath)/$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#nullable enable
#pragma warning disable

// <auto-generated />
namespace @Namespace
{
[global::System.Diagnostics.DebuggerDisplay("{DebuggerDisplay}")]
Expand Down
4 changes: 3 additions & 1 deletion src/Qowaiv.CodeGeneration.SingleValueObjects/SvoGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
}

/// <summary>Collects the SVO parameters.</summary>
[Pure]
private SvoParameters Collect(GeneratorAttributeSyntaxContext context, CancellationToken token)
{
token.ThrowIfCancellationRequested();
Expand All @@ -32,10 +33,10 @@ private SvoParameters Collect(GeneratorAttributeSyntaxContext context, Cancellat
};
}

/// <inheritdoc />
/// <remarks>
/// Currently, all syntax nodes are accepted.
/// </remarks>
[Pure]
private static bool Filter(SyntaxNode node, CancellationToken token)
{
token.ThrowIfCancellationRequested();
Expand All @@ -53,6 +54,7 @@ private static void Generate(SourceProductionContext context, ImmutableArray<Svo
}

/// <summary>Gets the full name of <see cref="ITypeSymbol"/>.</summary>
[Pure]
private static string FullName(ITypeSymbol symbol)
=> symbol.ContainingType is ITypeSymbol containing
? $"{FullName(containing)}.{symbol.Name}"
Expand Down
8 changes: 6 additions & 2 deletions src/Qowaiv.CodeGeneration.SingleValueObjects/SvoParameters.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
namespace Qowaiv.CodeGeneration.SingleValueObjects;

public sealed class SvoParameters
/// <summary>The parameters for the SVO generator.</summary>
public sealed record SvoParameters
{
/// <summary>The (type) name of the SVO.</summary>
public required string Svo { get; init; }

/// <summary>Namespace of the SVO.</summary>
public required Namespace Namespace { get; init; }


/// <summary>The (full name) of the SVO behavior.</summary>
public required string Behavior { get; init; }
}
3 changes: 1 addition & 2 deletions src/Qowaiv.CodeGeneration.SingleValueObjects/SvoTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ public void WriteTo(CSharpWriter writer) => Guard.NotNull(writer)
.Transform(line => line
.Replace("@Svo", Parameters.Svo)
.Replace("@Behavior", Parameters.Behavior)
.Replace("@Namespace", Parameters.Namespace.ToString())
));
.Replace("@Namespace", Parameters.Namespace.ToString())));

/// <inheritdoc />
[Pure]
Expand Down
2 changes: 2 additions & 0 deletions src/Qowaiv.CodeGeneration/Nill.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace Qowaiv.CodeGeneration;

/// <summary>Represents <c>null</c>.</summary>
public sealed class Nill
{
/// <summary>Represents <c>null</c>.</summary>
public static readonly Nill Value = new();
}
11 changes: 9 additions & 2 deletions src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

Check warning on line 1 in src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj

View workflow job for this annotation

GitHub Actions / build

Enable SBOM generation with <GenerateSBOM> is 'true' or define the <IsPackable> node with value 'false' (https://dotnet-project-file-analyzers.github.io/rules/Proj0243.html)

Check warning on line 1 in src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj

View workflow job for this annotation

GitHub Actions / build

Define the <EnablePackageValidation> node with value 'true' or define the <IsPackable> node with value 'false' or define the <DevelopmentDependency> node with value 'false' (https://dotnet-project-file-analyzers.github.io/rules/Proj0240.html)

Check warning on line 1 in src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj

View workflow job for this annotation

GitHub Actions / build

Enable SBOM generation with <GenerateSBOM> is 'true' or define the <IsPackable> node with value 'false' (https://dotnet-project-file-analyzers.github.io/rules/Proj0243.html)

Check warning on line 1 in src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj

View workflow job for this annotation

GitHub Actions / build

Define the <EnablePackageValidation> node with value 'true' or define the <IsPackable> node with value 'false' or define the <DevelopmentDependency> node with value 'false' (https://dotnet-project-file-analyzers.github.io/rules/Proj0240.html)

<Import Project="../../props/package.props" />

Expand All @@ -8,12 +8,19 @@

<PropertyGroup>
<Version>0.0.1-alpha-031</Version>
<IsPackable>true</IsPackable>

Check warning on line 11 in src/Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj

View workflow job for this annotation

GitHub Actions / build

Property <IsPackable> has been previously defined with the same value (https://dotnet-project-file-analyzers.github.io/rules/Proj0012.html)
<PackageId>Qowaiv.CodeGeneration</PackageId>
<PackageReleaseNotes>
<ToBeReleased>
<![CDATA[
ToBeReleased
v1.0.0
- Extend Open API documentation with explicit example. #188
- Initial alpha release
]]>
</ToBeReleased>
<PackageReleaseNotes>
<![CDATA[
v0.0.1
- Initial version.
]]>
</PackageReleaseNotes>
</PropertyGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/Qowaiv.CodeGeneration/Syntax/DisableWarningsHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ internal DisableWarningsHeader() { }
public void WriteTo(CSharpWriter writer) => Guard.NotNull(writer)
.Line("#pragma warning disable")
.Line();

/// <inheritdoc />
[Pure]
public override string ToString() => this.Stringify();
}
10 changes: 10 additions & 0 deletions src/Qowaiv.CodeGeneration/Syntax/Headers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Qowaiv.CodeGeneration.Syntax;

/// <summary>File headers.</summary>
public static class Headers
{
/// <summary>
/// Provides a header to indicate that #pragma warnings have been disabled.
/// </summary>
public static readonly DisableWarningsHeader DisableWarnings = new();
}
26 changes: 17 additions & 9 deletions src/Qowaiv.CodeGeneration/Syntax/Literal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Nill or
null /*.........*/ => writer.Write("null"),
Type type /*....*/ => writer.Write("typeof(").Write(type).Write(')'),
bool boolean /*.*/ => writer.Write(boolean ? "true" : "false"),
int int32 /*....*/ => writer.Write(int32.ToString(CultureInfo.InvariantCulture)),
int int32 /*....*/ => writer.Write(Int32(int32)),
double dbl /*...*/ => writer.Write(Double(dbl)),
decimal dec /*..*/ => writer.Write(dec.ToString(CultureInfo.InvariantCulture)).Write('m'),
string str /*...*/ => writer.Write(String(str)),
Expand All @@ -29,15 +29,23 @@ Nill or
}

[Pure]
private static string Double(double dbl)
private static string Int32(int num) => num switch
{
if (dbl <= double.MinValue) return "double.MinValue";
else if (dbl >= double.MaxValue) return "double.MaxValue";
else if (double.IsNaN(dbl)) return "double.NaN";
else if (double.IsPositiveInfinity(dbl)) return "double.PositiveInfinity";
else if (double.IsNegativeInfinity(dbl)) return "double.NegativeInfinity";
else return dbl.ToString(CultureInfo.InvariantCulture);
}
int.MinValue /*...*/ => "int.MinValue",
int.MaxValue /*...*/ => "int.MaxValue",
_ => num.ToString(CultureInfo.InvariantCulture),
};

[Pure]
private static string Double(double dbl) => dbl switch
{
double.MinValue /*...*/ => "double.MinValue",
double.MaxValue /*...*/ => "double.MaxValue",
_ when double.IsNaN(dbl) /*...*/ => "double.NaN",
_ when double.IsPositiveInfinity(dbl) /*...*/ => "double.PositiveInfinity",
_ when double.IsNegativeInfinity(dbl) /*...*/ => "double.NegativeInfinity",
_ => dbl.ToString(CultureInfo.InvariantCulture),
};

[Pure]
private static string String(string str)
Expand Down
13 changes: 13 additions & 0 deletions src/Specs/Nill_specs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Qowaiv.CodeGeneration;

namespace Specs.Nill_specs;

public class Singlton
{
[Test]
public void Value()
{
var nill = Nill.Value;
nill.Should().BeSameAs(Nill.Value);
}
}
1 change: 1 addition & 0 deletions src/Specs/Properties/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
global using NUnit.Framework;
global using FluentAssertions;
24 changes: 0 additions & 24 deletions src/Specs/Qowaiv.Customization/SvoAttribute.cs

This file was deleted.

1 change: 0 additions & 1 deletion src/Specs/SVOs/SVO_Generation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using FluentAssertions;
using Qowaiv.Globalization;
using Qowaiv.Hashing;
using Qowaiv.OpenApi;
Expand Down
4 changes: 0 additions & 4 deletions src/Specs/SVOs/Svo.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
using Qowaiv.Customization;
using Qowaiv.OpenApi;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace Specs.SVOs;

Expand Down
6 changes: 5 additions & 1 deletion src/Specs/Specs.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

Check warning on line 1 in src/Specs/Specs.csproj

View workflow job for this annotation

GitHub Actions / build

This file is using UTF-8 encoding with BOM (https://dotnet-project-file-analyzers.github.io/rules/Proj3000.html)

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
Expand All @@ -25,6 +25,10 @@
<PackageReference Include="NUnit.Analyzers" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../Qowaiv.CodeGeneration/Qowaiv.CodeGeneration.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="../Qowaiv.CodeGeneration.SingleValueObjects/Qowaiv.CodeGeneration.SingleValueObjects.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
</ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/Specs/Syntax/DisableWarningsHeader_specs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Qowaiv.CodeGeneration.Syntax;

namespace Specs.Syntax.DisableWarningsHeader_specs;

public class Generates
{
[Test]
public void DisableWarnings()
=> Headers.DisableWarnings.ToString().Should().Be("#pragma warning disable\r\n\r\n");
}
63 changes: 63 additions & 0 deletions src/Specs/Syntax/Literal_specs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Qowaiv.CodeGeneration.Syntax;
using System;

namespace Specs.Syntax.Literal_specs;

public class Generates
{
[Test]
public void Null() => new Literal(null).ToString().Should().Be("null");

[Test]
public void Type() => new Literal(typeof(object)).ToString().Should().Be("typeof(object)");

[Test]
public void False() => new Literal(false).ToString().Should().Be("false");

[Test]
public void True() => new Literal(true).ToString().Should().Be("true");

[Test]
public void Int() => new Literal(42).ToString().Should().Be("42");

[Test]
public void Int_MinValue() => new Literal(int.MinValue).ToString().Should().Be("int.MinValue");
[Test]
public void Int_MaxValue() => new Literal(int.MaxValue).ToString().Should().Be("int.MaxValue");

[Test]
public void Decimal() => new Literal(42m).ToString().Should().Be("42m");

[Test]
public void Double() => new Literal(3.14).ToString().Should().Be("3.14");

[Test]
public void Double_MinValue() => new Literal(double.MinValue).ToString().Should().Be("double.MinValue");

[Test]
public void Double_MaxValue() => new Literal(double.MaxValue).ToString().Should().Be("double.MaxValue");

[Test]
public void Double_NaN() => new Literal(double.NaN).ToString().Should().Be("double.NaN");

[Test]
public void Double_NegativeInfinity() => new Literal(double.NegativeInfinity).ToString().Should().Be("double.NegativeInfinity");

[Test]
public void Double_PositiveInfinity() => new Literal(double.PositiveInfinity).ToString().Should().Be("double.PositiveInfinity");

[Test]
public void String() => new Literal("Hello, world!").ToString().Should().Be("\"Hello, world!\"");

[Test]
public void Enum() => new Literal(System.TypeCode.Empty).ToString().Should().Be("System.TypeCode.Empty");
}

public class Throws
{
[Test]
public void On_objects_lacking_literal_representation()
=> new object().Invoking(o => new Literal(o).ToString())
.Should().Throw<NotSupportedException>()
.WithMessage("Literals of type System.Object are not supported");
}