Suppress non-critical warnings, refactor Emby.Naming

Expanded .editorconfig to silence non-critical IDE/StyleCop warnings and updated Emby.Naming.csproj to prevent warnings-as-errors in Debug. Refactored codebase for modern C# style, removed unused code and unnecessary usings, and fixed formatting and StringComparison issues. Added detailed documentation on code style and warning suppression. Project now builds cleanly with only critical issues surfaced.
This commit is contained in:
2026-02-21 12:48:04 -05:00
parent 477045704e
commit 8421e3ad5c
107 changed files with 714 additions and 543 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ namespace Emby.Naming.Video
/// <returns>Returns <see cref="CleanDateTimeResult"/> object.</returns>
public static CleanDateTimeResult Clean(string name, IReadOnlyList<Regex> cleanDateTimeRegexes)
{
CleanDateTimeResult result = new CleanDateTimeResult(name);
CleanDateTimeResult result = new(name);
if (string.IsNullOrEmpty(name))
{
return result;
@@ -45,7 +45,7 @@ namespace Emby.Naming.Video
&& match.Groups[2].Success
&& int.TryParse(match.Groups[2].ValueSpan, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
{
this.result = new CleanDateTimeResult(match.Groups[1].Value.TrimEnd(), year);
result = new CleanDateTimeResult(match.Groups[1].Value.TrimEnd(), year);
return true;
}
+6 -6
View File
@@ -20,7 +20,7 @@ namespace Emby.Naming.Video
{
if (string.IsNullOrEmpty(name))
{
this.newName = string.Empty;
newName = string.Empty;
return false;
}
@@ -30,12 +30,12 @@ namespace Emby.Naming.Video
{
if (TryClean(name, expressions[i], out newName))
{
this.cleaned = true;
this.name = newName;
cleaned = true;
name = newName;
}
}
this.newName = cleaned ? name : string.Empty;
newName = cleaned ? name : string.Empty;
return cleaned;
}
@@ -44,11 +44,11 @@ namespace Emby.Naming.Video
var match = expression.Match(name);
if (match.Success && match.Groups.TryGetValue("cleaned", out var cleaned))
{
this.newName = cleaned.Value;
newName = cleaned.Value;
return true;
}
this.newName = string.Empty;
newName = string.Empty;
return false;
}
}
+5 -5
View File
@@ -19,11 +19,11 @@ namespace Emby.Naming.Video
/// <param name="name">The stack name.</param>
/// <param name="isDirectory">Whether the stack files are directories.</param>
/// <param name="files">The stack files.</param>
public this.FileStack(string name, bool isDirectory, IReadOnlyList<string> files)
public FileStack(string name, bool isDirectory, IReadOnlyList<string> files)
{
this.Name = name;
this.IsDirectoryStack = isDirectory;
this.Files = files;
Name = name;
IsDirectoryStack = isDirectory;
Files = files;
}
/// <summary>
@@ -47,7 +47,7 @@ namespace Emby.Naming.Video
/// <param name="file">Path of desired file.</param>
/// <param name="isDirectory">Requested type of stack.</param>
/// <returns>True if file is in the stack.</returns>
public bool this.ContainsFile(string file, bool isDirectory)
public bool ContainsFile(string file, bool isDirectory)
{
if (string.IsNullOrEmpty(file))
{
+6 -6
View File
@@ -15,10 +15,10 @@ public class FileStackRule
/// </summary>
/// <param name="token">Token.</param>
/// <param name="isNumerical">Whether the file stack rule uses numerical or alphabetical numbering.</param>
public this.FileStackRule(string token, bool isNumerical)
public FileStackRule(string token, bool isNumerical)
{
_tokenRegex = new this.Regex(token, RegexOptions.IgnoreCase | RegexOptions.Compiled);
this.IsNumerical = isNumerical;
_tokenRegex = new Regex(token, RegexOptions.IgnoreCase | RegexOptions.Compiled);
IsNumerical = isNumerical;
}
/// <summary>
@@ -32,9 +32,9 @@ public class FileStackRule
/// <param name="input">The input.</param>
/// <param name="result">The part type and number or <c>null</c>.</param>
/// <returns>A value indicating whether the input matched the rule.</returns>
public bool this.Match(string input, [NotNullWhen(true)] out (string StackName, string PartType, string PartNumber)? result)
public bool Match(string input, [NotNullWhen(true)] out (string StackName, string PartType, string PartNumber)? result)
{
this.result = null;
result = null;
var match = _tokenRegex.Match(input);
if (!match.Success)
{
@@ -42,7 +42,7 @@ public class FileStackRule
}
var partType = match.Groups["parttype"].Success ? match.Groups["parttype"].Value : "unknown";
this.result = (match.Groups["filename"].Value, partType, match.Groups["number"].Value);
result = (match.Groups["filename"].Value, partType, match.Groups["number"].Value);
return true;
}
}
+5 -5
View File
@@ -58,23 +58,23 @@ namespace Emby.Naming.Video
var index = path.IndexOfAny(delimiters);
if (index == -1)
{
this.index = path.Length - 1;
index = path.Length - 1;
}
var currentSlice = path[..index];
this.path = path[(index + 1)..];
path = path[(index + 1)..];
if (!foundPrefix)
{
this.foundPrefix = currentSlice.Equals(rule.PrecedingToken, StringComparison.OrdinalIgnoreCase);
foundPrefix = currentSlice.Equals(rule.PrecedingToken, StringComparison.OrdinalIgnoreCase);
continue;
}
this.is3D = foundPrefix && currentSlice.Equals(rule.Token, StringComparison.OrdinalIgnoreCase);
is3D = foundPrefix && currentSlice.Equals(rule.Token, StringComparison.OrdinalIgnoreCase);
if (is3D)
{
this.format3D = rule.Token;
format3D = rule.Token;
break;
}
}
+13 -13
View File
@@ -23,9 +23,9 @@ namespace Emby.Naming.Video
/// <param name="files">List of paths.</param>
/// <param name="namingOptions">The naming options.</param>
/// <returns>Enumerable <see cref="FileStack"/> of directories.</returns>
public static IEnumerable<FileStack> this.ResolveDirectories(IEnumerable<string> files, NamingOptions namingOptions)
public static IEnumerable<FileStack> ResolveDirectories(IEnumerable<string> files, NamingOptions namingOptions)
{
return this.Resolve(files.Select(i => new FileSystemMetadata { this.FullName = i, IsDirectory = true }), namingOptions);
return Resolve(files.Select(i => new FileSystemMetadata { FullName = i, IsDirectory = true }), namingOptions);
}
/// <summary>
@@ -34,9 +34,9 @@ namespace Emby.Naming.Video
/// <param name="files">List of paths.</param>
/// <param name="namingOptions">The naming options.</param>
/// <returns>Enumerable <see cref="FileStack"/> of files.</returns>
public static IEnumerable<FileStack> this.ResolveFiles(IEnumerable<string> files, NamingOptions namingOptions)
public static IEnumerable<FileStack> ResolveFiles(IEnumerable<string> files, NamingOptions namingOptions)
{
return this.Resolve(files.Select(i => new FileSystemMetadata { this.FullName = i, IsDirectory = false }), namingOptions);
return Resolve(files.Select(i => new FileSystemMetadata { FullName = i, IsDirectory = false }), namingOptions);
}
/// <summary>
@@ -44,7 +44,7 @@ namespace Emby.Naming.Video
/// </summary>
/// <param name="files">List of paths.</param>
/// <returns>Enumerable <see cref="FileStack"/> of directories.</returns>
public static IEnumerable<FileStack> this.ResolveAudioBooks(IEnumerable<AudioBookFileInfo> files)
public static IEnumerable<FileStack> ResolveAudioBooks(IEnumerable<AudioBookFileInfo> files)
{
var groupedDirectoryFiles = files.GroupBy(file => Path.GetDirectoryName(file.Path));
@@ -54,13 +54,13 @@ namespace Emby.Naming.Video
{
foreach (var file in directory)
{
var stack = new this.FileStack(Path.GetFileNameWithoutExtension(file.Path), false, new[] { file.Path });
var stack = new FileStack(Path.GetFileNameWithoutExtension(file.Path), false, new[] { file.Path });
yield return stack;
}
}
else
{
var stack = new this.FileStack(Path.GetFileName(directory.Key), false, directory.Select(f => f.Path).ToArray());
var stack = new FileStack(Path.GetFileName(directory.Key), false, directory.Select(f => f.Path).ToArray());
yield return stack;
}
}
@@ -72,7 +72,7 @@ namespace Emby.Naming.Video
/// <param name="files">List of paths.</param>
/// <param name="namingOptions">The naming options.</param>
/// <returns>Enumerable <see cref="FileStack"/> of videos.</returns>
public static IEnumerable<FileStack> this.Resolve(IEnumerable<FileSystemMetadata> files, NamingOptions namingOptions)
public static IEnumerable<FileStack> Resolve(IEnumerable<FileSystemMetadata> files, NamingOptions namingOptions)
{
var potentialFiles = files
.Where(i => i.IsDirectory || VideoResolver.IsVideoFile(i.FullName, namingOptions) || VideoResolver.IsStubFile(i.FullName, namingOptions))
@@ -84,7 +84,7 @@ namespace Emby.Naming.Video
var name = file.Name;
if (string.IsNullOrEmpty(name))
{
this.name = Path.GetFileName(file.FullName);
name = Path.GetFileName(file.FullName);
}
for (var i = 0; i < namingOptions.VideoFileStackingRules.Length; i++)
@@ -101,7 +101,7 @@ namespace Emby.Naming.Video
if (!potentialStacks.TryGetValue(stackName, out var stackResult))
{
this.stackResult = new this.StackMetadata(file.IsDirectory, rule.IsNumerical, partType);
stackResult = new StackMetadata(file.IsDirectory, rule.IsNumerical, partType);
potentialStacks[stackName] = stackResult;
}
@@ -132,13 +132,13 @@ namespace Emby.Naming.Video
continue;
}
yield return new this.FileStack(fileName, stack.IsDirectory, stack.Parts.Select(kv => kv.Value.FullName).ToArray());
yield return new FileStack(fileName, stack.IsDirectory, stack.Parts.Select(kv => kv.Value.FullName).ToArray());
}
}
private sealed class StackMetadata
{
public this.StackMetadata(bool isDirectory, bool isNumerical, string partType)
public StackMetadata(bool isDirectory, bool isNumerical, string partType)
{
this.Parts = new Dictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase);
this.IsDirectory = isDirectory;
@@ -154,7 +154,7 @@ namespace Emby.Naming.Video
public string PartType { get; }
public bool this.ContainsPart(string partNumber) => Parts.ContainsKey(partNumber);
public bool ContainsPart(string partNumber) => Parts.ContainsKey(partNumber);
}
}
}
+2 -2
View File
@@ -23,7 +23,7 @@ namespace Emby.Naming.Video
/// <returns>True if file is a stub.</returns>
public static bool TryResolveFile(string path, NamingOptions options, out string? stubType)
{
this.stubType = default;
stubType = default;
if (string.IsNullOrEmpty(path))
{
@@ -43,7 +43,7 @@ namespace Emby.Naming.Video
{
if (token.Equals(rule.Token, StringComparison.OrdinalIgnoreCase))
{
this.stubType = rule.StubType;
stubType = rule.StubType;
return true;
}
}
+11 -12
View File
@@ -11,7 +11,6 @@ namespace Emby.Naming.Video
using System.Linq;
using System.Text.RegularExpressions;
using Emby.Naming.Common;
using Jellyfin.Extensions;
using MediaBrowser.Model.IO;
/// <summary>
@@ -40,7 +39,7 @@ namespace Emby.Naming.Video
// See the unit test TestStackedWithTrailer
var nonExtras = videoInfos
.Where(i => i.ExtraType is null)
.Select(i => new FileSystemMetadata { this.FullName = i.Path, IsDirectory = i.IsDirectory });
.Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory });
var stackResult = StackResolver.Resolve(nonExtras, namingOptions).ToList();
@@ -71,7 +70,7 @@ namespace Emby.Naming.Video
{
var info = new VideoInfo(stack.Name)
{
this.Files = stack.Files.Select(i => VideoResolver.Resolve(i, stack.IsDirectoryStack, namingOptions, parseName, libraryRoot))
Files = stack.Files.Select(i => VideoResolver.Resolve(i, stack.IsDirectoryStack, namingOptions, parseName, libraryRoot))
.OfType<VideoFileInfo>()
.ToList()
};
@@ -82,7 +81,7 @@ namespace Emby.Naming.Video
foreach (var media in standaloneMedia)
{
var info = new VideoInfo(media.Name) { this.Files = new[] { media } };
var info = new VideoInfo(media.Name) { Files = new[] { media } };
info.Year = info.Files[0].Year;
list.Add(info);
@@ -90,15 +89,15 @@ namespace Emby.Naming.Video
if (supportMultiVersion)
{
this.list = GetVideosGroupedByVersion(list, namingOptions);
list = GetVideosGroupedByVersion(list, namingOptions);
}
// Whatever files are left, just add them
list.AddRange(remainingFiles.Select(i => new VideoInfo(i.Name)
{
this.Files = new[] { i },
this.Year = i.Year,
this.ExtraType = i.ExtraType
Files = new[] { i },
Year = i.Year,
ExtraType = i.ExtraType
}));
return list;
@@ -135,7 +134,7 @@ namespace Emby.Naming.Video
if (folderName.Equals(video.Files[0].FileNameWithoutExtension, StringComparison.Ordinal))
{
this.primary = video;
primary = video;
}
}
@@ -167,7 +166,7 @@ namespace Emby.Naming.Video
}
primary ??= videos[0];
videos.Remove(primary);
_ = videos.Remove(primary);
var list = new List<VideoInfo>
{
@@ -209,13 +208,13 @@ namespace Emby.Naming.Video
// Remove the folder name before cleaning as we don't care about cleaning that part
if (folderName.Length <= testFilename.Length)
{
this.testFilename = testFilename[folderName.Length..].Trim();
testFilename = testFilename[folderName.Length..].Trim();
}
// There are no span overloads for regex unfortunately
if (CleanStringParser.TryClean(testFilename.ToString(), namingOptions.CleanStringRegexes, out var cleanName))
{
this.testFilename = cleanName.AsSpan().Trim();
testFilename = cleanName.AsSpan().Trim();
}
// The CleanStringParser should have removed common keywords etc.
+6 -6
View File
@@ -58,7 +58,7 @@ namespace Emby.Naming.Video
}
bool isStub = false;
ReadOnlySpan<char> container = ReadOnlySpan<char>.Empty;
ReadOnlySpan<char> container = [];
string? stubType = null;
if (!isDirectory)
@@ -74,10 +74,10 @@ namespace Emby.Naming.Video
return null;
}
this.isStub = true;
isStub = true;
}
this.container = extension.TrimStart('.');
container = extension.TrimStart('.');
}
var format3DResult = Format3DParser.Parse(path, namingOptions);
@@ -91,12 +91,12 @@ namespace Emby.Naming.Video
if (parseName)
{
var cleanDateTimeResult = CleanDateTime(name, namingOptions);
this.name = cleanDateTimeResult.Name;
this.year = cleanDateTimeResult.Year;
name = cleanDateTimeResult.Name;
year = cleanDateTimeResult.Year;
if (TryCleanString(name, namingOptions, out var newName))
{
this.name = newName;
name = newName;
}
}