From e5750a97ba2aa5fa7101251c3a241641b8879ab8 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Wed, 26 Oct 2022 16:29:33 -0500 Subject: [PATCH] refactor: Fix resharper analysis suggestions --- src/Recyclarr.Gui/Pages/Error.cshtml.cs | 21 +++++++++---------- .../IntegrationFixture.cs | 8 +++++++ .../Config/ConfigurationLoaderTest.cs | 4 ++-- src/Recyclarr/Command/BaseCommand.cs | 1 + src/Recyclarr/Command/RadarrCommand.cs | 10 +++++++-- src/Recyclarr/Command/ServiceCommand.cs | 1 + src/Recyclarr/Command/SonarrCommand.cs | 10 +++++++-- .../Config/ConfigurationException.cs | 2 ++ src/Recyclarr/Config/IConfigurationLoader.cs | 2 -- 9 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/Recyclarr.Gui/Pages/Error.cshtml.cs b/src/Recyclarr.Gui/Pages/Error.cshtml.cs index 79736c79..d14510e8 100644 --- a/src/Recyclarr.Gui/Pages/Error.cshtml.cs +++ b/src/Recyclarr.Gui/Pages/Error.cshtml.cs @@ -2,19 +2,18 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.RazorPages; -namespace Recyclarr.Gui.Pages +namespace Recyclarr.Gui.Pages; + +[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] +[IgnoreAntiforgeryToken] +public class ErrorModel : PageModel { - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - [IgnoreAntiforgeryToken] - public class ErrorModel : PageModel - { - public string? RequestId { get; set; } + public string? RequestId { get; set; } - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); - public void OnGet() - { - RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; - } + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; } } diff --git a/src/Recyclarr.TestLibrary/IntegrationFixture.cs b/src/Recyclarr.TestLibrary/IntegrationFixture.cs index 62e3acf8..6c5c6aba 100644 --- a/src/Recyclarr.TestLibrary/IntegrationFixture.cs +++ b/src/Recyclarr.TestLibrary/IntegrationFixture.cs @@ -45,6 +45,8 @@ public abstract class IntegrationFixture : IDisposable SetupMetadataJson(); } + // ReSharper disable once VirtualMemberNeverOverridden.Global + // ReSharper disable once UnusedParameter.Global protected virtual void RegisterExtraTypes(ContainerBuilder builder) { } @@ -63,17 +65,22 @@ public abstract class IntegrationFixture : IDisposable Fs.AddFileFromResource(metadataFile, "metadata.json"); } + // ReSharper disable MemberCanBePrivate.Global + protected MockFileSystem Fs { get; } = new(); protected FakeInMemoryConsole Console { get; } = new(); protected ILifetimeScope Container { get; } protected IAppPaths Paths { get; } protected ILogger Logger { get; } + // ReSharper restore MemberCanBePrivate.Global + private static void RegisterMockFor(ContainerBuilder builder) where T : class { builder.RegisterInstance(Substitute.For()).As(); } + // ReSharper disable once UnusedMember.Global protected T Resolve(Action customRegistrations) where T : notnull { var childScope = Container.BeginLifetimeScope(customRegistrations); @@ -85,6 +92,7 @@ public abstract class IntegrationFixture : IDisposable return Container.Resolve(); } + // ReSharper disable once VirtualMemberNeverOverridden.Global protected virtual void Dispose(bool disposing) { if (!disposing) diff --git a/src/Recyclarr.Tests/Config/ConfigurationLoaderTest.cs b/src/Recyclarr.Tests/Config/ConfigurationLoaderTest.cs index 431056ca..59f0919a 100644 --- a/src/Recyclarr.Tests/Config/ConfigurationLoaderTest.cs +++ b/src/Recyclarr.Tests/Config/ConfigurationLoaderTest.cs @@ -125,7 +125,7 @@ public class ConfigurationLoaderTest : IntegrationFixture Errors = {new ValidationFailure("PropertyName", "Test Validation Failure")} }); - var testYml = @" + const string testYml = @" fubar: - api_key: abc "; @@ -137,7 +137,7 @@ fubar: [Test, AutoMockData] public void Validation_success_does_not_throw(ConfigurationLoader configLoader) { - var testYml = @" + const string testYml = @" fubar: - api_key: abc "; diff --git a/src/Recyclarr/Command/BaseCommand.cs b/src/Recyclarr/Command/BaseCommand.cs index 32d1dbc7..aa432dab 100644 --- a/src/Recyclarr/Command/BaseCommand.cs +++ b/src/Recyclarr/Command/BaseCommand.cs @@ -20,6 +20,7 @@ public abstract class BaseCommand : ICommand [CommandOption("debug", 'd', Description = "Display additional logs useful for development/debug purposes.")] + // ReSharper disable once MemberCanBeProtected.Global public bool Debug { get; [UsedImplicitly] set; } = false; protected virtual void RegisterServices(ContainerBuilder builder) diff --git a/src/Recyclarr/Command/RadarrCommand.cs b/src/Recyclarr/Command/RadarrCommand.cs index 65f1bbf3..906c76ce 100644 --- a/src/Recyclarr/Command/RadarrCommand.cs +++ b/src/Recyclarr/Command/RadarrCommand.cs @@ -16,16 +16,18 @@ namespace Recyclarr.Command; [UsedImplicitly] internal class RadarrCommand : ServiceCommand { + // ReSharper disable MemberCanBePrivate.Global + [CommandOption("list-custom-formats", Description = "List available custom formats from the guide in YAML format.")] - // ReSharper disable once MemberCanBePrivate.Global public bool ListCustomFormats { get; [UsedImplicitly] set; } [CommandOption("list-qualities", Description = "List available quality definition types from the guide.")] - // ReSharper disable once MemberCanBePrivate.Global public bool ListQualities { get; [UsedImplicitly] set; } + // ReSharper restore MemberCanBePrivate.Global + public override string Name => "Radarr"; public override async Task Process(ILifetimeScope container) @@ -59,6 +61,8 @@ internal class RadarrCommand : ServiceCommand log.Information("Processing server {Url}", FlurlLogging.SanitizeUrl(config.BaseUrl)); + // ReSharper disable InvertIf + if (config.QualityDefinition != null) { var updater = scope.Resolve(); @@ -70,6 +74,8 @@ internal class RadarrCommand : ServiceCommand var updater = scope.Resolve(); await updater.Process(Preview, config.CustomFormats, guideService); } + + // ReSharper restore InvertIf } } } diff --git a/src/Recyclarr/Command/ServiceCommand.cs b/src/Recyclarr/Command/ServiceCommand.cs index 0b3b9871..d0c66337 100644 --- a/src/Recyclarr/Command/ServiceCommand.cs +++ b/src/Recyclarr/Command/ServiceCommand.cs @@ -103,6 +103,7 @@ public abstract class ServiceCommand : BaseCommand, IServiceCommand settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings); FlurlLogging.SetupLogging(settings, log); + // ReSharper disable once InvertIf if (!settingsProvider.Settings.EnableSslCertificateValidation) { log.Warning( diff --git a/src/Recyclarr/Command/SonarrCommand.cs b/src/Recyclarr/Command/SonarrCommand.cs index bbab7324..b00645a5 100644 --- a/src/Recyclarr/Command/SonarrCommand.cs +++ b/src/Recyclarr/Command/SonarrCommand.cs @@ -19,6 +19,8 @@ namespace Recyclarr.Command; [UsedImplicitly] public class SonarrCommand : ServiceCommand { + // ReSharper disable MemberCanBePrivate.Global + [CommandOption("list-release-profiles", Description = "List available release profiles from the guide in YAML format.")] public bool ListReleaseProfiles { get; [UsedImplicitly] set; } @@ -32,14 +34,14 @@ public class SonarrCommand : ServiceCommand [CommandOption("list-qualities", Description = "List available quality definition types from the guide.")] - // ReSharper disable once MemberCanBeProtected.Global public bool ListQualities { get; [UsedImplicitly] set; } [CommandOption("list-custom-formats", Description = "List available custom formats from the guide in YAML format.")] - // ReSharper disable once MemberCanBeProtected.Global public bool ListCustomFormats { get; [UsedImplicitly] set; } + // ReSharper restore MemberCanBePrivate.Global + public override string Name => "Sonarr"; public override async Task Process(ILifetimeScope container) @@ -97,6 +99,8 @@ public class SonarrCommand : ServiceCommand var versionEnforcement = scope.Resolve(); await versionEnforcement.DoVersionEnforcement(config); + // ReSharper disable InvertIf + if (config.ReleaseProfiles.Count > 0) { var updater = scope.Resolve(); @@ -114,6 +118,8 @@ public class SonarrCommand : ServiceCommand var updater = scope.Resolve(); await updater.Process(Preview, config.CustomFormats, guideService); } + + // ReSharper restore InvertIf } } } diff --git a/src/Recyclarr/Config/ConfigurationException.cs b/src/Recyclarr/Config/ConfigurationException.cs index e6428250..86053762 100644 --- a/src/Recyclarr/Config/ConfigurationException.cs +++ b/src/Recyclarr/Config/ConfigurationException.cs @@ -41,6 +41,8 @@ public class ConfigurationException : Exception const string delim = "\n - "; var builder = new StringBuilder( $"An exception occurred while deserializing type '{DeserializableType}' for YML property '{PropertyName}'"); + + // ReSharper disable once InvertIf if (ErrorMessages.Count > 0) { builder.Append(":" + delim); diff --git a/src/Recyclarr/Config/IConfigurationLoader.cs b/src/Recyclarr/Config/IConfigurationLoader.cs index 940e107d..60d0b97f 100644 --- a/src/Recyclarr/Config/IConfigurationLoader.cs +++ b/src/Recyclarr/Config/IConfigurationLoader.cs @@ -5,7 +5,5 @@ namespace Recyclarr.Config; public interface IConfigurationLoader where T : IServiceConfiguration { - IEnumerable Load(string file, string configSection); - IEnumerable LoadFromStream(TextReader stream, string configSection); IEnumerable LoadMany(IEnumerable configFiles, string configSection); }