From 8acb3e17fcaa590f425dc7afddaf469e26ea735c Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Wed, 7 Sep 2022 21:42:53 -0500 Subject: [PATCH] refactor: Address several SonarCloud code smells --- src/Common/YamlDotNet/ForceEmptySequences.cs | 4 +- .../ServiceCompatibilityIntegrationTest.cs | 4 +- src/Recyclarr/Command/ServiceCommand.cs | 2 +- .../Command/Setup/AppPathSetupTask.cs | 1 + .../Command/Setup/JanitorCleanupTask.cs | 1 + src/Recyclarr/CompositionRoot.cs | 4 +- .../JsonTransactionStepTest.cs | 2 +- .../CustomFormat/CustomFormatUpdater.cs | 4 +- .../Guide/CustomFormatGroupParser.cs | 48 ++++++++----------- .../CustomFormat/ICustomFormatUpdater.cs | 2 +- .../SonarrQualityDefinitionUpdater.cs | 2 - .../Sonarr/ReleaseProfile/ScopedState.cs | 2 +- 12 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/Common/YamlDotNet/ForceEmptySequences.cs b/src/Common/YamlDotNet/ForceEmptySequences.cs index 2947519e..a6b5eca9 100644 --- a/src/Common/YamlDotNet/ForceEmptySequences.cs +++ b/src/Common/YamlDotNet/ForceEmptySequences.cs @@ -15,8 +15,8 @@ public sealed class ForceEmptySequences : INodeDeserializer _objectFactory = objectFactory; } - public bool Deserialize(IParser reader, Type expectedType, Func nestedObjectDeserializer, - out object? value) + bool INodeDeserializer.Deserialize(IParser reader, Type expectedType, + Func nestedObjectDeserializer, out object? value) { value = null; diff --git a/src/Recyclarr.Tests/ServiceCompatibilityIntegrationTest.cs b/src/Recyclarr.Tests/ServiceCompatibilityIntegrationTest.cs index a03d9b36..90f66205 100644 --- a/src/Recyclarr.Tests/ServiceCompatibilityIntegrationTest.cs +++ b/src/Recyclarr.Tests/ServiceCompatibilityIntegrationTest.cs @@ -17,8 +17,8 @@ public class ServiceCompatibilityIntegrationTest : IntegrationFixture var sut = Resolve(); var paths = Resolve(); - // For this test, it doesn't really matter if the YAML data matches what SettingsValue expects; - // this test only ensures that the data deserialized is from the actual correct file. + // For this test, it doesn't really matter if the YAML data matches what SettingsValue expects. + // This test only ensures that the data deserialized is from the actual correct file. const string yamlData = @" repository: clone_url: http://the_url.com diff --git a/src/Recyclarr/Command/ServiceCommand.cs b/src/Recyclarr/Command/ServiceCommand.cs index 59b07f96..39e89ccc 100644 --- a/src/Recyclarr/Command/ServiceCommand.cs +++ b/src/Recyclarr/Command/ServiceCommand.cs @@ -87,7 +87,7 @@ public abstract class ServiceCommand : BaseCommand, IServiceCommand return Task.CompletedTask; } - private void SetupHttp(ILogger log, ISettingsProvider settingsProvider) + private static void SetupHttp(ILogger log, ISettingsProvider settingsProvider) { FlurlHttp.Configure(settings => { diff --git a/src/Recyclarr/Command/Setup/AppPathSetupTask.cs b/src/Recyclarr/Command/Setup/AppPathSetupTask.cs index 433a894c..126a4804 100644 --- a/src/Recyclarr/Command/Setup/AppPathSetupTask.cs +++ b/src/Recyclarr/Command/Setup/AppPathSetupTask.cs @@ -26,5 +26,6 @@ public class AppPathSetupTask : IBaseCommandSetupTask public void OnFinish() { + // No work to do for this event } } diff --git a/src/Recyclarr/Command/Setup/JanitorCleanupTask.cs b/src/Recyclarr/Command/Setup/JanitorCleanupTask.cs index 4a413bd8..56d005d3 100644 --- a/src/Recyclarr/Command/Setup/JanitorCleanupTask.cs +++ b/src/Recyclarr/Command/Setup/JanitorCleanupTask.cs @@ -19,6 +19,7 @@ public class JanitorCleanupTask : IBaseCommandSetupTask public void OnStart() { + // No work to do for this event } public void OnFinish() diff --git a/src/Recyclarr/CompositionRoot.cs b/src/Recyclarr/CompositionRoot.cs index fe4701e6..1e3953e6 100644 --- a/src/Recyclarr/CompositionRoot.cs +++ b/src/Recyclarr/CompositionRoot.cs @@ -67,7 +67,7 @@ public class CompositionRoot : ICompositionRoot return new ServiceLocatorProxy(builder.Build()); } - private void RegisterLogger(ContainerBuilder builder, LogEventLevel logLevel) + private static void RegisterLogger(ContainerBuilder builder, LogEventLevel logLevel) { builder.RegisterType().As(); builder.RegisterType(); @@ -76,7 +76,7 @@ public class CompositionRoot : ICompositionRoot .InstancePerLifetimeScope(); } - private void RegisterAppPaths(ContainerBuilder builder, string? appDataDir) + private static void RegisterAppPaths(ContainerBuilder builder, string? appDataDir) { builder.RegisterModule(); builder.RegisterType().As(); diff --git a/src/TrashLib.Tests/CustomFormat/Processors/PersistenceSteps/JsonTransactionStepTest.cs b/src/TrashLib.Tests/CustomFormat/Processors/PersistenceSteps/JsonTransactionStepTest.cs index bb1193ab..284bf4e6 100644 --- a/src/TrashLib.Tests/CustomFormat/Processors/PersistenceSteps/JsonTransactionStepTest.cs +++ b/src/TrashLib.Tests/CustomFormat/Processors/PersistenceSteps/JsonTransactionStepTest.cs @@ -296,7 +296,7 @@ public class JsonTransactionStepTest processor.Process(guideCfs, radarrCfs!); processor.RecordDeletions(deletedCfsInCache, radarrCfs!); - var expectedJson = @"{ + const string expectedJson = @"{ 'id': 1, 'name': 'updated', 'specifications': [{ diff --git a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs index 9d71f627..da6a73b5 100644 --- a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs +++ b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs @@ -34,11 +34,11 @@ internal class CustomFormatUpdater : ICustomFormatUpdater private ILogger Log { get; } - public async Task Process(bool isPreview, IEnumerable customFormats, IGuideService guideService) + public async Task Process(bool isPreview, IEnumerable configs, IGuideService guideService) { _cache.Load(); - await _guideProcessor.BuildGuideDataAsync(customFormats, _cache.CfCache, guideService); + await _guideProcessor.BuildGuideDataAsync(configs, _cache.CfCache, guideService); if (!ValidateGuideDataAndCheckShouldProceed()) { diff --git a/src/TrashLib/Services/CustomFormat/Guide/CustomFormatGroupParser.cs b/src/TrashLib/Services/CustomFormat/Guide/CustomFormatGroupParser.cs index fcd22ed7..e266a42d 100644 --- a/src/TrashLib/Services/CustomFormat/Guide/CustomFormatGroupParser.cs +++ b/src/TrashLib/Services/CustomFormat/Guide/CustomFormatGroupParser.cs @@ -64,44 +64,38 @@ public class CustomFormatGroupParser break; } - if (!line.Any()) + if (line.Any()) { - if (tableRows.Any()) + var fields = GetTableRow(line); + if (fields.Any()) { - break; + tableRows.Add(fields); + continue; } - - continue; } - var match = TableRegex.Match(line); - if (!match.Success) + if (tableRows.Any()) { - if (tableRows.Any()) - { - break; - } - - continue; - } - - var tableRow = match.Groups[1].Value; - var fields = tableRow.Split('|').Select(x => x.Trim()).ToList(); - if (!fields.Any()) - { - if (tableRows.Any()) - { - break; - } - - continue; + break; } - - tableRows.Add(fields); } return tableRows // Filter out the `|---|---|---|` part of the table between the heading & data rows. .Where(x => !Regex.IsMatch(x[0], @"^-+$")); } + + private static List GetTableRow(string line) + { + var fields = new List(); + + var match = TableRegex.Match(line); + if (match.Success) + { + var tableRow = match.Groups[1].Value; + fields = tableRow.Split('|').Select(x => x.Trim()).ToList(); + } + + return fields; + } } diff --git a/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs b/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs index d6d22914..ff792331 100644 --- a/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs +++ b/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs @@ -5,5 +5,5 @@ namespace TrashLib.Services.CustomFormat; public interface ICustomFormatUpdater { - Task Process(bool isPreview, IEnumerable config, IGuideService guideService); + Task Process(bool isPreview, IEnumerable configs, IGuideService guideService); } diff --git a/src/TrashLib/Services/Sonarr/QualityDefinition/SonarrQualityDefinitionUpdater.cs b/src/TrashLib/Services/Sonarr/QualityDefinition/SonarrQualityDefinitionUpdater.cs index 4321e4cd..e858364e 100644 --- a/src/TrashLib/Services/Sonarr/QualityDefinition/SonarrQualityDefinitionUpdater.cs +++ b/src/TrashLib/Services/Sonarr/QualityDefinition/SonarrQualityDefinitionUpdater.cs @@ -49,7 +49,6 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater var qualityDefinitions = _guide.GetQualities(); var qualityTypeInConfig = config.QualityDefinition; - // var qualityDefinitions = _parser.ParseMarkdown(await _parser.GetMarkdownData()); SonarrQualityData? selectedQuality; if (config.QualityDefinition.EqualsIgnoreCase("hybrid")) @@ -88,7 +87,6 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater IReadOnlyCollection anime, IReadOnlyCollection series) { - // todo Verify anime & series are the same length? Probably not, because we might not care about some rows anyway. _log.Information( "Notice: Hybrid only functions on 720/1080 qualities and uses non-anime values for the rest (e.g. 2160)"); diff --git a/src/TrashLib/Services/Sonarr/ReleaseProfile/ScopedState.cs b/src/TrashLib/Services/Sonarr/ReleaseProfile/ScopedState.cs index 839b4a1f..8dc7adb5 100644 --- a/src/TrashLib/Services/Sonarr/ReleaseProfile/ScopedState.cs +++ b/src/TrashLib/Services/Sonarr/ReleaseProfile/ScopedState.cs @@ -44,7 +44,7 @@ public class ScopedState return prevCount != StackSize; } - private class Node + private sealed class Node { public Node(T value, int scope) {