Skip to content

Commit

Permalink
Merge pull request #44 from SeferMirza/issue/stylecop-analyzers
Browse files Browse the repository at this point in the history
Issue / Stylecop Analyzers
  • Loading branch information
SeferMirza authored Sep 1, 2023
2 parents 238cdea + 2de75c4 commit 9312cbf
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 66 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Collective. It is, and will always be, free and open source.
- ⛔ Wrong => `private int _id;`
- ✅ Correct => `int _id;`
- Don't use `[TestFixture]` attribute, nunit runs tests without it anyway
- Refer to [Stylecop.Analyzers](https://github.com/mouseless/learn-dotnet/tree/main/analyzers/README.md)
for coding standards we enforce using `Stylecop Analyzers`.

## Naming Conventions

Expand Down
11 changes: 11 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<CodeAnalysisRuleSet>../../../stylecop.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.507">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Using Include="System" />
<Using Include="System.Linq" />
Expand Down
21 changes: 12 additions & 9 deletions Do.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,31 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2F297832-93E
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "blueprints", "blueprints", "{CDC3A00A-52BD-4CDA-B7D7-1FCFC5DD1CEE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Blueprints.Service.Application", "src\blueprints\Do.Blueprints.Service.Application\Do.Blueprints.Service.Application.csproj", "{AAF123F9-BEAB-42D0-84AD-DFBD6CE7A9A9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Blueprints.Service.Application", "src\blueprints\Do.Blueprints.Service.Application\Do.Blueprints.Service.Application.csproj", "{AAF123F9-BEAB-42D0-84AD-DFBD6CE7A9A9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{C407EF64-970A-498F-989D-17BBEF83B36F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "blueprints", "blueprints", "{F1F041D0-E073-455C-96F9-233FDF5CC2A8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Test.Blueprints.Service.Application", "test\blueprints\Do.Test.Blueprints.Service.Application\Do.Test.Blueprints.Service.Application.csproj", "{F8B3EFE9-7BC4-48C3-98D8-97500A2486C6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Test.Blueprints.Service.Application", "test\blueprints\Do.Test.Blueprints.Service.Application\Do.Test.Blueprints.Service.Application.csproj", "{F8B3EFE9-7BC4-48C3-98D8-97500A2486C6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{FC5EA7BE-2E36-4CC7-8CE0-DD8D69F8CF85}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Architecture", "src\core\Do.Architecture\Do.Architecture.csproj", "{D24161F5-5B89-4EE5-94D3-660E9BC94CFA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Architecture", "src\core\Do.Architecture\Do.Architecture.csproj", "{D24161F5-5B89-4EE5-94D3-660E9BC94CFA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "core", "core", "{BE392BCA-BDD7-43F6-BF11-9AC259F82CE6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Test.Architecture", "test\core\Do.Test.Architecture\Do.Test.Architecture.csproj", "{45D92BDD-5EA8-4B6C-A6F0-38C9DE139A32}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Test.Architecture", "test\core\Do.Test.Architecture\Do.Test.Architecture.csproj", "{45D92BDD-5EA8-4B6C-A6F0-38C9DE139A32}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Blueprints.Service", "src\blueprints\Do.Blueprints.Service\Do.Blueprints.Service.csproj", "{68CBB995-C501-41BB-93B4-01A0CC618A89}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Blueprints.Service", "src\blueprints\Do.Blueprints.Service\Do.Blueprints.Service.csproj", "{68CBB995-C501-41BB-93B4-01A0CC618A89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Do.Test.Blueprints.Service", "test\blueprints\Do.Test.Blueprints.Service\Do.Test.Blueprints.Service.csproj", "{063A65CC-F465-4E53-816E-048E05BC3F75}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Do.Test.Blueprints.Service", "test\blueprints\Do.Test.Blueprints.Service\Do.Test.Blueprints.Service.csproj", "{063A65CC-F465-4E53-816E-048E05BC3F75}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{AAF123F9-BEAB-42D0-84AD-DFBD6CE7A9A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AAF123F9-BEAB-42D0-84AD-DFBD6CE7A9A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -61,6 +58,9 @@ Global
{063A65CC-F465-4E53-816E-048E05BC3F75}.Release|Any CPU.ActiveCfg = Release|Any CPU
{063A65CC-F465-4E53-816E-048E05BC3F75}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CDC3A00A-52BD-4CDA-B7D7-1FCFC5DD1CEE} = {2F297832-93E6-4750-9141-818873A769F6}
{AAF123F9-BEAB-42D0-84AD-DFBD6CE7A9A9} = {CDC3A00A-52BD-4CDA-B7D7-1FCFC5DD1CEE}
Expand All @@ -73,4 +73,7 @@ Global
{68CBB995-C501-41BB-93B4-01A0CC618A89} = {CDC3A00A-52BD-4CDA-B7D7-1FCFC5DD1CEE}
{063A65CC-F465-4E53-816E-048E05BC3F75} = {F1F041D0-E073-455C-96F9-233FDF5CC2A8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F41E6823-793F-4036-A795-DB6105039AEC}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.Extensions.Configuration;
using Do.Configuration;
using Microsoft.Extensions.Configuration;

namespace Do;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void Configure(LayerConfigurator configurator)
{
string[] splitedNamespace = t.Namespace?.Split(".") ?? new string[0];
string name = t.IsNested && t.FullName is not null
? t.FullName.Replace($"{t.Namespace}.", "").Replace("Controller", "").Replace("+", ".")
? t.FullName.Replace($"{t.Namespace}.", string.Empty).Replace("Controller", string.Empty).Replace("+", ".")
: t.Name;

return splitedNamespace.Length > 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public void Apply(OpenApiOperation operation, OperationFilterContext context)
property.Type = "object";
}
}
};
}
}
}
2 changes: 1 addition & 1 deletion src/blueprints/Do.Blueprints.Service/Orm/IEntityContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
public interface IEntityContext<TEntity>
{
TEntity Insert(TEntity entity);
void Delete(TEntity entity);
void Delete(TEntity entity);
}
6 changes: 3 additions & 3 deletions src/blueprints/Do.Blueprints.Service/Orm/IQueryContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IQueryContext<TEntity>
) => Query(where,
orderBy: orderBy,
orderByDescending: orderByDescending
).FirstOrDefault();
).FirstOrDefault();

