refactor: Address several SonarCloud code smells

pull/124/head
Robert Dailey 2 years ago
parent a124902f6d
commit 8acb3e17fc

@ -15,8 +15,8 @@ public sealed class ForceEmptySequences : INodeDeserializer
_objectFactory = objectFactory; _objectFactory = objectFactory;
} }
public bool Deserialize(IParser reader, Type expectedType, Func<IParser, Type, object?> nestedObjectDeserializer, bool INodeDeserializer.Deserialize(IParser reader, Type expectedType,
out object? value) Func<IParser, Type, object?> nestedObjectDeserializer, out object? value)
{ {
value = null; value = null;

@ -17,8 +17,8 @@ public class ServiceCompatibilityIntegrationTest : IntegrationFixture
var sut = Resolve<ISettingsProvider>(); var sut = Resolve<ISettingsProvider>();
var paths = Resolve<IAppPaths>(); var paths = Resolve<IAppPaths>();
// For this test, it doesn't really matter if the YAML data matches what SettingsValue expects; // 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. // This test only ensures that the data deserialized is from the actual correct file.
const string yamlData = @" const string yamlData = @"
repository: repository:
clone_url: http://the_url.com clone_url: http://the_url.com

@ -87,7 +87,7 @@ public abstract class ServiceCommand : BaseCommand, IServiceCommand
return Task.CompletedTask; return Task.CompletedTask;
} }
private void SetupHttp(ILogger log, ISettingsProvider settingsProvider) private static void SetupHttp(ILogger log, ISettingsProvider settingsProvider)
{ {
FlurlHttp.Configure(settings => FlurlHttp.Configure(settings =>
{ {

@ -26,5 +26,6 @@ public class AppPathSetupTask : IBaseCommandSetupTask
public void OnFinish() public void OnFinish()
{ {
// No work to do for this event
} }
} }

@ -19,6 +19,7 @@ public class JanitorCleanupTask : IBaseCommandSetupTask
public void OnStart() public void OnStart()
{ {
// No work to do for this event
} }
public void OnFinish() public void OnFinish()

@ -67,7 +67,7 @@ public class CompositionRoot : ICompositionRoot
return new ServiceLocatorProxy(builder.Build()); return new ServiceLocatorProxy(builder.Build());
} }
private void RegisterLogger(ContainerBuilder builder, LogEventLevel logLevel) private static void RegisterLogger(ContainerBuilder builder, LogEventLevel logLevel)
{ {
builder.RegisterType<LogJanitor>().As<ILogJanitor>(); builder.RegisterType<LogJanitor>().As<ILogJanitor>();
builder.RegisterType<LoggerFactory>(); builder.RegisterType<LoggerFactory>();
@ -76,7 +76,7 @@ public class CompositionRoot : ICompositionRoot
.InstancePerLifetimeScope(); .InstancePerLifetimeScope();
} }
private void RegisterAppPaths(ContainerBuilder builder, string? appDataDir) private static void RegisterAppPaths(ContainerBuilder builder, string? appDataDir)
{ {
builder.RegisterModule<CommonAutofacModule>(); builder.RegisterModule<CommonAutofacModule>();
builder.RegisterType<FileSystem>().As<IFileSystem>(); builder.RegisterType<FileSystem>().As<IFileSystem>();

@ -296,7 +296,7 @@ public class JsonTransactionStepTest
processor.Process(guideCfs, radarrCfs!); processor.Process(guideCfs, radarrCfs!);
processor.RecordDeletions(deletedCfsInCache, radarrCfs!); processor.RecordDeletions(deletedCfsInCache, radarrCfs!);
var expectedJson = @"{ const string expectedJson = @"{
'id': 1, 'id': 1,
'name': 'updated', 'name': 'updated',
'specifications': [{ 'specifications': [{

@ -34,11 +34,11 @@ internal class CustomFormatUpdater : ICustomFormatUpdater
private ILogger Log { get; } private ILogger Log { get; }
public async Task Process(bool isPreview, IEnumerable<CustomFormatConfig> customFormats, IGuideService guideService) public async Task Process(bool isPreview, IEnumerable<CustomFormatConfig> configs, IGuideService guideService)
{ {
_cache.Load(); _cache.Load();
await _guideProcessor.BuildGuideDataAsync(customFormats, _cache.CfCache, guideService); await _guideProcessor.BuildGuideDataAsync(configs, _cache.CfCache, guideService);
if (!ValidateGuideDataAndCheckShouldProceed()) if (!ValidateGuideDataAndCheckShouldProceed())
{ {

@ -64,44 +64,38 @@ public class CustomFormatGroupParser
break; 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 (tableRows.Any())
if (!match.Success)
{ {
if (tableRows.Any()) break;
{
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;
} }
tableRows.Add(fields);
} }
return tableRows return tableRows
// Filter out the `|---|---|---|` part of the table between the heading & data rows. // Filter out the `|---|---|---|` part of the table between the heading & data rows.
.Where(x => !Regex.IsMatch(x[0], @"^-+$")); .Where(x => !Regex.IsMatch(x[0], @"^-+$"));
} }
private static List<string> GetTableRow(string line)
{
var fields = new List<string>();
var match = TableRegex.Match(line);
if (match.Success)
{
var tableRow = match.Groups[1].Value;
fields = tableRow.Split('|').Select(x => x.Trim()).ToList();
}
return fields;
}
} }

@ -5,5 +5,5 @@ namespace TrashLib.Services.CustomFormat;
public interface ICustomFormatUpdater public interface ICustomFormatUpdater
{ {
Task Process(bool isPreview, IEnumerable<CustomFormatConfig> config, IGuideService guideService); Task Process(bool isPreview, IEnumerable<CustomFormatConfig> configs, IGuideService guideService);
} }

@ -49,7 +49,6 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater
var qualityDefinitions = _guide.GetQualities(); var qualityDefinitions = _guide.GetQualities();
var qualityTypeInConfig = config.QualityDefinition; var qualityTypeInConfig = config.QualityDefinition;
// var qualityDefinitions = _parser.ParseMarkdown(await _parser.GetMarkdownData());
SonarrQualityData? selectedQuality; SonarrQualityData? selectedQuality;
if (config.QualityDefinition.EqualsIgnoreCase("hybrid")) if (config.QualityDefinition.EqualsIgnoreCase("hybrid"))
@ -88,7 +87,6 @@ internal class SonarrQualityDefinitionUpdater : ISonarrQualityDefinitionUpdater
IReadOnlyCollection<QualityItem> anime, IReadOnlyCollection<QualityItem> anime,
IReadOnlyCollection<QualityItem> series) IReadOnlyCollection<QualityItem> series)
{ {
// todo Verify anime & series are the same length? Probably not, because we might not care about some rows anyway.
_log.Information( _log.Information(
"Notice: Hybrid only functions on 720/1080 qualities and uses non-anime values for the rest (e.g. 2160)"); "Notice: Hybrid only functions on 720/1080 qualities and uses non-anime values for the rest (e.g. 2160)");

@ -44,7 +44,7 @@ public class ScopedState<T>
return prevCount != StackSize; return prevCount != StackSize;
} }
private class Node private sealed class Node
{ {
public Node(T value, int scope) public Node(T value, int scope)
{ {

Loading…
Cancel
Save