mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-01-11 13:00:33 +01:00
Fix some SonarCloud warnings (#1138)
* r * hdr * sc * StyleCop.Analyzers
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
using System;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
// C# Hello
|
||||
@@ -1 +1,3 @@
|
||||
// Copyright © WireMock.Net
|
||||
|
||||
// C# Hello
|
||||
9
hdr.ps1
9
hdr.ps1
@@ -7,11 +7,12 @@ function Write-Header ($file) {
|
||||
$content = Get-Content $file -Raw # Using -Raw to read the entire file as a single string
|
||||
$filename = Split-Path -Leaf $file
|
||||
|
||||
# Check if the file content starts with the auto-generated line
|
||||
if ($content.TrimStart().StartsWith("// <auto-generated>")) {
|
||||
Write-Host "Skipping auto-generated file: $filename"
|
||||
if ($content.TrimStart().StartsWith($header.Trim())) {
|
||||
# Write-Host "Skipping existing: $filename"
|
||||
} elseif ($content.TrimStart().StartsWith("// <auto-generated>")) {
|
||||
# Write-Host "Skipping auto-generated file: $filename"
|
||||
} else {
|
||||
# If not an auto-generated file, prepend the header
|
||||
Write-Host "Prepend the header for file: $filename"
|
||||
Set-Content $file $header
|
||||
Add-Content $file $content -NoNewline # Writing back to the file without an extra newline
|
||||
}
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<!-- <PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference> -->
|
||||
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -11,14 +11,14 @@ namespace WireMock.Util;
|
||||
internal static class StringUtils
|
||||
{
|
||||
private static readonly string[] ValidUriSchemes =
|
||||
{
|
||||
[
|
||||
"ftp://",
|
||||
"http://",
|
||||
"https://"
|
||||
};
|
||||
];
|
||||
|
||||
private static readonly Func<string, (bool IsConverted, object ConvertedValue)>[] ConversionsFunctions =
|
||||
{
|
||||
[
|
||||
s => bool.TryParse(s, out var result) ? (true, result) : (false, s),
|
||||
s => int.TryParse(s, out var result) ? (true, result) : (false, s),
|
||||
s => long.TryParse(s, out var result) ? (true, result) : (false, s),
|
||||
@@ -36,7 +36,7 @@ internal static class StringUtils
|
||||
|
||||
return (false, s);
|
||||
}
|
||||
};
|
||||
];
|
||||
|
||||
public static (bool IsConverted, object ConvertedValue) TryConvertToKnownType(string value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user