Skip to content

Commit 94a0bf5

Browse files
committed
style(core): clear Sonar/CodeQL smells on A5 new code
- Explicit types where the type is not apparent (IDE0008) in the config DI extensions. - Use Path.Join instead of Path.Combine in the directory test (avoids the cs/path-combine CodeQL alerts; Path.Join never drops earlier segments). - Hoist the expected names array to a static readonly field (CA1861). No behavior change; 51 green Core tests.
1 parent 3cad51c commit 94a0bf5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/NeoReports.Core/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static IServiceCollection AddReportFromConfig(this IServiceCollection ser
6363
ArgumentNullException.ThrowIfNull(configJson);
6464

6565
services.AddNeoReports();
66-
var config = new JsonReportConfigParser().Parse(configJson);
66+
ReportConfig config = new JsonReportConfigParser().Parse(configJson);
6767
services.AddSingleton(config);
6868
return services;
6969
}
@@ -91,7 +91,7 @@ public static IServiceCollection AddReportsFromConfigDirectory(
9191
if (!Directory.Exists(directory))
9292
throw new DirectoryNotFoundException($"Report config directory not found: {directory}");
9393

94-
foreach (var file in Directory.EnumerateFiles(directory, searchPattern).OrderBy(f => f, StringComparer.Ordinal))
94+
foreach (string file in Directory.EnumerateFiles(directory, searchPattern).OrderBy(f => f, StringComparer.Ordinal))
9595
services.AddReportFromConfig(File.ReadAllText(file));
9696

9797
return services;

tests/NeoReports.Core.UnitTests/DynamicConfigDiTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ namespace NeoReports.Core.UnitTests;
1717
/// </summary>
1818
public class DynamicConfigDiTests
1919
{
20+
private static readonly string[] AlphaBeta = { "alpha", "beta" };
21+
2022
private static string ConfigNamed(string name) => $$"""
2123
{
2224
"name": "{{name}}",
@@ -54,12 +56,12 @@ public async Task Registers_a_config_report_and_runs_it_by_name()
5456
[Fact]
5557
public void Loads_every_config_from_a_directory()
5658
{
57-
var directory = Path.Combine(Path.GetTempPath(), "nr-cfg-" + Guid.NewGuid().ToString("N"));
59+
var directory = Path.Join(Path.GetTempPath(), "nr-cfg-" + Guid.NewGuid().ToString("N"));
5860
Directory.CreateDirectory(directory);
5961
try
6062
{
61-
File.WriteAllText(Path.Combine(directory, "a.json"), ConfigNamed("alpha"));
62-
File.WriteAllText(Path.Combine(directory, "b.json"), ConfigNamed("beta"));
63+
File.WriteAllText(Path.Join(directory, "a.json"), ConfigNamed("alpha"));
64+
File.WriteAllText(Path.Join(directory, "b.json"), ConfigNamed("beta"));
6365

6466
var services = new ServiceCollection();
6567
services.AddLogging();
@@ -70,7 +72,7 @@ public void Loads_every_config_from_a_directory()
7072
using var provider = services.BuildServiceProvider();
7173

7274
var registry = provider.GetRequiredService<IReportRegistry>();
73-
registry.Names.ShouldBe(new[] { "alpha", "beta" }, ignoreOrder: true);
75+
registry.Names.ShouldBe(AlphaBeta, ignoreOrder: true);
7476
}
7577
finally
7678
{

0 commit comments

Comments
 (0)