public List<TEntity> By(Expression<Func<TEntity, bool>> where) =>
Query(where).ToList();
Expand All @@ -30,7 +30,7 @@ public List<TEntity> By<TOrderBy>(Expression<Func<TEntity, bool>> where,
) => Query(where,
orderBy: orderBy,
orderByDescending: orderByDescending
).ToList();
).ToList();

public List<TEntity> All() => Query().ToList();

Expand All @@ -40,7 +40,7 @@ public List<TEntity> All<TOrderBy>(
) => Query(t => true,
orderBy: orderBy,
orderByDescending: orderByDescending
).ToList();
).ToList();

IQueryable<TEntity> Query(Expression<Func<TEntity, bool>> where) =>
Query().Where(where);
Expand Down
9 changes: 6 additions & 3 deletions src/core/Do.Architecture/Architecture/PhaseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void IPhase.Initialize(ApplicationContext context)

public abstract class PhaseBase<T> : PhaseBase
{
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal) : base(order: order) { }
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal)
: base(order: order) { }

protected override sealed bool IsReady() => Context.Has<T>();
protected override sealed void Initialize() => Initialize(Context.Get<T>());
Expand All @@ -40,7 +41,8 @@ protected PhaseBase(PhaseOrder order = PhaseOrder.Normal) : base(order: order) {

public abstract class PhaseBase<T1, T2> : PhaseBase
{
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal) : base(order: order) { }
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal)
: base(order: order) { }

