Enable all analyzers and enforce code style on build

Fixes #8201
Fixes #8202
Fixes #8203
Fixes #8204
Fixes #8205
Fixes #8207
Fixes #8208
Fixes #8209
Fixes #8210
Fixes #8211
Fixes #8212
Fixes #8213
Fixes #8214
Fixes #8215
Closes #8216
Fixes #8217
Closes #8218
Fixes #8219
Closes #8220
This commit is contained in:
Qstick 2023-03-29 18:27:30 -05:00
parent 926d37a572
commit 2167da87ce
33 changed files with 73 additions and 62 deletions

View File

@ -19,10 +19,10 @@ indent_size = 4
dotnet_sort_system_directives_first = true
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_property = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_event = false:warning
dotnet_style_qualification_for_field = false:refactoring
dotnet_style_qualification_for_property = false:refactoring
dotnet_style_qualification_for_method = false:refactoring
dotnet_style_qualification_for_event = false:refactoring
# Indentation preferences
csharp_indent_block_contents = true
@ -32,6 +32,10 @@ csharp_indent_case_contents_when_block = true
csharp_indent_switch_labels = true
csharp_indent_labels = flush_left
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_naming_style.instance_field_style.capitalization = camel_case
dotnet_naming_style.instance_field_style.required_prefix = _
@ -64,6 +68,7 @@ dotnet_diagnostic.SA1406.severity = suggestion
dotnet_diagnostic.SA1410.severity = suggestion
dotnet_diagnostic.SA1411.severity = suggestion
dotnet_diagnostic.SA1413.severity = none
dotnet_diagnostic.SA1512.severity = none
dotnet_diagnostic.SA1516.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.SA1601.severity = none
@ -162,6 +167,7 @@ dotnet_diagnostic.CA1309.severity = suggestion
dotnet_diagnostic.CA1310.severity = suggestion
dotnet_diagnostic.CA1401.severity = suggestion
dotnet_diagnostic.CA1416.severity = suggestion
dotnet_diagnostic.CA1419.severity = suggestion
dotnet_diagnostic.CA1507.severity = suggestion
dotnet_diagnostic.CA1508.severity = suggestion
dotnet_diagnostic.CA1707.severity = suggestion
@ -177,9 +183,6 @@ dotnet_diagnostic.CA1720.severity = suggestion
dotnet_diagnostic.CA1721.severity = suggestion
dotnet_diagnostic.CA1724.severity = suggestion
dotnet_diagnostic.CA1725.severity = suggestion
dotnet_diagnostic.CA1801.severity = suggestion
dotnet_diagnostic.CA1802.severity = suggestion
dotnet_diagnostic.CA1805.severity = suggestion
dotnet_diagnostic.CA1806.severity = suggestion
dotnet_diagnostic.CA1810.severity = suggestion
dotnet_diagnostic.CA1812.severity = suggestion
@ -191,13 +194,11 @@ dotnet_diagnostic.CA1819.severity = suggestion
dotnet_diagnostic.CA1822.severity = suggestion
dotnet_diagnostic.CA1823.severity = suggestion
dotnet_diagnostic.CA1824.severity = suggestion
dotnet_diagnostic.CA1848.severity = suggestion
dotnet_diagnostic.CA2000.severity = suggestion
dotnet_diagnostic.CA2002.severity = suggestion
dotnet_diagnostic.CA2007.severity = suggestion
dotnet_diagnostic.CA2008.severity = suggestion
dotnet_diagnostic.CA2009.severity = suggestion
dotnet_diagnostic.CA2010.severity = suggestion
dotnet_diagnostic.CA2011.severity = suggestion
dotnet_diagnostic.CA2012.severity = suggestion
dotnet_diagnostic.CA2013.severity = suggestion
dotnet_diagnostic.CA2100.severity = suggestion
@ -228,6 +229,9 @@ dotnet_diagnostic.CA2243.severity = suggestion
dotnet_diagnostic.CA2244.severity = suggestion
dotnet_diagnostic.CA2245.severity = suggestion
dotnet_diagnostic.CA2246.severity = suggestion
dotnet_diagnostic.CA2249.severity = suggestion
dotnet_diagnostic.CA2251.severity = suggestion
dotnet_diagnostic.CA2254.severity = suggestion
dotnet_diagnostic.CA3061.severity = suggestion
dotnet_diagnostic.CA3075.severity = suggestion
dotnet_diagnostic.CA3076.severity = suggestion
@ -255,7 +259,7 @@ dotnet_diagnostic.CA5392.severity = suggestion
dotnet_diagnostic.CA5394.severity = suggestion
dotnet_diagnostic.CA5397.severity = suggestion
dotnet_diagnostic.SYSLIB0006.severity = none
[*.{js,html,js,hbs,less,css}]
charset = utf-8

