Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Sep 13, 2024
1 parent 754b1c9 commit c1d2e3e
Show file tree
Hide file tree
Showing 412 changed files with 17,001 additions and 16,719 deletions.
17 changes: 9 additions & 8 deletions build/Benchmarks/Analyzer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable MemberCanBeMadeStatic.Global

namespace Build.Benchmarks;

[SuppressMessage("Performance", "CA1822:Mark members as static")]
Expand All @@ -19,7 +20,7 @@ public bool Analyze(IEnumerable<Benchmark> benchmarks, params Thresholds[] thres
Error($"Cannot find baseline method \"{threshold.BenchmarkMethod}\" in \"{benchmarkType}\".");
return false;
}

if (!methods.TryGetValue(threshold.BaselineMethod, out var baselineBenchmark))
{
Error($"Cannot find baseline method \"{threshold.BaselineMethod}\" in \"{benchmarkType}\".");
Expand All @@ -34,7 +35,7 @@ public bool Analyze(IEnumerable<Benchmark> benchmarks, params Thresholds[] thres
benchmark.Statistics.Mean,
benchmarkType,
threshold.BenchmarkMethod);

status |= CheckThreshold(
"bytes allocated per operation",
threshold.WarningBytesAllocatedPerOperationRatio,
Expand All @@ -45,10 +46,10 @@ public bool Analyze(IEnumerable<Benchmark> benchmarks, params Thresholds[] thres
threshold.BenchmarkMethod);
}
}

return status;
}

private static bool CheckThreshold(string name, double? warningThreshold, double? errorThreshold, double baseline, double value, string benchmarkType, string benchmarkMethod)
{
var ratio = value / baseline;
Expand All @@ -57,14 +58,14 @@ private static bool CheckThreshold(string name, double? warningThreshold, double
Error(CreateMessage(name, errorThreshold, ratio, benchmarkType, benchmarkMethod, "must"));
return false;
}

// ReSharper disable once InvertIf
if (warningThreshold > double.Epsilon && ratio > warningThreshold)
{
Warning(CreateMessage(name, warningThreshold, ratio, benchmarkType, benchmarkMethod, "could"));
return true;
}

return true;
}

Expand All @@ -74,6 +75,6 @@ private static string CreateMessage(
double ratio,
string benchmarkType,
string benchmarkMethod,
string verb) =>
string verb) =>
$"The {benchmarkType} {benchmarkMethod} method {verb} meet a {name} ratio threshold of {thresholdRatio}, but it is currently {ratio:0.##}.";
}
}
2 changes: 1 addition & 1 deletion build/Benchmarks/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public readonly record struct Benchmark(
string Parameters = "",
string FullName = "",
Statistics Statistics = default,
MemoryStatistics Memory = default);
MemoryStatistics Memory = default);
1 change: 1 addition & 0 deletions build/Benchmarks/BenchmarksDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable ClassNeverInstantiated.Global

namespace Build.Benchmarks;

