Skip to content

Commit

Permalink
JetBrains Rider code cleanup (#89)
Browse files Browse the repository at this point in the history
* Update all projects from .NET 8 to 9

* Upgrade all packages to latests

* Remove no-op null check

* Update Rider files

* Update GitHub Actions build-and-test workflow to use .NET 9

* First round

* Second round

* Add Rider file

* Disallow nulls

* Rider file
  • Loading branch information
codeconscious authored Nov 30, 2024
1 parent 98c9975 commit 7de9f9c
Show file tree
Hide file tree
Showing 40 changed files with 267 additions and 289 deletions.
1 change: 1 addition & 0 deletions src/.idea/.idea.AudioTagger/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/.idea.AudioTagger/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/.idea/.idea.AudioTagger/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions src/AudioTagger.Console/GetUserInput.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using System;
using System.Linq;
using System.Collections.Generic;
using AudioTagger.Library;
using AudioTagger.Library;

namespace AudioTagger.Console;

public enum UserResponse
{
None,
Yes,
No,
Cancel
}

public sealed record KeyResponse
{
public char Key { get; init; }
public UserResponse Response { get; init; }
public char Key { get; }
public UserResponse Response { get; }

public KeyResponse(char key, UserResponse response)
{
Expand All @@ -30,7 +26,7 @@ public static class ResponseHandler
/// <summary>
/// Ask the user a question that they can answer with a single keystroke.
/// </summary>
public static UserResponse AskUserQuestion(IReadOnlyList<LineSubString> question,
private static UserResponse AskUserQuestion(IReadOnlyList<LineSubString> question,
IReadOnlyList<KeyResponse> allowedResponses,
IPrinter printer)
{
Expand All @@ -56,13 +52,13 @@ public static UserResponse AskUserQuestion(IReadOnlyList<LineSubString> question
ConsoleKeyInfo keyInfo = System.Console.ReadKey(true);
char keyChar = char.ToLowerInvariant(keyInfo.KeyChar);

KeyResponse? relevantKeyResponse =
allowedResponses
.Where(r => r.Key == keyChar)?
.FirstOrDefault();
var relevantKeyResponse =
allowedResponses.FirstOrDefault(r => r.Key == keyChar);

if (relevantKeyResponse == null)
{
continue;
}

return relevantKeyResponse.Response;
}
Expand All @@ -82,7 +78,7 @@ public static UserResponse AskUserYesNoCancel(IPrinter printer)
new ("N", ConsoleColor.Magenta),
new (" (or "),
new ("C", ConsoleColor.Magenta),
new (" to cancel): "),
new (" to cancel): ")
};

var allowedResponses = new List<KeyResponse>
Expand Down
6 changes: 3 additions & 3 deletions src/AudioTagger.Console/MediaFilePathInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ internal sealed class MediaFilePathInfo
Path.DirectorySeparatorChar
];

private string WorkingPath { get; init; }
private List<string> SubDirectories { get; init; }
private string FileName { get; init; }
private string WorkingPath { get; }
private List<string> SubDirectories { get; }
private string FileName { get; }

public MediaFilePathInfo(
string workingPath,
Expand Down
33 changes: 17 additions & 16 deletions src/AudioTagger.Console/MediaFileViewer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Spectre.Console;

namespace AudioTagger.Console;
Expand All @@ -7,53 +8,53 @@ public sealed class MediaFileViewer
public void PrintFileDetails(MediaFile file)
{
// TODO: Handle colors more gracefully.
var tagNameFormatter = (string s) => "[grey]" + s + "[/]";
string TagNameFormatter(string s) => "[grey]" + s + "[/]";

Table table = new();
table.AddColumns(string.Empty, string.Empty);
table.Border = TableBorder.None;
table.HideHeaders();
table.Expand = true;

table.AddRow(tagNameFormatter("Title"), file.Title.EscapeMarkup());
table.AddRow(TagNameFormatter("Title"), file.Title.EscapeMarkup());
if (file.AlbumArtists.Any())
{
table.AddRow(tagNameFormatter("Album Artist"),
table.AddRow(TagNameFormatter("Album Artist"),
file.AlbumArtists.Join().EscapeMarkup());
}
table.AddRow(tagNameFormatter("Artist"), file.Artists.Join().EscapeMarkup());
table.AddRow(tagNameFormatter("Album"), file.Album.EscapeMarkup());
table.AddRow(TagNameFormatter("Artist"), file.Artists.Join().EscapeMarkup());
table.AddRow(TagNameFormatter("Album"), file.Album.EscapeMarkup());
if (file.TrackNo > 0)
table.AddRow(tagNameFormatter("Track"), file.TrackNo.ToString());
table.AddRow(TagNameFormatter("Track"), file.TrackNo.ToString());
if (file.Year > 0)
table.AddRow(tagNameFormatter("Year"), file.Year.ToString());
table.AddRow(tagNameFormatter("Duration"), file.Duration.ToString("m\\:ss"));
table.AddRow(TagNameFormatter("Year"), file.Year.ToString());
table.AddRow(TagNameFormatter("Duration"), file.Duration.ToString("m\\:ss"));

int genreCount = file.Genres.Length;
table.AddRow(tagNameFormatter("Genres"),
table.AddRow(TagNameFormatter("Genres"),
file.Genres.Join().EscapeMarkup() +
(genreCount > 1 ? $" ({genreCount})" : string.Empty));

string bitrate = file.BitRate.ToString();
string sampleRate = file.SampleRate.ToString("#,##0");

table.AddRow(tagNameFormatter("Quality"), $"{bitrate} kbps @ {sampleRate} kHz | {file.ReplayGainSummary()}");
table.AddRow(TagNameFormatter("Quality"), $"{bitrate} kbps @ {sampleRate} kHz | {file.ReplayGainSummary()}");

if (file.Composers?.Length > 0)
if (file.Composers.Length > 0)
{
table.AddRow(
tagNameFormatter("Composers"),
TagNameFormatter("Composers"),
file.Composers.Join().EscapeMarkup());
}

if (file.Comments.HasText())
table.AddRow(tagNameFormatter("Comments"), file.Comments.EscapeMarkup());
table.AddRow(TagNameFormatter("Comments"), file.Comments.EscapeMarkup());

if (file.Description.HasText())
table.AddRow(tagNameFormatter("Comments"), file.Description.EscapeMarkup());
table.AddRow(TagNameFormatter("Comments"), file.Description.EscapeMarkup());

if (file.Lyrics.HasText())
table.AddRow(tagNameFormatter("Lyrics"), file.Lyrics[..25].EscapeMarkup() + "...");
table.AddRow(TagNameFormatter("Lyrics"), file.Lyrics[..25].EscapeMarkup() + "...");

table.Columns[0].Width(15);

Expand All @@ -78,7 +79,7 @@ public static TableRow PrintFileSummary(MediaFile file)
file.Year == 0 ? string.Empty : file.Year.ToString(),
file.Genres.Join().EscapeMarkup(),
file.Duration.ToString("m\\:ss"),
file.ReplayGainTrack.ToString()
file.ReplayGainTrack.ToString(CultureInfo.InvariantCulture)
};

IEnumerable<Markup> markups = rows.Select(r => new Markup(r));
Expand Down
11 changes: 5 additions & 6 deletions src/AudioTagger.Console/OperationLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace AudioTagger.Console;

internal static class OperationLibrary
{
internal static readonly IReadOnlyList<Operation> Operations =
private static readonly IReadOnlyList<Operation> Operations =
[
new(
["-v", "--view"],
Expand Down Expand Up @@ -95,7 +95,7 @@ internal static class OperationLibrary
["--cache-tags"],
"Cache files' tag data locally to a JSON file whose path is specified in the settings. (Eventually, this will be helpful in speeding up certain operations.)",
new TagCacher(),
isHidden: true),
isHidden: true)
];

public static Dictionary<string, string> GenerateHelpTextPairs(bool includeHidden)
Expand All @@ -109,7 +109,7 @@ public static Dictionary<string, string> GenerateHelpTextPairs(bool includeHidde
o => o.Description);
}

public static Result<IPathOperation> GetPathOperation(string requestedOperation)
private static Result<IPathOperation> GetPathOperation(string requestedOperation)
{
string loweredOperation = requestedOperation.ToLowerInvariant();

Expand All @@ -129,10 +129,9 @@ public static Result<ImmutableList<IPathOperation>> GetPathOperations(
var successes = new List<IPathOperation>();
var failures = new List<string>();

Result<IPathOperation> currentResult;
foreach (string operation in requestedOperations)
{
currentResult = GetPathOperation(operation);
Result<IPathOperation> currentResult = GetPathOperation(operation);
if (currentResult.IsSuccess)
{
successes.Add(currentResult.Value);
Expand Down Expand Up @@ -167,5 +166,5 @@ public Operation(
(Commands, Description, PathOperation, IsHidden) =
(commands, description, pathOperation, isHidden);
}
};
}
}
Loading

0 comments on commit 7de9f9c

Please sign in to comment.