protected override sealed bool IsReady() => Context.Has<T1>() && Context.Has<T2>();
protected override sealed void Initialize() => Initialize(Context.Get<T1>(), Context.Get<T2>());
Expand All @@ -50,7 +52,8 @@ protected PhaseBase(PhaseOrder order = PhaseOrder.Normal) : base(order: order) {

public abstract class PhaseBase<T1, T2, T3> : PhaseBase
{
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal) : base(order: order) { }
protected PhaseBase(PhaseOrder order = PhaseOrder.Normal)
: base(order: order) { }

protected override sealed bool IsReady() => Context.Has<T1>() && Context.Has<T2>() && Context.Has<T3>();
protected override sealed void Initialize() => Initialize(Context.Get<T1>(), Context.Get<T2>(), Context.Get<T3>());
Expand Down
7 changes: 6 additions & 1 deletion src/core/Do.Architecture/Architecture/PhaseContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ public PhaseContextBuilder Add<TTarget1, TTarget2, TTarget3>(TTarget1 target1, T
return this;
}

public PhaseContextBuilder OnDispose(Action? onDispose) { _onDispose = onDispose; return this; }
public PhaseContextBuilder OnDispose(Action? onDispose)
{
_onDispose = onDispose;

return this;
}

public PhaseContext Build() => new(_configurators) { OnDispose = _onDispose };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
namespace Do.Branding;

public sealed class DoBanner : IBanner
{
public void Print()
{
var assembly = GetType().Assembly;
var version = assembly.GetName().Version ?? new(0, 0, 0);
var ver = $"{version.Major}.{version.Minor}.{version.Build}";

var brand = ConsoleColor.DarkRed;
var white = ConsoleColor.White;
var foreground = ConsoleColor.Gray;
var border = ConsoleColor.DarkGray;

L("----------------------------------------------", border);
L();
W(" "); W("██", brand); L(" ████████ ██████████", white);
W(" "); W("██", brand); L(" ██ ██ ██ ██", white);
W(" "); W("██", brand); L(" ██ ██ ██ ██", white);
W(" "); W("██", brand); L(" ██ ██ ██ ██", white);
W(" "); W("██", brand); W(" ████████ ██████████ ", white); L("██████████", brand);
L();
L("------------------- v$VER$ -------------------".Replace("$VER$", ver), border);
L();
L("Docs: https://do.mouseless.codes", foreground);
L("Source: https://github.com/mouseless/do", foreground);
L();
L("----------------------------------------------", border);
}

static void L(string? message = default, ConsoleColor? color = default) => W($"{message ?? string.Empty}{Environment.NewLine}", color);
static void W(string message, ConsoleColor? color = default)
{
color ??= Console.ForegroundColor;

var old = Console.ForegroundColor;

Console.ForegroundColor = color.Value;
Console.Write(message);

Console.ForegroundColor = old;
}
}
namespace Do.Branding;

public sealed class DoBanner : IBanner
{
public void Print()
{
var assembly = GetType().Assembly;
var version = assembly.GetName().Version ?? new(0, 0, 0);
var ver = $"{version.Major}.{version.Minor}.{version.Build}";

var brand = ConsoleColor.DarkRed;
var white = ConsoleColor.White;
var foreground = ConsoleColor.Gray;
var border = ConsoleColor.DarkGray;

L("----------------------------------------------", border);
L();
W(" ").W("██", brand).L(" ████████ ██████████", white);
W(" ").W("██", brand).L(" ██ ██ ██ ██", white);
W(" ").W("██", brand).L(" ██ ██ ██ ██", white);
W(" ").W("██", brand).L(" ██ ██ ██ ██", white);
W(" ").W("██", brand).W(" ████████ ██████████ ", white).L("██████████", brand);
L();
L("------------------- v$VER$ -------------------".Replace("$VER$", ver), border);
L();
L("Docs: https://do.mouseless.codes", foreground);
L("Source: https://github.com/mouseless/do", foreground);
L();
L("----------------------------------------------", border);
}

DoBanner L(string? message = default, ConsoleColor? color = default) => W($"{message ?? string.Empty}{Environment.NewLine}", color);
DoBanner W(string message, ConsoleColor? color = default)
{
color ??= Console.ForegroundColor;

var old = Console.ForegroundColor;

Console.ForegroundColor = color.Value;
Console.Write(message);

Console.ForegroundColor = old;

return this;
}
}
Loading

0 comments on commit 9312cbf

Please sign in to comment.