Skip to content

Commit

Permalink
Automatically linting code
Browse files Browse the repository at this point in the history
  • Loading branch information
rsg-bot authored Dec 27, 2024
1 parent 511cb09 commit 476be52
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 38 deletions.
15 changes: 13 additions & 2 deletions src/Foundation/Rocket.Surgery.LaunchPad.Foundation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,18 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Telemetry\Rocket.Surgery.LaunchPad.Telemetry.csproj" />
<ProjectReference Include="..\Analyzers\Rocket.Surgery.LaunchPad.Analyzers.csproj" IncludeAssets="analyzers" ExcludeAssets="compile;runtime;native" PrivateAssets="contentfiles;build;buildMultitargeting;buildTransitive" OutputItemType="Analyzer" />
<PackageReference Include="Polyfill" IncludeAssets="runtime;build;buildMultitargeting;buildTransitive;native;contentfiles;analyzers" PrivateAssets="All" Condition="'$(TargetFramework)' == 'netstandard2.1'" />
<ProjectReference
Include="..\Analyzers\Rocket.Surgery.LaunchPad.Analyzers.csproj"
IncludeAssets="analyzers"
ExcludeAssets="compile;runtime;native"
PrivateAssets="contentfiles;build;buildMultitargeting;buildTransitive"
OutputItemType="Analyzer"
/>
<PackageReference
Include="Polyfill"
IncludeAssets="runtime;build;buildMultitargeting;buildTransitive;native;contentfiles;analyzers"
PrivateAssets="All"
Condition="'$(TargetFramework)' == 'netstandard2.1'"
/>
</ItemGroup>
</Project>
36 changes: 30 additions & 6 deletions src/Mapping/DateTimeMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,53 @@ namespace Rocket.Surgery.LaunchPad.Mapping;
/// </remarks>
[Mapper]
[PublicAPI]
[System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")]
public partial class DateTimeMapper
{
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
get
{
return ToString();
}
}

/// <summary>
/// Converts a <see cref="DateTime" /> to a <see cref="DateTimeOffset" />.
/// </summary>
/// <param name="source"></param>
/// <returns></returns>
public static DateTime FromDateTimeOffset(DateTimeOffset source)
{
return source.UtcDateTime;
}
public static DateTime FromDateTimeOffset(DateTimeOffset source) => source.UtcDateTime;

/// <summary>
/// Converts a <see cref="DateTimeOffset" /> to a <see cref="DateTime" />.
/// </summary>
/// <param name="source"></param>
/// <returns></returns>

/* Unmerged change from project 'Rocket.Surgery.LaunchPad.Mapping(net9.0)'
Before:
public static DateTimeOffset ToDateTimeOffset(DateTime source)
{
return source switch
{
{ Kind: DateTimeKind.Unspecified or DateTimeKind.Local, } => new(source.ToUniversalTime(), TimeSpan.Zero),
{ Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero),
};
}
}
}
After:
public static DateTimeOffset ToDateTimeOffset(DateTime source) => source switch
{
{ Kind: DateTimeKind.Unspecified or DateTimeKind.Local, } => new(source.ToUniversalTime(), TimeSpan.Zero),
{ Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero),
_ => throw new NotImplementedException(),
};
*/
public static DateTimeOffset ToDateTimeOffset(DateTime source) => source switch
{
{ Kind: DateTimeKind.Unspecified or DateTimeKind.Local, } => new(source.ToUniversalTime(), TimeSpan.Zero),
{ Kind: DateTimeKind.Utc, } => new(source, TimeSpan.Zero),
_ => throw new NotImplementedException(),
};
}
26 changes: 14 additions & 12 deletions src/Telemetry/Conventions/SerilogTelemetryConvention.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Rocket.Surgery.Conventions;
using Rocket.Surgery.Conventions.DependencyInjection;
using Rocket.Surgery.LaunchPad.Serilog;
Expand All @@ -17,15 +15,23 @@ namespace Rocket.Surgery.LaunchPad.Telemetry.Conventions;
/// </summary>
[PublicAPI]
[ConventionCategory(ConventionCategory.Core)]
[System.Diagnostics.DebuggerDisplay("{DebuggerDisplay,nq}")]
public partial class SerilogTelemetryConvention : ISerilogConvention, IServiceConvention
{
/// <inheritdoc />
public void Register(IConventionContext context, IConfiguration configuration, IServiceProvider services, LoggerConfiguration loggerConfiguration)
[System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
private string DebuggerDisplay
{
loggerConfiguration.WriteTo.OpenTelemetry(
get
{
return ToString();
}
}

/// <inheritdoc />
public void Register(IConventionContext context, IConfiguration configuration, IServiceProvider services, LoggerConfiguration loggerConfiguration) => loggerConfiguration.WriteTo.OpenTelemetry(
options =>
{
services.GetRequiredService<IOptions<OpenTelemetryLoggerOptions>>();
_ = services.GetRequiredService<IOptions<OpenTelemetryLoggerOptions>>();
var di = services.GetRequiredService<IOptionsMonitor<BatchedOpenTelemetrySinkOptions>>();
options.BatchingOptions.BatchSizeLimit = di.CurrentValue.BatchingOptions.BatchSizeLimit;
options.BatchingOptions.BufferingTimeLimit = di.CurrentValue.BatchingOptions.BufferingTimeLimit;
Expand All @@ -46,11 +52,7 @@ public void Register(IConventionContext context, IConfiguration configuration, I
options.TracesEndpoint = di.CurrentValue.TracesEndpoint;
}
);
}

/// <inheritdoc />
public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services)
{
services.AddOptions<BatchedOpenTelemetrySinkOptions>();
}
public void Register(IConventionContext context, IConfiguration configuration, IServiceCollection services) => services.AddOptions<BatchedOpenTelemetrySinkOptions>();
}
24 changes: 6 additions & 18 deletions test/Sample.Graphql.Tests/Helpers/GraphQlExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ internal class GraphQlExtension : IAlbaExtension
{
public void Dispose() { }

public ValueTask DisposeAsync()
{
return ValueTask.CompletedTask;
}
public ValueTask DisposeAsync() => ValueTask.CompletedTask;

public Task Start(IAlbaHost host)
{
return Task.CompletedTask;
}
public Task Start(IAlbaHost host) => Task.CompletedTask;

public IHostBuilder Configure(IHostBuilder builder)
{
Expand All @@ -50,7 +44,7 @@ public IHostBuilder Configure(IHostBuilder builder)
return builder;
}

public class CO(TestServer testServer) : PostConfigureOptions<HttpClientFactoryOptions>(Options.DefaultName, null)
internal class CO(TestServer testServer) : PostConfigureOptions<HttpClientFactoryOptions>(Options.DefaultName, null)
{
public override void PostConfigure(string? name, HttpClientFactoryOptions options)
{
Expand All @@ -66,18 +60,12 @@ public override void PostConfigure(string? name, HttpClientFactoryOptions option
}

[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class TestServerDiagnosticEventListener(ILogger<TestServerDiagnosticEventListener> logger) : ServerDiagnosticEventListener
internal class TestServerDiagnosticEventListener(ILogger<TestServerDiagnosticEventListener> logger) : ServerDiagnosticEventListener
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
private string DebuggerDisplay => ToString();

public override void HttpRequestError(HttpContext context, Exception exception)
{
logger.LogError(exception, "HttpRequestError");
}
public override void HttpRequestError(HttpContext context, Exception exception) => logger.LogError(exception, "HttpRequestError");

public override void HttpRequestError(HttpContext context, IError error)
{
logger.LogError(error.Exception, "HttpRequestError");
}
public override void HttpRequestError(HttpContext context, IError error) => logger.LogError(error.Exception, "HttpRequestError");
}

0 comments on commit 476be52

Please sign in to comment.