Skip to content

Commit

Permalink
Merge pull request #175 from BUTR/code-formatting/fix-codeformatting
Browse files Browse the repository at this point in the history
Automated PR to fix formatting errors
  • Loading branch information
Aragas authored Feb 19, 2024
2 parents 1152358 + 7ae1b9c commit b5cdc9e
Show file tree
Hide file tree
Showing 29 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.DependencyInjection;
namespace BUTR.Site.NexusMods.DependencyInjection;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class HostedServiceAttribute : Attribute, IToRegister { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.DependencyInjection;
namespace BUTR.Site.NexusMods.DependencyInjection;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class ScopedServiceAttribute<TInterface> : Attribute, IToRegister { }
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.DependencyInjection;
namespace BUTR.Site.NexusMods.DependencyInjection;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class SingletonServiceAttribute : Attribute, IToRegister { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BUTR.Site.NexusMods.DependencyInjection;
namespace BUTR.Site.NexusMods.DependencyInjection;

[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public sealed class TransientServiceAttribute<TInterface> : Attribute, IToRegister { }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace BUTR.Site.NexusMods.DependencyInjection;
namespace BUTR.Site.NexusMods.DependencyInjection;

public interface IToRegister { }
24 changes: 12 additions & 12 deletions src/BUTR.Site.NexusMods.DependencyInjection/SourceGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;

using System.Diagnostics.CodeAnalysis;
Expand Down Expand Up @@ -44,7 +44,7 @@ partial void ConfigureServicesPartial(IServiceCollection services)
{
var attributeData = GetAttributeData(typeSymbol);
if (attributeData?.AttributeClass is null) continue;

var interfaceSymbols = attributeData.AttributeClass.TypeArguments;

foreach (var interfaceSymbol in interfaceSymbols)
Expand All @@ -62,7 +62,7 @@ partial void ConfigureServicesPartial(IServiceCollection services)
""");
}
}

stringBuilder.Append("""

}
Expand All @@ -75,7 +75,7 @@ partial void ConfigureServicesPartial(IServiceCollection services)
private IEnumerable<INamedTypeSymbol> GetTypesWithIToRegisterAttributes(Compilation compilation)
{
var allTypes = GetAllTypes(compilation.GlobalNamespace);
var types = allTypes.Where(x =>
var types = allTypes.Where(x =>
x is { TypeKind: TypeKind.Class, IsAbstract: false } &&
x.GetAttributes().Any(a => a.AttributeClass?.Interfaces.Any(i => i.Name.Equals("IToRegister", StringComparison.OrdinalIgnoreCase)) == true)).ToList();
return types;
Expand All @@ -84,22 +84,22 @@ private IEnumerable<INamedTypeSymbol> GetTypesWithIToRegisterAttributes(Compilat
private IEnumerable<INamedTypeSymbol> GetAllTypes(INamespaceSymbol @namespace)
{
foreach (var type in @namespace.GetTypeMembers())
foreach (var nestedType in GetNestedTypes(type))
yield return nestedType;
foreach (var nestedType in GetNestedTypes(type))
yield return nestedType;

foreach (var nestedNamespace in @namespace.GetNamespaceMembers())
foreach (var type in GetAllTypes(nestedNamespace))
yield return type;
foreach (var type in GetAllTypes(nestedNamespace))
yield return type;
}

private IEnumerable<INamedTypeSymbol> GetNestedTypes(INamedTypeSymbol type)
{
yield return type;

foreach (var nestedType in type.GetTypeMembers().SelectMany(GetNestedTypes))
yield return nestedType;
}

private static string GetMethodName(INamedTypeSymbol attributeClass)
{
return attributeClass.Name switch
Expand All @@ -111,7 +111,7 @@ var x when x.StartsWith("HostedService") => "AddHostedService",
_ => throw new InvalidOperationException()
};
}

private static AttributeData? GetAttributeData(INamedTypeSymbol typeSymbol)
{
static IEnumerable<INamedTypeSymbol> GetAllInterfaces(INamedTypeSymbol? namedTypeSymbol)
Expand All @@ -125,7 +125,7 @@ static IEnumerable<INamedTypeSymbol> GetAllInterfaces(INamedTypeSymbol? namedTyp
typeSymbol = typeSymbol.BaseType;
}
}

return typeSymbol.GetAttributes().Where(a =>
{
return GetAllInterfaces(a.AttributeClass).Any(i => i.Name.Equals("IToRegister", StringComparison.OrdinalIgnoreCase));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Utils.Http.ApiResults;
using BUTR.Site.NexusMods.Server.Utils.Http.ApiResults;

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Utils.Http.ApiResults;
using BUTR.Site.NexusMods.Server.Utils.Http.ApiResults;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -14,7 +14,7 @@ namespace BUTR.Site.NexusMods.Server.Tests.ApiResult;
public class ApiResultProblemDetailsWriterTests
{
private ApiResult<object> ControllerMethod() => default!;

[Fact]
public void CanWrite_ReturnsTrue_WhenEndpointHasControllerActionDescriptor()
{
Expand Down Expand Up @@ -63,7 +63,7 @@ public void CanWrite_ReturnsFalse_WhenEndpointDoesNotHaveControllerActionDescrip
}

[Fact]
public async Task WriteAsync_ExecutesObjectResult_WhenCalled()
public async Task WriteAsync_ExecutesObjectResult_WhenCalledAsync()
{
// Arrange
var actionResultExecutorMock = new Mock<IActionResultExecutor<ObjectResult>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ private class MockCsvFile : ICsvFile
{
[Name("Test"), Index(0)]
public string Test { get; init; }

public static string GenerateFilename() => "mock.csv";
}

[Fact]
public void CanWriteType_ReturnsTrue_ForAssignableTypes()
{
Expand All @@ -37,7 +37,7 @@ public void CanWriteType_ReturnsFalse_ForNonAssignableTypes()
}

[Fact]
public async void WriteResponseBodyAsync_WritesSingleEntry_ToResponseBody()
public async Task WriteResponseBodyAsync_WritesSingleEntry_ToResponseBodyAsync()
{
var formatter = new ExportOutputFormatter<MockCsvFile>();
var context = new OutputFormatterWriteContext(
Expand All @@ -52,7 +52,7 @@ public async void WriteResponseBodyAsync_WritesSingleEntry_ToResponseBody()
}

[Fact]
public async void WriteResponseBodyAsync_WritesEnumerable_ToResponseBody()
public async Task WriteResponseBodyAsync_WritesEnumerable_ToResponseBodyAsync()
{
var formatter = new ExportOutputFormatter<MockCsvFile>();
var context = new OutputFormatterWriteContext(
Expand All @@ -67,7 +67,7 @@ public async void WriteResponseBodyAsync_WritesEnumerable_ToResponseBody()
}

[Fact]
public async void WriteResponseBodyAsync_ThrowsException_ForInvalidObjectType()
public async Task WriteResponseBodyAsync_ThrowsException_ForInvalidObjectTypeAsync()
{
var formatter = new ExportOutputFormatter<MockCsvFile>();
var context = new OutputFormatterWriteContext(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class ImmutableArrayExtensions
/// <param name="immutableArray">The immutable array to convert.</param>
/// <returns>A regular array containing the same elements as the immutable array.</returns>
public static T[] AsArray<T>(this ImmutableArray<T> immutableArray) => Unsafe.As<ImmutableArray<T>, T[]>(ref immutableArray);

/// <summary>
/// Converts a regular array to an <see cref="ImmutableArray{T}"/>.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static int BinarySearch<T, TKey>(this IList<T> instance, TKey itemKey, Fu
{
var mid = (start + end) / 2;
var result = keySelector(instance[mid]).CompareTo(itemKey);

if (result == 0)
return mid;
if (result < 0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.CrashReport.Bannerlord.Parser;
using BUTR.CrashReport.Bannerlord.Parser;
using BUTR.CrashReport.Models;
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.Server.Contexts;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.Server.Models;
using BUTR.Site.NexusMods.Server.Utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using AsmResolver.DotNet;
using AsmResolver.DotNet;
using AsmResolver.PE;

using Bannerlord.ModuleManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.Server.Models.Quartz;

using Quartz;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Caching.Distributed;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.DependencyInjection;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.CrashReport.Models;
using BUTR.CrashReport.Models;
using BUTR.Site.NexusMods.Server.Models;

using Microsoft.Extensions.Options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Options;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;

using System;
using System.Net.Http;
Expand Down Expand Up @@ -50,7 +50,7 @@ public GOGAuthClient(HttpClient httpClient)

var data = JsonSerializer.Deserialize<TokenResponse>(await response.Content.ReadAsStreamAsync(ct));
if (data is null) return null;

return new GOGOAuthTokens(data.UserId, data.AccessToken, data.RefreshToken, DateTimeOffset.UtcNow.AddMinutes(data.ExpiresIn ?? 0));
}

Expand All @@ -65,7 +65,7 @@ public GOGAuthClient(HttpClient httpClient)

var data = JsonSerializer.Deserialize<TokenResponse>(await response.Content.ReadAsStreamAsync(ct));
if (data is null) return null;

return new GOGOAuthTokens(data.UserId, data.AccessToken, data.RefreshToken, DateTimeOffset.UtcNow.AddMinutes(data.ExpiresIn ?? 0));
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;

using System;
using System.Collections.Generic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.Options;
using Microsoft.Extensions.Options;

using System;
using System.Net.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Options;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Models;
using BUTR.Site.NexusMods.Server.Models;
using BUTR.Site.NexusMods.Server.Models.NexusModsAPI;
using BUTR.Site.NexusMods.Server.Utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Models;
using BUTR.Site.NexusMods.Server.Models;

using HtmlAgilityPack;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using BUTR.Site.NexusMods.Server.Options;
using BUTR.Site.NexusMods.Server.Options;

using Microsoft.Extensions.Options;

Expand Down Expand Up @@ -86,7 +86,7 @@ public SteamAPIClient(HttpClient httpClient, IOptions<SteamAPIOptions> options)

var data = JsonSerializer.Deserialize<GetUserInfoRoot>(await response.Content.ReadAsStreamAsync(ct));
if (data is null) return null;

return new SteamUserInfo(data.Response.Players[0].Steamid, data.Response.Players[0].Personaname);
}

Expand All @@ -98,7 +98,7 @@ public async Task<bool> IsOwningGameAsync(string steamId, uint appId, Cancellati

var data = JsonSerializer.Deserialize<IsOwningGameRoot>(await response.Content.ReadAsStreamAsync(ct));
if (data is null) return false;

return data.Response.GameCount == 1;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading;
Expand Down
6 changes: 3 additions & 3 deletions src/BUTR.Site.NexusMods.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Startup(IConfiguration configuration)
}

partial void ConfigureServicesPartial(IServiceCollection services);

public void ConfigureServices(IServiceCollection services)
{
var userAgent = $"{_assemblyName.Name ?? "ERROR"} v{_assemblyName.Version?.ToString() ?? "ERROR"} (github.com/BUTR)";
Expand Down Expand Up @@ -172,7 +172,7 @@ public void ConfigureServices(IServiceCollection services)
client.BaseAddress = new Uri("https://embed.gog.com/");
client.DefaultRequestHeaders.Add("User-Agent", userAgent);
}).AddPolicyHandler(GetRetryPolicy());

services.AddQuartz(opt =>
{
opt.AddJobListener<IQuartzEventProviderService>(sp => sp.GetRequiredService<IQuartzEventProviderService>());
Expand Down Expand Up @@ -217,7 +217,7 @@ public void ConfigureServices(IServiceCollection services)
services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IEntityConfiguration), type));
foreach (var type in types.Where(x => x.BaseType!.GetGenericTypeDefinition() == typeof(BaseEntityConfiguration<>)))
services.TryAddEnumerable(ServiceDescriptor.Scoped(typeof(IEntityConfiguration), type));

services.AddDbContext<BaseAppDbContext>(ServiceLifetime.Scoped);
services.AddDbContextFactory<AppDbContextRead>(lifetime: ServiceLifetime.Scoped);
services.AddDbContextFactory<AppDbContextWrite>(lifetime: ServiceLifetime.Scoped);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static class ApiResultUtils
public static bool IsReturnTypeApiResult(MethodInfo? methodInfo)
{
if (methodInfo is null) return false;

var returnType = GetReturnType(methodInfo);

return returnType == typeof(ApiResult) || returnType.GetGenericTypeDefinition() == typeof(ApiResult<>);
Expand Down

0 comments on commit b5cdc9e

Please sign in to comment.