-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some SonarCloud warnings (#1138)
* r * hdr * sc * StyleCop.Analyzers
- Loading branch information
Showing
8 changed files
with
59 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// Copyright © WireMock.Net | ||
|
||
using System; | ||
using System.Net.Http.Headers; | ||
using System.Text; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
// Copyright © WireMock.Net | ||
|
||
// C# Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
// Copyright © WireMock.Net | ||
|
||
// C# Hello |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 39 additions & 19 deletions
58
src/WireMock.Net/Transformers/Handlebars/WireMockHandlebarsHelpers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
namespace WireMock.Transformers.Handlebars; | ||
|
||
internal static class WireMockHandlebarsHelpers | ||
{ | ||
internal static class WireMockHandlebarsHelpers | ||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler) | ||
{ | ||
public static void Register(IHandlebars handlebarsContext, IFileSystemHandler fileSystemHandler) | ||
// Register https://github.com/StefH/Handlebars.Net.Helpers | ||
HandlebarsHelpers.Register(handlebarsContext, o => | ||
{ | ||
// 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) | ||
{ | ||
o.CustomHelperPaths = new string[] | ||
if (!string.IsNullOrEmpty(path)) | ||
{ | ||
Directory.GetCurrentDirectory() | ||
#if !NETSTANDARD1_3 | ||
, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) | ||
#endif | ||
customHelperPaths.Add(path!); | ||
} | ||
.Distinct() | ||
.ToList(); | ||
} | ||
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) } | ||
}; | ||
}); | ||
} | ||
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters