refactor: Address several resharper analysis issues

pull/201/head
Robert Dailey 1 year ago
parent 39f106c72b
commit 29ca61f68f

@ -6,7 +6,7 @@ namespace Recyclarr.Cli.Tests.Migration.Steps;
[TestFixture] [TestFixture]
[Parallelizable(ParallelScope.All)] [Parallelizable(ParallelScope.All)]
public class MigrateTrashYmlTest public partial class MigrateTrashYmlTest
{ {
private static readonly string BasePath = AppContext.BaseDirectory; private static readonly string BasePath = AppContext.BaseDirectory;
@ -49,6 +49,9 @@ public class MigrateTrashYmlTest
sut.Execute(null); sut.Execute(null);
fs.AllFiles.Should().ContainSingle(x => Regex.IsMatch(x, @"[/\\]recyclarr\.yml$")); fs.AllFiles.Should().ContainSingle(x => RecyclarrYmlRegex().IsMatch(x));
} }
[GeneratedRegex("[/\\\\]recyclarr\\.yml$")]
private static partial Regex RecyclarrYmlRegex();
} }

@ -27,21 +27,25 @@ public class SyncCommand : AsyncCommand<SyncCommand.CliSettings>
{ {
[CommandArgument(0, "[service]")] [CommandArgument(0, "[service]")]
[EnumDescription<SupportedServices>("The service to sync. If not specified, all services are synced.")] [EnumDescription<SupportedServices>("The service to sync. If not specified, all services are synced.")]
public SupportedServices? Service { get; [UsedImplicitly] init; } [UsedImplicitly(ImplicitUseKindFlags.Assign)]
public SupportedServices? Service { get; init; }
[CommandOption("-c|--config")] [CommandOption("-c|--config")]
[Description("One or more YAML configuration files to load & use.")] [Description("One or more YAML configuration files to load & use.")]
[TypeConverter(typeof(FileInfoConverter))] [TypeConverter(typeof(FileInfoConverter))]
public IFileInfo[] ConfigsOption { get; [UsedImplicitly] init; } = Array.Empty<IFileInfo>(); [UsedImplicitly(ImplicitUseKindFlags.Assign)]
public IFileInfo[] ConfigsOption { get; init; } = Array.Empty<IFileInfo>();
public IReadOnlyCollection<IFileInfo> Configs => ConfigsOption; public IReadOnlyCollection<IFileInfo> Configs => ConfigsOption;
[CommandOption("-p|--preview")] [CommandOption("-p|--preview")]
[Description("Perform a dry run: preview the results without syncing.")] [Description("Perform a dry run: preview the results without syncing.")]
public bool Preview { get; [UsedImplicitly] init; } [UsedImplicitly(ImplicitUseKindFlags.Assign)]
public bool Preview { get; init; }
[CommandOption("-i|--instance")] [CommandOption("-i|--instance")]
[Description("One or more instance names to sync. If not specified, all instances will be synced.")] [Description("One or more instance names to sync. If not specified, all instances will be synced.")]
public string[] InstancesOption { get; [UsedImplicitly] init; } = Array.Empty<string>(); [UsedImplicitly(ImplicitUseKindFlags.Assign)]
public string[] InstancesOption { get; init; } = Array.Empty<string>();
public IReadOnlyCollection<string> Instances => InstancesOption; public IReadOnlyCollection<string> Instances => InstancesOption;
} }

@ -1,6 +1,5 @@
using System.Reflection; using System.Reflection;
using Autofac; using Autofac;
using Recyclarr.Common.FluentValidation;
using Module = Autofac.Module; using Module = Autofac.Module;
namespace Recyclarr.Common; namespace Recyclarr.Common;
@ -18,7 +17,6 @@ public class CommonAutofacModule : Module
{ {
builder.RegisterType<DefaultEnvironment>().As<IEnvironment>(); builder.RegisterType<DefaultEnvironment>().As<IEnvironment>();
builder.RegisterType<FileUtilities>().As<IFileUtilities>(); builder.RegisterType<FileUtilities>().As<IFileUtilities>();
builder.RegisterType<ValidatorFactory>();
builder.Register(_ => new ResourceDataReader(_rootAssembly)) builder.Register(_ => new ResourceDataReader(_rootAssembly))
.As<IResourceDataReader>(); .As<IResourceDataReader>();

@ -1,9 +1,11 @@
using System.Diagnostics.CodeAnalysis;
using System.IO.Abstractions; using System.IO.Abstractions;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Spectre.Console; using Spectre.Console;
namespace Recyclarr.Common.Extensions; namespace Recyclarr.Common.Extensions;
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
public static class FileSystemExtensions public static class FileSystemExtensions
{ {
public static void CreateParentDirectory(this IFileInfo f) public static void CreateParentDirectory(this IFileInfo f)

@ -1,31 +0,0 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Recyclarr.Common.Extensions;
public static class JsonNetExtensions
{
public static JEnumerable<T> Children<T>(this JToken token, string key)
where T : JToken
{
return token[key]?.Children<T>() ?? JEnumerable<T>.Empty;
}
public static T ValueOrThrow<T>(this JToken token, string key)
where T : class
{
var value = token.Value<T>(key);
if (value is null)
{
throw new ArgumentNullException(token.Path);
}
return value;
}
public static T Clone<T>(this T source) where T : notnull
{
return JsonConvert.DeserializeObject<T>(JsonConvert.SerializeObject(source))
?? throw new ArgumentException("Could not deep clone", nameof(source));
}
}

@ -1,8 +0,0 @@
using FluentValidation;
namespace Recyclarr.Common.FluentValidation;
public interface IValidatorFactory
{
IValidator GetValidator(Type typeToValidate);
}

@ -1,20 +0,0 @@
using Autofac;
using FluentValidation;
using Recyclarr.Common.Extensions;
namespace Recyclarr.Common.FluentValidation;
public class ValidatorFactory : IValidatorFactory
{
private readonly ILifetimeScope _scope;
public ValidatorFactory(ILifetimeScope scope)
{
_scope = scope;
}
public IValidator GetValidator(Type typeToValidate)
{
return (IValidator) _scope.ResolveGeneric(typeof(IValidator<>), typeToValidate);
}
}

@ -1,5 +1,8 @@
using System.Diagnostics.CodeAnalysis;
namespace Recyclarr.Common; namespace Recyclarr.Common;
[SuppressMessage("ReSharper", "ConvertIfStatementToReturnStatement")]
public sealed class GenericEqualityComparer<T> : IEqualityComparer<T> public sealed class GenericEqualityComparer<T> : IEqualityComparer<T>
{ {
private readonly Func<T, T, bool> _equalsPredicate; private readonly Func<T, T, bool> _equalsPredicate;

Loading…
Cancel
Save