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 @@ public static bool ContainsIgnoreCase(this string text, string contains)
public static string WrapInQuotes(this string text)
{
if (!text.Contains(" "))
if (!text.Contains(' '))
{
return text;
}
@ -217,7 +217,7 @@ public static bool IsValidIpAddress(this string value)
public static string ToUrlHost(this string input)
{
return input.Contains(":") ? $"[{input}]" : input;
return input.Contains(':') ? $"[{input}]" : input;
}
}
}

View file

@ -216,7 +216,7 @@ protected virtual void AddRequestHeaders(HttpRequestMessage webRequest, HttpHead
}
}
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 @@ private static string CombineRelativePath(string basePath, string relativePath)
if (baseSlashIndex >= 0)
{
return basePath.Substring(0, baseSlashIndex) + "/" + relativePath;
return $"{basePath.AsSpan(0, baseSlashIndex)}/{relativePath}";
}
return relativePath;

View file

@ -64,7 +64,7 @@ public virtual void Install(string serviceName)
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 @@ public class LimitedConcurrencyLevelTaskScheduler : TaskScheduler
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 @@ public void Setup()
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 @@ public void should_import_matching_file(string filePath, string expectedOutputPa
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 @@ public void should_not_import_multiple_nfo_files()
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 @@ public void should_not_import_non_subtitle_file(string filePath)
var results = Subject.ImportFiles(_localMovie, _movieFile, files, true).ToList();
results.Count().Should().Be(0);
results.Count.Should().Be(0);
}
[Test]
@ -84,7 +84,7 @@ public void should_import_matching_subtitle_file(string filePath, string expecte
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 @@ public void should_import_multiple_subtitle_files_per_language()
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 @@ public void should_import_multiple_subtitle_files_per_language_with_tags()
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 @@ public void should_import_unmatching_subtitle_file_if_only_episode(string filePa
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 @@ private void MigrateAudioChannelPositions(MediaInfo198 mediaInfo, MediaInfo199 m
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 @@ protected string ReadEscapedString(char escape)
}
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 @@ public class WhereBuilderPostgres : WhereBuilder
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 @@ public class WhereBuilderSqlite : WhereBuilder
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 @@ public override IEnumerable<ExtraFile> ImportFiles(LocalMovie localMovie, MovieF
.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file)))
.ToList();
if (videoFiles.Count() > 2)
if (videoFiles.Count > 2)
{
return importedFiles;
}
@ -246,7 +246,7 @@ private string GetSuffix(Language language, int copy, List<string> languageTags,
if (languageTags.Any())
{
suffixBuilder.Append(".");
suffixBuilder.Append('.');
suffixBuilder.Append(string.Join(".", languageTags));
}

View file

@ -34,8 +34,8 @@ public class HealthCheckService : IHealthCheckService,
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 @@ private void AddMovieIdPageableRequests(IndexerPageableRequestChain chain, int m
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 @@ private async Task<Dictionary<string, string>> GetDictionary(string prefix, stri
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 @@ private List<ManualImportItem> ProcessFolder(string rootFolder, string baseFolde
// 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 @@ public override void OnGrab(GrabMessage message)
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 @@ public override void OnDownload(DownloadMessage message)
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 @@ public static ParsedMovieInfo ParseMovieTitle(string title, bool isDir = false)
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 @@ public static ParsedMovieInfo ParseMovieTitle(string title, bool isDir = false)
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 @@ public static string GetSceneTitle(string title)
return null;
}
if (!title.Contains("."))
if (!title.Contains('.'))
{
return null;
}
if (title.Contains(" "))
if (title.Contains(' '))
{
return null;
}

View file

@ -46,7 +46,7 @@ public static void Start(string[] args, Action<IHostBuilder> trayCallback = null
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 @@ public void ConfigureServices(IServiceCollection services)
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ apiKeyHeader, new string[] { } }
{ apiKeyHeader, Array.Empty<string>() }
});
var apikeyQuery = new OpenApiSecurityScheme
@ -157,7 +157,7 @@ public void ConfigureServices(IServiceCollection services)
c.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{ apikeyQuery, new string[] { } }
{ apikeyQuery, Array.Empty<string>() }
});
});

View file

@ -27,7 +27,7 @@ public class ProcMountProvider : IProcMountProvider
private static Dictionary<string, bool> _fileSystems;
private bool _hasLoggedProcMountFailure = false;
private bool _hasLoggedProcMountFailure;
public ProcMountProvider(Logger logger)
{

View file

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

View file

@ -93,7 +93,7 @@ public object UploadAndRestore()
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 @@ public override bool CanHandle(string resourceUrl)
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 @@ public async Task InvokeAsync(HttpContext context)
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;
}