internal record BenchmarksDto(IReadOnlyCollection<Benchmark> Benchmarks);
2 changes: 1 addition & 1 deletion build/Benchmarks/MemoryStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ public readonly record struct MemoryStatistics(
int Gen1Collections = 0,
int Gen2Collections = 0,
int TotalOperations = 0,
int BytesAllocatedPerOperation = 0);
int BytesAllocatedPerOperation = 0);
2 changes: 1 addition & 1 deletion build/Benchmarks/Statistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ public readonly record struct Statistics(
double Variance = .0,
double StandardDeviation = .0,
double Skewness = .0,
double Kurtosis = .0);
double Kurtosis = .0);
2 changes: 1 addition & 1 deletion build/Benchmarks/Thresholds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ public readonly record struct Thresholds(
double? WarningTimeRatio = default,
double? WarningBytesAllocatedPerOperationRatio = default,
double? ErrorTimeRatio = default,
double? ErrorBytesAllocatedPerOperationRatio = default);
double? ErrorBytesAllocatedPerOperationRatio = default);
4 changes: 2 additions & 2 deletions build/CompatibilityCheckTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<IReadOnlyCollection<Package>> RunAsync(CancellationToken cance
DeleteNuGetPackageFromCache("Pure.DI", settings.NextVersion, Path.GetDirectoryName(generatorPackage.Path)!);
await new DotNetCustom("new", "install", "Pure.DI.Templates")
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();

string[] frameworks =
[
"net8.0",
Expand Down Expand Up @@ -58,7 +58,7 @@ public async Task<IReadOnlyCollection<Package>> RunAsync(CancellationToken cance

var tasks = new List<Task>();
tasks.AddRange(frameworks.Reverse().Select(framework => CompatibilityCheckAsync(generatorPackage.Path, framework, cancellationToken)));

// Libraries
var packages = new List<Package> { generatorPackage };
foreach (var library in libraries)
Expand Down
2 changes: 1 addition & 1 deletion build/DotNetEnv.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Build;

internal class DotNetEnv(Env env): IInitializable
internal class DotNetEnv(Env env) : IInitializable
{
public async Task InitializeAsync(CancellationToken cancellationToken)
{
Expand Down
4 changes: 2 additions & 2 deletions build/GeneratorTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class GeneratorTarget(
: IInitializable, ITarget<Package>
{
private const string PackagesDir = ".packages";

private string PackageName => $"Pure.DI.{settings.NextVersion}.nupkg";

public Task InitializeAsync(CancellationToken cancellationToken) => commands.RegisterAsync(
Expand Down Expand Up @@ -64,7 +64,7 @@ private async Task<string> CreateGeneratorPackageAsync(CodeAnalysis codeAnalysis
{
Directory.Delete(bin, true);
}

var obj = Path.Combine(projectDirectory, "obj");
if (Directory.Exists(obj))
{
Expand Down
2 changes: 1 addition & 1 deletion build/LibrariesTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public async Task<IReadOnlyCollection<Library>> RunAsync(CancellationToken cance
.Select(v => $"net{v.Version.Major}.{v.Version.Minor}")
.ToArray(),
["webapi"]),

new("Pure.DI.Abstractions",
new Package(GetPackagePath("Pure.DI.Abstractions", settings.NextVersion), false),
sdk.Versions
Expand Down
3 changes: 2 additions & 1 deletion build/PackTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ namespace Build;
internal class PackTarget(
Commands commands,
ITeamCityArtifactsWriter artifactsWriter,
[Tag(typeof(CompatibilityCheckTarget))] ITarget<IReadOnlyCollection<Package>> compatibilityCheckTarget)
[Tag(typeof(CompatibilityCheckTarget))]
ITarget<IReadOnlyCollection<Package>> compatibilityCheckTarget)
: IInitializable, ITarget<IReadOnlyCollection<Package>>
{
public Task InitializeAsync(CancellationToken cancellationToken) => commands.RegisterAsync(
Expand Down
34 changes: 12 additions & 22 deletions build/PerformanceTestsTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public async Task<bool> RunAsync(CancellationToken cancellationToken)
"--", "--filter")
.AddArgs(Filters.Select(filter => filter).ToArray())
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();

foreach (var reportName in fileSystem.EnumerateFiles(tempDirectory, "*.json", SearchOption.AllDirectories))
{
await using var benchmarksJsonStream = fileSystem.OpenRead(reportName);
if (json.TryDeserialize<BenchmarksDto>(benchmarksJsonStream) is {} dto)
if (json.TryDeserialize<BenchmarksDto>(benchmarksJsonStream) is { } dto)
{
benchmarks.AddRange(dto.Benchmarks);
}
Expand All @@ -56,7 +56,7 @@ public async Task<bool> RunAsync(CancellationToken cancellationToken)
{
Directory.Delete(tempDirectory, true);
}

var baseThreshold = new Thresholds()
.WithWarningTimeRatio(1.4)
.WithWarningBytesAllocatedPerOperationRatio(1.00)
Expand All @@ -66,81 +66,71 @@ public async Task<bool> RunAsync(CancellationToken cancellationToken)
var rootThreshold = baseThreshold
.WithBaselineMethod("TestHandCoded")
.WithBenchmarkMethod("TestPureDIByCR");

var resolveThreshold = baseThreshold
.WithBaselineMethod("TestHandCoded")
.WithBenchmarkMethod("TestPureDI");

var objectResolveThreshold = baseThreshold
.WithBaselineMethod("TestHandCoded")
.WithBenchmarkMethod("TestPureDINonGeneric");

return analyzer.Analyze(
benchmarks,

// AddDisposable
new Thresholds(
"Pure.DI.Benchmarks.Tests.AddDisposableBenchmark",
"Baseline",
"AddDisposable")
.WithWarningBytesAllocatedPerOperationRatio(1.1)
.WithErrorBytesAllocatedPerOperationRatio(1.1),

// Resolve
new Thresholds(
"Pure.DI.Benchmarks.Tests.ResolveBenchmark",
"Baseline",
"Resolve")
.WithWarningTimeRatio(0.48)
.WithErrorTimeRatio(0.53),

// Transient
rootThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Transient"),

resolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Transient"),

objectResolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Transient"),

// Singleton
rootThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Singleton"),

resolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Singleton"),

objectResolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Singleton"),

// Func
rootThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Func"),

resolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Func"),

objectResolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Func"),

// Enum
rootThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Enum"),

resolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Enum"),

objectResolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Enum"),

// Array
rootThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Array"),

resolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Array"),

objectResolveThreshold
.WithType("Pure.DI.Benchmarks.Benchmarks.Array"));
}
Expand Down
4 changes: 1 addition & 3 deletions build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

DI.Setup(nameof(Composition))
.Root<RootTarget>("RootTarget")

.DefaultLifetime(Lifetime.PerBlock)

.Bind().To<RootCommand>()
.Bind().To<Settings>()
.Bind<ITeamCityArtifactsWriter>().To(_ => GetService<ITeamCityWriter>())
.Bind().To(_ => GetService<INuGet>())
.Bind(Tag.Type).To<DotNetEnv>()

// Targets
.Bind(Tag.Type).To<GeneratorTarget>()
.Bind(Tag.Type).To<LibrariesTarget>()
Expand Down
6 changes: 3 additions & 3 deletions build/PublishBlazorTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ public async Task<int> RunAsync(CancellationToken cancellationToken)
.WithConfiguration("Release")
.WithOutput(publishPath)
.RunAsync(cancellationToken: cancellationToken).EnsureSuccess();

// Change the base-tag in index.html from '/' to 'BlazorWebAssemblyApp' to match GitHub Pages repository subdirectory
var indexFile = Path.Combine(rootPath, "index.html");
var indexContent = await File.ReadAllTextAsync(indexFile, cancellationToken);
indexContent = indexContent.Replace("""<base href="/" />""", """<base href="/Pure.DI/" />""");
await File.WriteAllTextAsync(indexFile, indexContent, cancellationToken);

// Copy index.html to 404.html to serve the same file when a file is not found
File.Copy(indexFile, Path.Combine(rootPath, "404.html"));

// Add .nojekyll file to tell GitHub pages to not treat this as a Jekyll project. (Allow files and folders starting with an underscore)
await File.AppendAllTextAsync(Path.Combine(rootPath, ".nojekyll"), "", cancellationToken);

Expand Down
8 changes: 4 additions & 4 deletions build/ReadmeTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public async Task<int> RunAsync(CancellationToken cancellationToken)
await new DotNetTest(usageTestsProjects).RunAsync(cancellationToken: cancellationToken).EnsureSuccess();

await using var readmeWriter = File.CreateText(ReadmeFile);

await AddContentAsync(HeaderTemplateFile, readmeWriter);

await AddContentAsync(CommonReadmeFile, readmeWriter, "docs");
Expand Down Expand Up @@ -290,13 +290,13 @@ private async Task GenerateExamplesAsync(IEnumerable<(string GroupName, Dictiona
}

var exampleName = Path.GetFileNameWithoutExtension(vars[SourceKey]);

await AddExample(logsDirectory, $"Pure.DI.UsageTests.*.{exampleName}.*.g.cs", examplesWriter);
await examplesWriter.WriteLineAsync("");

await AddClassDiagram(logsDirectory, exampleName, examplesWriter);
await examplesWriter.WriteLineAsync("");

await examplesWriter.FlushAsync();
}
}
Expand Down
6 changes: 3 additions & 3 deletions build/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal class Settings(Properties properties, Versions versions)
public string Configuration => "Release";

public NuGetVersion CurrentVersion => _currentVersion.Value;

public NuGetVersion NextVersion
{
get
Expand All @@ -29,7 +29,7 @@ public NuGetVersion NextVersion
return version;
}

var currentVersion = _currentVersion.Value;
var currentVersion = _currentVersion.Value;
return new NuGetVersion(currentVersion.Major, currentVersion.Minor, currentVersion.Patch + 1);
}
}
Expand All @@ -42,6 +42,6 @@ public NuGetVersion NextVersion
new(new Version(4, 3, 1))
];

private static NuGetVersion GetVersion(Versions versions) =>
private static NuGetVersion GetVersion(Versions versions) =>
versions.GetNext(new NuGetRestoreSettings("Pure.DI"), VersionRange, 0);
}
7 changes: 4 additions & 3 deletions build/Tools/Commands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// ReSharper disable SuggestBaseTypeForParameterInConstructor
// ReSharper disable ClassNeverInstantiated.Global

namespace Build.Tools;

[SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly")]
Expand All @@ -17,12 +18,12 @@ public Task RegisterAsync<T>(
WriteLine($"---------- {description} ----------", Color.Highlighted);
return target.RunAsync(ctx.GetCancellationToken());
});

foreach (var alias in aliases)
{
command.AddAlias(alias);
command.AddAlias(alias);
}

rootCommand.AddCommand(command);
return Task.CompletedTask;
}
Expand Down
1 change: 1 addition & 0 deletions build/Tools/Env.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// ReSharper disable MemberCanBeMadeStatic.Global

namespace Build.Tools;

[SuppressMessage("Performance", "CA1822:Mark members as static")]
Expand Down
Loading

0 comments on commit c1d2e3e

Please sign in to comment.