3
src/.globalconfig Normal file
View File

@ -0,0 +1,3 @@
is_global = true
dotnet_diagnostic.CA1014.severity = none

View File

@ -1,7 +1,9 @@
<Project>
<!-- Common to all Radarr Projects -->
<PropertyGroup>
<AnalysisLevel>6.0-all</AnalysisLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<PlatformTarget>AnyCPU</PlatformTarget>

View File

@ -131,7 +131,7 @@ namespace NzbDrone.Common.Extensions
public static string WrapInQuotes(this string text)
{
if (!text.Contains(" "))
if (!text.Contains(' '))
{
return text;
}
@ -217,7 +217,7 @@ namespace NzbDrone.Common.Extensions
public static string ToUrlHost(this string input)
{
return input.Contains(":") ? $"[{input}]" : input;
return input.Contains(':') ? $"[{input}]" : input;
}
}
}

View File

@ -216,7 +216,7 @@ namespace NzbDrone.Common.Http.Dispatchers
}
}
private void AddContentHeader(HttpRequestMessage request, string header, string value)
private static void AddContentHeader(HttpRequestMessage request, string header, string value)
{
var headers = request.Content?.Headers;
if (headers == null)

View File

@ -170,7 +170,7 @@ namespace NzbDrone.Common.Http
if (baseSlashIndex >= 0)
{
return basePath.Substring(0, baseSlashIndex) + "/" + relativePath;
return $"{basePath.AsSpan(0, baseSlashIndex)}/{relativePath}";
}
return relativePath;

View File

@ -64,7 +64,7 @@ namespace NzbDrone.Common
var args = $"create {serviceName} " +
$"DisplayName= \"{serviceName}\" " +
$"binpath= \"{Process.GetCurrentProcess().MainModule.FileName}\" " +
$"binpath= \"{Environment.ProcessPath}\" " +
"start= auto " +
"depend= EventLog/Tcpip/http " +
"obj= \"NT AUTHORITY\\LocalService\"";

View File

@ -19,7 +19,7 @@ namespace NzbDrone.Common.TPL
private readonly int _maxDegreeOfParallelism;
/// <summary>Whether the scheduler is currently processing work items.</summary>
private int _delegatesQueuedOrRunning = 0;
private int _delegatesQueuedOrRunning;
/// <summary>
/// Initializes an instance of the LimitedConcurrencyLevelTaskScheduler class with the

View File

@ -15,7 +15,7 @@ namespace NzbDrone.Core.Test.Datastore.Migration
[TestFixture]
public class custom_formatsFixture : MigrationTest<add_custom_formats>
{
public static Dictionary<int, int> QualityToDefinition = null;
public static Dictionary<int, int> QualityToDefinition;
public void AddDefaultProfile(add_custom_formats m, string name, Quality cutoff, params Quality[] allowed)
{

View File

@ -80,7 +80,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.FreeboxDownloadTests
Mocker.GetMock<IHttpClient>()
.Setup(s => s.Get(It.IsAny<HttpRequest>()))
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), new byte[0]));
.Returns<HttpRequest>(r => new HttpResponse(r, new HttpHeader(), Array.Empty<byte>()));
}
protected void GivenCategory()

View File

@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test.Extras.Others
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(1);
results.Count.Should().Be(1);
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
}
@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.Extras.Others
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(1);
results.Count.Should().Be(1);
}
}
}

