Skip to content

Commit 9e9ad86

Browse files
authored
🧹 chore: [MegaLinter] Apply [1] automatic fixes (#94)
Co-authored-by: TylerCarrol <25536704+TylerCarrol@users.noreply.github.com>
1 parent 88f332d commit 9e9ad86

7 files changed

Lines changed: 73 additions & 47 deletions

File tree

‎TJC.Singleton.Tests/Mocks/Logging/MockLogger.cs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ internal class MockLogger : ILogger
77
public static MockLogger Default => new();
88

99
public IDisposable? BeginScope<TState>(TState state)
10-
where TState : notnull
11-
=> default!;
10+
where TState : notnull => default!;
1211

1312
public bool IsEnabled(LogLevel logLevel) => true;
1413

15-
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
14+
public void Log<TState>(
15+
LogLevel logLevel,
16+
EventId eventId,
17+
TState state,
18+
Exception? exception,
19+
Func<TState, Exception?, string> formatter
20+
)
1621
{
1722
Trace.WriteLine($"[{logLevel}:{eventId}] {formatter(state, exception)}");
1823
}
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
76
<IsPackable>false</IsPackable>
87
<IsTestProject>true</IsTestProject>
98
</PropertyGroup>
10-
119
<ItemGroup>
1210
<PackageReference Include="coverlet.collector" Version="6.0.2" />
1311
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
1412
<PackageReference Include="MSTest.TestAdapter" Version="3.6.1" />
1513
<PackageReference Include="MSTest.TestFramework" Version="3.6.1" />
1614
</ItemGroup>
17-
1815
<ItemGroup>
1916
<ProjectReference Include="..\TJC.Singleton\TJC.Singleton.csproj" />
2017
</ItemGroup>
21-
2218
<ItemGroup>
2319
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
2420
</ItemGroup>
25-
2621
</Project>

‎TJC.Singleton.Tests/Tests/Constructor/ConstructorTests.cs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@ public void PrivateConstructorIsInitialized()
1212
[TestMethod]
1313
public void NoConstructorThrowsException()
1414
{
15-
Assert.ThrowsException<InvalidSingletonConstructorException>(
16-
() => MockSingletonNoConstructor.Instance
15+
Assert.ThrowsException<InvalidSingletonConstructorException>(() =>
16+
MockSingletonNoConstructor.Instance
1717
);
1818
}
1919

2020
[TestMethod]
2121
public void PublicParameterlessConstructorThrowsException()
2222
{
23-
Assert.ThrowsException<InvalidSingletonConstructorException>(
24-
() => MockSingletonPublicParameterLessConstructor.Instance
23+
Assert.ThrowsException<InvalidSingletonConstructorException>(() =>
24+
MockSingletonPublicParameterLessConstructor.Instance
2525
);
2626
}
2727

2828
[TestMethod]
2929
public void ProtectedConstructorWithParametersThrowsException()
3030
{
31-
Assert.ThrowsException<InvalidSingletonConstructorException>(
32-
() => MockSingletonProtectedConstructorWithParameters.Instance
31+
Assert.ThrowsException<InvalidSingletonConstructorException>(() =>
32+
MockSingletonProtectedConstructorWithParameters.Instance
3333
);
3434
}
3535

3636
[TestMethod]
3737
public void PrivateConstructorWithParametersThrowsException()
3838
{
39-
Assert.ThrowsException<InvalidSingletonConstructorException>(
40-
() => MockSingletonPrivateConstructorWithParameters.Instance
39+
Assert.ThrowsException<InvalidSingletonConstructorException>(() =>
40+
MockSingletonPrivateConstructorWithParameters.Instance
4141
);
4242
}
4343
}

‎TJC.Singleton/Factories/SingletonFactory.cs‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Microsoft.Extensions.Logging;
2-
using System.Reflection;
1+
using System.Reflection;
2+
using Microsoft.Extensions.Logging;
33
using TJC.Singleton.Helpers;
44

55
namespace TJC.Singleton.Factories;
66

7-
/// <summary>
8-
/// Factory for creating <seealso cref="SingletonBase{TDerivedClass}"/>'s.
7+
/// <summary>
8+
/// Factory for creating <seealso cref="SingletonBase{TDerivedClass}"/>'s.
99
/// </summary>
1010
public static class SingletonFactory
1111
{
@@ -24,11 +24,15 @@ private class PlaceholderSingleton : SingletonBase<PlaceholderSingleton>;
2424
/// <param name="logger"></param>
2525
/// <param name="logLevel"></param>
2626
/// <exception cref="Exception"></exception>
27-
public static void InstantiateAll(ILogger? logger = null, LogLevel logLevel = LogLevel.Trace, bool throwIfFailed = false)
27+
public static void InstantiateAll(
28+
ILogger? logger = null,
29+
LogLevel logLevel = LogLevel.Trace,
30+
bool throwIfFailed = false
31+
)
2832
{
2933
var failedToInstantiate = new List<string>();
3034
var singletons = GetSingletonTypes();
31-
35+
3236
logger?.Log(logLevel, "{count} Singletons Found", singletons.Count);
3337

3438
foreach (var singleton in singletons)
@@ -72,7 +76,7 @@ public static List<Type> GetSingletonTypes()
7276
/// <param name="logger"></param>
7377
/// <param name="logLevel"></param>
7478
/// <returns></returns>
75-
public static bool Instantiate<T>(ILogger? logger = null, LogLevel logLevel = LogLevel.Trace) =>
79+
public static bool Instantiate<T>(ILogger? logger = null, LogLevel logLevel = LogLevel.Trace) =>
7680
Instantiate(typeof(T), logger, logLevel);
7781

7882
/// <summary>
@@ -83,16 +87,25 @@ public static bool Instantiate<T>(ILogger? logger = null, LogLevel logLevel = Lo
8387
/// <param name="logLevel"></param>
8488
/// <returns></returns>
8589
/// <exception cref="Exception"></exception>
86-
private static bool Instantiate(this Type singleton, ILogger? logger = null, LogLevel logLevel = LogLevel.Trace)
87-
{
90+
private static bool Instantiate(
91+
this Type singleton,
92+
ILogger? logger = null,
93+
LogLevel logLevel = LogLevel.Trace
94+
)
95+
{
8896
logger?.Log(logLevel, "[{name}] Instantiating", singleton.Name);
8997
var instanceProp =
9098
singleton.GetProperty(
9199
InstanceName,
92100
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy
93101
) ?? throw new Exception($"[{singleton.Name}] does not have property [{InstanceName}]");
94102
var instanceValue = instanceProp.GetValue(singleton);
95-
logger?.Log(logLevel, "[{name}] {result}", singleton.Name, instanceValue != null ? "Instantiated" : "Failed to Instantiate");
103+
logger?.Log(
104+
logLevel,
105+
"[{name}] {result}",
106+
singleton.Name,
107+
instanceValue != null ? "Instantiated" : "Failed to Instantiate"
108+
);
96109
return instanceValue != null;
97110
}
98111
}

‎TJC.Singleton/Helpers/SingletonConstructorHelpers.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
namespace TJC.Singleton.Helpers;
55

6-
/// <summary>
7-
/// Helpers for constructing <seealso cref="SingletonBase{TDerivedClass}"/>.
6+
/// <summary>
7+
/// Helpers for constructing <seealso cref="SingletonBase{TDerivedClass}"/>.
88
/// </summary>
99
public static class SingletonConstructorHelpers
1010
{

‎TJC.Singleton/Helpers/SingletonIdentifierHelpers.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TJC.Singleton.Helpers;
22

3-
/// <summary>
4-
/// Helpers for identifying details about <seealso cref="SingletonBase{TDerivedClass}"/>.
3+
/// <summary>
4+
/// Helpers for identifying details about <seealso cref="SingletonBase{TDerivedClass}"/>.
55
/// </summary>
66
public static class SingletonIdentifierHelpers
77
{

‎TJC.Singleton/TJC.Singleton.csproj‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<Description>Singleton Base &amp; Singleton Factory</Description>
99
<Authors>Tyler Carrol</Authors>
1010
<PackageReadmeFile>README.md</PackageReadmeFile>
11-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
11+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1212
<PackageReleaseNotes>$([System.IO.File]::ReadAllText("$(MSBuildProjectDirectory)/../CHANGELOG.md"))</PackageReleaseNotes>
1313
<RepositoryUrl>https://github.com/TJC-Tools/TJC.Singleton</RepositoryUrl>
1414
<GenerateDocumentationFile>true</GenerateDocumentationFile>
15-
</PropertyGroup>
15+
</PropertyGroup>
1616
<!-- INCLUDED FILES -->
1717
<ItemGroup>
1818
<None Remove="Nuget.config" />
@@ -31,7 +31,7 @@
3131
<Pack>True</Pack>
3232
<PackagePath>\</PackagePath>
3333
</None>
34-
<EmbeddedResource Include="..\LICENSE" />
34+
<EmbeddedResource Include="..\LICENSE" />
3535
</ItemGroup>
3636
<!-- DEPENDENCIES -->
3737
<!-- TESTS -->
@@ -44,40 +44,48 @@
4444
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.7" />
4545
</ItemGroup>
4646
<!-- TASKS -->
47-
<UsingTask TaskName="ReadFileContent" TaskFactory="RoslynCodeTaskFactory" AssemblyName="Microsoft.Build.Tasks.Core">
47+
<UsingTask
48+
TaskName="ReadFileContent"
49+
TaskFactory="RoslynCodeTaskFactory"
50+
AssemblyName="Microsoft.Build.Tasks.Core"
51+
>
4852
<ParameterGroup>
4953
<FilePath ParameterType="System.String" Required="true" />
5054
<Content Output="true" ParameterType="System.String" />
5155
</ParameterGroup>
5256
<Task>
5357
<Using Namespace="System.IO" />
5458
<Code Type="Fragment" Language="cs">
55-
<![CDATA[
56-
Content = File.ReadAllText(FilePath);
59+
<![CDATA[
60+
Content = File.ReadAllText(FilePath);
5761
]]>
5862
</Code>
5963
</Task>
6064
</UsingTask>
61-
<UsingTask TaskName="AppendNewLineAndFile" TaskFactory="RoslynCodeTaskFactory" AssemblyName="Microsoft.Build.Tasks.Core">
65+
<UsingTask
66+
TaskName="AppendNewLineAndFile"
67+
TaskFactory="RoslynCodeTaskFactory"
68+
AssemblyName="Microsoft.Build.Tasks.Core"
69+
>
6270
<ParameterGroup>
6371
<File1 ParameterType="System.String" Required="true" />
6472
<File2 ParameterType="System.String" Required="true" />
6573
</ParameterGroup>
6674
<Task>
6775
<Using Namespace="System.IO" />
6876
<Code Type="Fragment" Language="cs">
69-
<![CDATA[
70-
var text = Environment.NewLine;
71-
text += "===========================================================";
72-
text += Environment.NewLine;
73-
text += Environment.NewLine;
74-
text += File.ReadAllText(File2);
75-
text += Environment.NewLine;
76-
File.AppendAllText(File1, text);
77+
<![CDATA[
78+
var text = Environment.NewLine;
79+
text += "===========================================================";
80+
text += Environment.NewLine;
81+
text += Environment.NewLine;
82+
text += File.ReadAllText(File2);
83+
text += Environment.NewLine;
84+
File.AppendAllText(File1, text);
7785
]]>
7886
</Code>
7987
</Task>
80-
</UsingTask>
88+
</UsingTask>
8189
<!-- PRE-PACK -->
8290
<Target Name="CustomSetup" BeforeTargets="_IntermediatePack">
8391
<Message Text="=== CUSTOM SETUP ===" Importance="high" />
@@ -99,6 +107,11 @@
99107
<!-- Cleanup License File -->
100108
<Target Name="RestoreLicenseFile">
101109
<Message Text="Restore License File Contents" Importance="high" />
102-
<WriteLinesToFile File="..\LICENSE" Lines="$(OriginalLicenseLines)" Overwrite="true" Encoding="UTF-8" />
110+
<WriteLinesToFile
111+
File="..\LICENSE"
112+
Lines="$(OriginalLicenseLines)"
113+
Overwrite="true"
114+
Encoding="UTF-8"
115+
/>
103116
</Target>
104117
</Project>

0 commit comments

Comments
 (0)