mirror of
https://github.com/wiremock/WireMock.Net.git
synced 2026-04-20 07:51:41 +02: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;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -1 +1,3 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
// C# Hello
|
// C# Hello
|
||||||
@@ -1 +1,3 @@
|
|||||||
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
// C# Hello
|
// 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
|
$content = Get-Content $file -Raw # Using -Raw to read the entire file as a single string
|
||||||
$filename = Split-Path -Leaf $file
|
$filename = Split-Path -Leaf $file
|
||||||
|
|
||||||
# Check if the file content starts with the auto-generated line
|
if ($content.TrimStart().StartsWith($header.Trim())) {
|
||||||
if ($content.TrimStart().StartsWith("// <auto-generated>")) {
|
# Write-Host "Skipping existing: $filename"
|
||||||
Write-Host "Skipping auto-generated file: $filename"
|
} elseif ($content.TrimStart().StartsWith("// <auto-generated>")) {
|
||||||
|
# Write-Host "Skipping auto-generated file: $filename"
|
||||||
} else {
|
} else {
|
||||||
# If not an auto-generated file, prepend the header
|
Write-Host "Prepend the header for file: $filename"
|
||||||
Set-Content $file $header
|
Set-Content $file $header
|
||||||
Add-Content $file $content -NoNewline # Writing back to the file without an extra newline
|
Add-Content $file $content -NoNewline # Writing back to the file without an extra newline
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,10 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</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="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
|
||||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using HandlebarsDotNet;
|
|||||||
|
|
||||||
namespace WireMock.Transformers.Handlebars;
|
namespace WireMock.Transformers.Handlebars;
|
||||||
|
|
||||||
interface IHandlebarsContext : ITransformerContext
|
internal interface IHandlebarsContext : ITransformerContext
|
||||||
{
|
{
|
||||||
IHandlebars Handlebars { get; }
|
IHandlebars Handlebars { get; }
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,58 @@
|
|||||||
// Copyright © WireMock.Net
|
// Copyright © WireMock.Net
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using HandlebarsDotNet;
|
using HandlebarsDotNet;
|
||||||
using HandlebarsDotNet.Helpers;
|
using HandlebarsDotNet.Helpers;
|
||||||
using HandlebarsDotNet.Helpers.Helpers;
|
using HandlebarsDotNet.Helpers.Helpers;
|
||||||
using WireMock.Handlers;
|
using WireMock.Handlers;
|
||||||
|
|
||||||
namespace WireMock.Transformers.Handlebars
|
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();
|
|
||||||
|
|
||||||
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
|
internal static class StringUtils
|
||||||
{
|
{
|
||||||
private static readonly string[] ValidUriSchemes =
|
private static readonly string[] ValidUriSchemes =
|
||||||
{
|
[
|
||||||
"ftp://",
|
"ftp://",
|
||||||
"http://",
|
"http://",
|
||||||
"https://"
|
"https://"
|
||||||
};
|
];
|
||||||
|
|
||||||
private static readonly Func<string, (bool IsConverted, object ConvertedValue)>[] ConversionsFunctions =
|
private static readonly Func<string, (bool IsConverted, object ConvertedValue)>[] ConversionsFunctions =
|
||||||
{
|
[
|
||||||
s => bool.TryParse(s, out var result) ? (true, result) : (false, s),
|
s => bool.TryParse(s, out var result) ? (true, result) : (false, s),
|
||||||
s => int.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),
|
s => long.TryParse(s, out var result) ? (true, result) : (false, s),
|
||||||
@@ -36,7 +36,7 @@ internal static class StringUtils
|
|||||||
|
|
||||||
return (false, s);
|
return (false, s);
|
||||||
}
|
}
|
||||||
};
|
];
|
||||||
|
|
||||||
public static (bool IsConverted, object ConvertedValue) TryConvertToKnownType(string value)
|
public static (bool IsConverted, object ConvertedValue) TryConvertToKnownType(string value)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user