Skip to content

Commit

Permalink
Added Analyzer rules for writing Api classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Oct 6, 2023
1 parent 17a3aba commit 6c6fcd4
Show file tree
Hide file tree
Showing 27 changed files with 2,144 additions and 390 deletions.
26 changes: 15 additions & 11 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,25 @@
<PropertyGroup>
<SignAssembly>false</SignAssembly>
<DelaySign>false</DelaySign>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<NoWarn>436,NU5125</NoWarn>
<Configurations>Debug;Release;ReleaseForDeploy</Configurations>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

<!-- Analyzers -->
<PropertyGroup>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn),1573,1574,1591,1712,1723</NoWarn>
</PropertyGroup>

<!-- Runs the analyzers (in memory) on build -->
<ItemGroup Condition="'$(IsTestProject)'!='true' AND '$(IsRoslynComponent)'!='true'">
<PackageReference Include="SaaStack.Tools.Analyzers.Core" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

<!-- Build configurations -->
<PropertyGroup>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<NoWarn>$(NoWarn),436,NU5125</NoWarn>
<Configurations>Debug;Release;ReleaseForDeploy</Configurations>
<Platforms>AnyCPU</Platforms>
<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>
<Platform Condition="'$(Platform)' == ''">AnyCPU</Platform>
</PropertyGroup>
Expand Down Expand Up @@ -95,11 +106,4 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<!-- Runs the analyzers (in memory) on build -->
<ItemGroup Condition="'$(IsTestProject)'!='true' AND '$(IsRoslynComponent)'!='true'">
<PackageReference Include="SaaStack.Tools.Analyzers.Core" Version="1.0.0">
<IncludeAssets>analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
51 changes: 51 additions & 0 deletions src/Infrastructure.WebApi.Common/ApiResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Common;
using Infrastructure.WebApi.Interfaces;

namespace Infrastructure.WebApi.Common;

/// <summary>
/// Defines an callback that relates a <see cref="PostResult{TResponse}" /> containing a
/// <see cref="TResource" />
/// </summary>
// ReSharper disable once UnusedTypeParameter
public delegate Result<PostResult<TResponse>, Error> ApiPostResult<TResource, TResponse>()
where TResource : class where TResponse : IWebResponse;

/// <summary>
/// Defines an callback that relates a <see cref="TResponse" /> containing a
/// <see cref="TResource" />
/// </summary>
// ReSharper disable once UnusedTypeParameter
public delegate Result<TResponse, Error> ApiResult<TResource, TResponse>()
where TResource : class where TResponse : IWebResponse;

/// <summary>
/// Defines an callback that relates a <see cref="EmptyResponse" />
/// </summary>
public delegate Result<EmptyResponse, Error> ApiEmptyResult();

/// <summary>
/// Provides a container with a <see cref="TResponse" /> and other attributes describing a
/// </summary>
/// <typeparam name="TResponse"></typeparam>
public class PostResult<TResponse>
where TResponse : IWebResponse
{
public PostResult(TResponse response, string? location = null)
{
Response = response;
Location = location;
}

public string? Location { get; }

public TResponse Response { get; }

/// <summary>
/// Converts the <see cref="response" /> into a <see cref="PostResult{TResponse}" />
/// </summary>
public static implicit operator PostResult<TResponse>(TResponse response)
{
return new PostResult<TResponse>(response);
}
}
47 changes: 0 additions & 47 deletions src/Infrastructure.WebApi.Common/HandlerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,6 @@

namespace Infrastructure.WebApi.Common;

/// <summary>
/// Defines an callback that relates a <see cref="PostResult{TResponse}" /> containing a
/// <see cref="TResource" />
/// </summary>
// ReSharper disable once UnusedTypeParameter
public delegate Result<PostResult<TResponse>, Error> ApiPostResult<TResource, TResponse>()
where TResource : class where TResponse : IWebResponse;

/// <summary>
/// Defines an callback that relates a <see cref="TResponse" /> containing a
/// <see cref="TResource" />
/// </summary>
// ReSharper disable once UnusedTypeParameter
public delegate Result<TResponse, Error> ApiResult<TResource, TResponse>()
where TResource : class where TResponse : IWebResponse;

/// <summary>
/// Defines an callback that relates a <see cref="EmptyResponse" />
/// </summary>
public delegate Result<EmptyResponse, Error> ApiEmptyResult();

/// <summary>
/// Provides a container with a <see cref="TResponse" /> and other attributes describing a
/// </summary>
/// <typeparam name="TResponse"></typeparam>
public class PostResult<TResponse>
where TResponse : IWebResponse
{
public PostResult(TResponse response, string? location = null)
{
Response = response;
Location = location;
}

public string? Location { get; }

public TResponse Response { get; }

/// <summary>
/// Converts the <see cref="response" /> into a <see cref="PostResult{TResponse}" />
/// </summary>
public static implicit operator PostResult<TResponse>(TResponse response)
{
return new PostResult<TResponse>(response);
}
}

public static class HandlerExtensions
{
/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions src/SaaStack.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeNamespaceBody/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=DuplicateResource/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=SeparateLocalFunctionsWithJumpStatement/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=UnusedType_002EGlobal/@EntryIndexedValue">WARNING</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOR/@EntryValue">Required</s:String>
Expand Down Expand Up @@ -133,6 +134,7 @@
&lt;/And&gt;
&lt;/Entry.Match&gt;
&lt;Entry.SortBy&gt;
&lt;Access/&gt;
&lt;Name /&gt;
&lt;/Entry.SortBy&gt;
&lt;/Entry&gt;
Expand All @@ -159,6 +161,7 @@
&lt;/Entry.Match&gt;
&lt;Entry.SortBy&gt;
&lt;Kind Order="Constant Field" /&gt;
&lt;Access/&gt;
&lt;Name /&gt;
&lt;/Entry.SortBy&gt;
&lt;/Entry&gt;
Expand All @@ -172,6 +175,7 @@
&lt;/And&gt;
&lt;/Entry.Match&gt;
&lt;Entry.SortBy&gt;
&lt;Access/&gt;
&lt;Readonly /&gt;
&lt;Name /&gt;
&lt;/Entry.SortBy&gt;
Expand Down Expand Up @@ -373,10 +377,12 @@ public void When$condition$_Then$outcome$()
<s:Boolean x:Key="/Default/UserDictionary/Words/=aname/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Anding/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=anid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=anotherresource/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=anothervalue/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=apattern/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aproperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=areplacement/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aresource/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=aresourceref/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=asort/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=asortfield/@EntryIndexedValue">True</s:Boolean>
Expand Down
Loading

0 comments on commit 6c6fcd4

Please sign in to comment.