mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-26 02:08:29 +02:00
Fix some SonarCloud warnings (#1138)
* r * hdr * sc * StyleCop.Analyzers
This commit is contained in:
@@ -4,7 +4,7 @@ using HandlebarsDotNet;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars;
|
||||
|
||||
interface IHandlebarsContext : ITransformerContext
|
||||
internal interface IHandlebarsContext : ITransformerContext
|
||||
{
|
||||
IHandlebars Handlebars { get; }
|
||||
}
|
||||
@@ -1,38 +1,58 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using HandlebarsDotNet;
|
||||
using HandlebarsDotNet.Helpers;
|
||||
using HandlebarsDotNet.Helpers.Helpers;
|
||||
using WireMock.Handlers;
|
||||
|
||||
namespace WireMock.Transformers.Handlebars
|
||||
{
|
||||
internal static class WireMockHandlebarsHelpers
|
||||
{
|
||||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
|
||||
{
|
||||
// Register https://github.com/StefH/Handlebars.Net.Helpers
|
||||
HandlebarsHelpers.Register(handlebarsContext, o =>
|
||||
{
|
||||
o.CustomHelperPaths = new string[]
|
||||
{
|
||||
Directory.GetCurrentDirectory()
|
||||
#if !NETSTANDARD1_3
|
||||
, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)
|
||||
#endif
|
||||
}
|
||||
.Distinct()
|
||||
.ToList();
|
||||
namespace WireMock.Transformers.Handlebars;
|
||||
|
||||
o.CustomHelpers = new Dictionary<string, IHelpers>
|
||||
internal static class WireMockHandlebarsHelpers
|
||||
{
|
||||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler)
|
||||
{
|
||||
// Register https://github.com/StefH/Handlebars.Net.Helpers
|
||||
HandlebarsHelpers.Register(handlebarsContext, o =>
|
||||
{
|
||||
var paths = new List<string>
|
||||
{
|
||||
Directory.GetCurrentDirectory(),
|
||||
GetBaseDirectory(),
|
||||
};
|
||||
|
||||
#if !NETSTANDARD1_3_OR_GREATER
|
||||
void Add(string? path, ICollection<string> customHelperPaths)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
{ "File", new FileHelpers(handlebarsContext, fileSystemHandler) }
|
||||
};
|
||||
});
|
||||
}
|
||||
customHelperPaths.Add(path!);
|
||||
}
|
||||
}
|
||||
Add(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location), paths);
|
||||
Add(Path.GetDirectoryName(Assembly.GetCallingAssembly().Location), paths);
|
||||
Add(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), paths);
|
||||
Add(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule?.FileName), paths);
|
||||
#endif
|
||||
o.CustomHelperPaths = paths;
|
||||
|
||||
o.CustomHelpers = new Dictionary<string, IHelpers>
|
||||
{
|
||||
{ "File", new FileHelpers(handlebarsContext, fileSystemHandler) }
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private static string GetBaseDirectory()
|
||||
{
|
||||
#if NETSTANDARD1_3_OR_GREATER || NET6_0_OR_GREATER
|
||||
return AppContext.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
|
||||
#else
|
||||
return AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user