View File

@ -67,7 +67,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(0);
results.Count.Should().Be(0);
}
[Test]
@ -84,7 +84,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(1);
results.Count.Should().Be(1);
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);
}
@ -110,7 +110,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(expectedOutputs.Length);
results.Count.Should().Be(expectedOutputs.Length);
for (int i = 0; i < expectedOutputs.Length; i++)
{
@ -139,7 +139,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(expectedOutputs.Length);
results.Count.Should().Be(expectedOutputs.Length);
for (int i = 0; i < expectedOutputs.Length; i++)
{
@ -169,7 +169,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles
var results = Subject.ImportFiles(_localMovie, _movieFile, new List<string> { subtitleFile }, true).ToList();
results.Count().Should().Be(1);
results.Count.Should().Be(1);
results[0].RelativePath.AsOsAgnostic().PathEquals(expectedOutputPath.AsOsAgnostic()).Should().Be(true);

View File

@ -14,7 +14,7 @@ namespace NzbDrone.Core.Test.MediaFiles.MediaFileDeletionService
[TestFixture]
public class DeleteMovieFileFixture : CoreTest<Core.MediaFiles.MediaFileDeletionService>
{
private static readonly string RootFolder = @"C:\Test\Movies";
private const string RootFolder = @"C:\Test\Movies";
private Movie _movie;
private MovieFile _movieFile;

View File

@ -627,13 +627,13 @@ namespace NzbDrone.Core.Datastore.Migration
try
{
if (audioChannelPositions.Contains("+"))
if (audioChannelPositions.Contains('+'))
{
return audioChannelPositions.Split('+')
.Sum(s => decimal.Parse(s.Trim(), CultureInfo.InvariantCulture));
}
if (audioChannelPositions.Contains("/"))
if (audioChannelPositions.Contains('/'))
{
var channelStringList = Regex.Replace(audioChannelPositions,
@"^\d+\sobjects",

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
@ -250,7 +250,7 @@ namespace NzbDrone.Core.Datastore.Migration.Framework
}
Index = end + 1;
identifier.Append(Buffer.Substring(start, end - start));
identifier.Append(Buffer.AsSpan(start, end - start));
if (Buffer[Index] != escape)
{

View File

@ -15,9 +15,9 @@ namespace NzbDrone.Core.Datastore
private const DbType EnumerableMultiParameter = (DbType)(-1);
private readonly string _paramNamePrefix;
private readonly bool _requireConcreteValue = false;
private int _paramCount = 0;
private bool _gotConcreteValue = false;
private readonly bool _requireConcreteValue;
private int _paramCount;
private bool _gotConcreteValue;
public WhereBuilderPostgres(Expression filter, bool requireConcreteValue, int seq)
{

View File

@ -15,9 +15,9 @@ namespace NzbDrone.Core.Datastore
private const DbType EnumerableMultiParameter = (DbType)(-1);
private readonly string _paramNamePrefix;
private readonly bool _requireConcreteValue = false;
private int _paramCount = 0;
private bool _gotConcreteValue = false;
private readonly bool _requireConcreteValue;
private int _paramCount;
private bool _gotConcreteValue;
public WhereBuilderSqlite(Expression filter, bool requireConcreteValue, int seq)
{

View File

@ -149,7 +149,7 @@ namespace NzbDrone.Core.Extras.Subtitles
.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
.ToList();
if (videoFiles.Count() > 2)
if (videoFiles.Count > 2)
{
return importedFiles;
}
@ -246,7 +246,7 @@ namespace NzbDrone.Core.Extras.Subtitles
if (languageTags.Any())
{
suffixBuilder.Append(".");
suffixBuilder.Append('.');
suffixBuilder.Append(string.Join(".", languageTags));
}

View File

@ -34,8 +34,8 @@ namespace NzbDrone.Core.HealthCheck
private readonly ICached<HealthCheck> _healthCheckResults;
private bool _hasRunHealthChecksAfterGracePeriod = false;
private bool _isRunningHealthChecksAfterGracePeriod = false;
private bool _hasRunHealthChecksAfterGracePeriod;
private bool _isRunningHealthChecksAfterGracePeriod;
public HealthCheckService(IEnumerable<IProvideHealthCheck> healthChecks,
IServerSideNotificationService serverSideNotificationService,

View File

@ -124,12 +124,12 @@ namespace NzbDrone.Core.Indexers.Newznab
if (includeTmdbSearch)
{
ids += "&tmdbid=" + searchCriteria.Movie.MovieMetadata.Value.TmdbId;
ids += $"&tmdbid={searchCriteria.Movie.MovieMetadata.Value.TmdbId}";
}
if (includeImdbSearch)
{
ids += "&imdbid=" + searchCriteria.Movie.MovieMetadata.Value.ImdbId.Substring(2);
ids += $"&imdbid={searchCriteria.Movie.MovieMetadata.Value.ImdbId.Substring(2)}";
}
chain.Add(GetPagedRequests(maxPages, categories, "movie", ids));

View File

@ -11,7 +11,7 @@ namespace NzbDrone.Core.Indexers
public class TorrentRssParser : RssParser
{
// Use to sum/calculate Peers as Leechers+Seeders
public bool CalculatePeersAsSum { get; set; } = false;
public bool CalculatePeersAsSum { get; set; }
// Use the specified element name to determine the Infohash
public string InfoHashElementName { get; set; }

View File

@ -127,7 +127,7 @@ namespace NzbDrone.Core.Localization
await CopyInto(dictionary, baseFilenamePath).ConfigureAwait(false);
if (culture.Contains("_"))
if (culture.Contains('_'))
{
var languageBaseFilenamePath = Path.Combine(prefix, GetResourceFilename(culture.Split('_')[0]));
await CopyInto(dictionary, languageBaseFilenamePath).ConfigureAwait(false);

View File

@ -158,7 +158,7 @@ namespace NzbDrone.Core.MediaFiles.MovieImport.Manual
// If the movie is unknown for the directory and there are more than 100 files in the folder don't process the items before returning.
var files = _diskScanService.FilterPaths(rootFolder, _diskScanService.GetVideoFiles(baseFolder, false));
if (files.Count() > 100)
if (files.Count > 100)
{
_logger.Warn("Unable to determine movie from folder name and found more than 100 files. Skipping parsing");

View File

@ -65,8 +65,9 @@ namespace NzbDrone.Core.Notifications.Discord
switch ((DiscordGrabFieldType)field)
{
case DiscordGrabFieldType.Overview:
var overview = message.Movie.MovieMetadata.Value.Overview ?? "";
discordField.Name = "Overview";
discordField.Value = message.Movie.MovieMetadata.Value.Overview.Length <= 300 ? message.Movie.MovieMetadata.Value.Overview : message.Movie.MovieMetadata.Value.Overview.Substring(0, 300) + "...";
discordField.Value = overview.Length <= 300 ? overview : $"{overview.AsSpan(0, 300)}...";
break;
case DiscordGrabFieldType.Rating:
discordField.Name = "Rating";
@ -160,8 +161,9 @@ namespace NzbDrone.Core.Notifications.Discord
switch ((DiscordImportFieldType)field)
{
case DiscordImportFieldType.Overview:
var overview = message.Movie.MovieMetadata.Value.Overview ?? "";
discordField.Name = "Overview";
discordField.Value = message.Movie.MovieMetadata.Value.Overview.Length <= 300 ? message.Movie.MovieMetadata.Value.Overview : message.Movie.MovieMetadata.Value.Overview.Substring(0, 300) + "...";
discordField.Value = overview.Length <= 300 ? overview : $"{overview.AsSpan(0, 300)}...";
break;
case DiscordImportFieldType.Rating:
discordField.Name = "Rating";

View File

@ -213,7 +213,7 @@ namespace NzbDrone.Core.Parser
var titleWithoutExtension = RemoveFileExtension(title).ToCharArray();
Array.Reverse(titleWithoutExtension);
title = new string(titleWithoutExtension) + title.Substring(titleWithoutExtension.Length);
title = $"{titleWithoutExtension}{title.Substring(titleWithoutExtension.Length)}";
Logger.Debug("Reversed name detected. Converted to '{0}'", title);
}
@ -282,11 +282,11 @@ namespace NzbDrone.Core.Parser
if (match[0].Groups["title"].Success)
{
simpleReleaseTitle = simpleReleaseTitle.Remove(match[0].Groups["title"].Index, match[0].Groups["title"].Length)
.Insert(match[0].Groups["title"].Index, simpleTitleReplaceString.Contains(".") ? "A.Movie" : "A Movie");
.Insert(match[0].Groups["title"].Index, simpleTitleReplaceString.Contains('.') ? "A.Movie" : "A Movie");
}
else
{
simpleReleaseTitle = simpleReleaseTitle.Replace(simpleTitleReplaceString, simpleTitleReplaceString.Contains(".") ? "A.Movie" : "A Movie");
simpleReleaseTitle = simpleReleaseTitle.Replace(simpleTitleReplaceString, simpleTitleReplaceString.Contains('.') ? "A.Movie" : "A Movie");
}
}

View File

@ -11,12 +11,12 @@ namespace NzbDrone.Core.Parser
return null;
}
if (!title.Contains("."))
if (!title.Contains('.'))
{
return null;
}
if (title.Contains(" "))
if (title.Contains(' '))
{
return null;
}

View File

@ -46,7 +46,7 @@ namespace NzbDrone.Host
try
{
Logger.Info("Starting Radarr - {0} - Version {1}",
Process.GetCurrentProcess().MainModule.FileName,
Environment.ProcessPath,
Assembly.GetExecutingAssembly().GetName().Version);
var startupContext = new StartupContext(args);

View File

@ -126,7 +126,7 @@ namespace NzbDrone.Host
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ apiKeyHeader, new string[] { } }
{ apiKeyHeader, Array.Empty<string>() }
});
var apikeyQuery = new OpenApiSecurityScheme
@ -157,7 +157,7 @@ namespace NzbDrone.Host
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ apikeyQuery, new string[] { } }
{ apikeyQuery, Array.Empty<string>() }
});
});

View File

@ -27,7 +27,7 @@ namespace NzbDrone.Mono.Disk
private static Dictionary<string, bool> _fileSystems;
private bool _hasLoggedProcMountFailure = false;
private bool _hasLoggedProcMountFailure;
public ProcMountProvider(Logger logger)
{

View File

@ -27,7 +27,7 @@ namespace NzbDrone.Test.Common
public int Start()
{
int threadId = Thread.CurrentThread.ManagedThreadId;
int threadId = Environment.CurrentManagedThreadId;
lock (_mutex)
{
_threads[threadId] = 1;

View File

@ -93,7 +93,7 @@ namespace Radarr.Api.V3.System.Backup
throw new BadRequestException("file must be provided");
}
var file = files.First();
var file = files[0];
var extension = Path.GetExtension(file.FileName);
if (!ValidExtensions.Contains(extension))

View File

@ -35,7 +35,7 @@ namespace Radarr.Http.Frontend.Mappers
return !resourceUrl.StartsWith("/content") &&
!resourceUrl.StartsWith("/mediacover") &&
!resourceUrl.Contains(".") &&
!resourceUrl.Contains('.') &&
!resourceUrl.StartsWith("/login");
}
}

View File

@ -12,9 +12,9 @@ namespace Radarr.Http.Middleware
{
public class StartingUpMiddleware
{
private const string MESSAGE = "Radarr is starting up, please try again later";
private readonly RequestDelegate _next;
private readonly IRuntimeInfo _runtimeInfo;
private static readonly string MESSAGE = "Radarr is starting up, please try again later";
public StartingUpMiddleware(RequestDelegate next, IRuntimeInfo runtimeInfo)
{
@ -32,7 +32,7 @@ namespace Radarr.Http.Middleware
context.Response.StatusCode = 503;
context.Response.ContentType = isJson ? "application/json" : "text/plain";
await context.Response.Body.WriteAsync(bytes, 0, bytes.Length);
await context.Response.Body.WriteAsync(bytes);
return;
}