From ffac71b15f866dde8f464071a256f0478c0afe3a Mon Sep 17 00:00:00 2001 From: Nathan Baulch Date: Thu, 12 Jun 2025 11:35:37 +1000 Subject: [PATCH] code_style: general cleanup (#1415) * code_style: general cleanup * code_style: whitespace cleanup --- .editorconfig | 2 +- src/App.axaml.cs | 8 ++--- src/Commands/Blame.cs | 2 +- src/Commands/Command.cs | 2 +- src/Commands/Commit.cs | 2 +- src/Commands/LFS.cs | 2 +- .../QueryCommitsForInteractiveRebase.cs | 2 +- src/Commands/QueryFileSize.cs | 5 --- src/Commands/UnstageChangesForAmend.cs | 6 ++-- src/Models/AvatarManager.cs | 13 +++---- src/Models/Commit.cs | 2 +- src/Models/CommitTemplate.cs | 2 +- src/Models/NumericSort.cs | 1 - src/Models/RepositorySettings.cs | 3 +- src/Models/TemplateEngine.cs | 2 +- src/Models/TextInlineChange.cs | 18 +++++----- src/Models/User.cs | 6 +--- src/Models/Watcher.cs | 2 +- src/Native/Windows.cs | 8 ++--- src/Resources/Styles.axaml | 34 +++++++++---------- src/Resources/Themes.axaml | 2 +- src/ViewModels/Blame.cs | 4 +-- src/ViewModels/CheckoutAndFastForward.cs | 8 ++--- src/ViewModels/CommitDetail.cs | 8 ++--- src/ViewModels/ConfigureWorkspace.cs | 3 +- src/ViewModels/CreateTag.cs | 3 +- src/ViewModels/Histories.cs | 6 ++-- src/ViewModels/InProgressContexts.cs | 2 +- src/ViewModels/InteractiveRebase.cs | 2 +- src/ViewModels/Launcher.cs | 9 ++--- src/ViewModels/MergeMultiple.cs | 10 +++--- src/ViewModels/Repository.cs | 21 ++++-------- src/ViewModels/RepositoryConfigure.cs | 2 +- src/ViewModels/ScanRepositories.cs | 14 ++++---- src/Views/About.axaml | 1 - src/Views/ApplyStash.axaml.cs | 1 - src/Views/AssumeUnchangedManager.axaml | 2 +- src/Views/Avatar.cs | 4 +-- src/Views/Blame.axaml | 8 ++--- src/Views/Blame.axaml.cs | 3 +- src/Views/BranchTree.axaml | 1 - src/Views/BranchTree.axaml.cs | 5 ++- src/Views/CheckoutAndFastForward.axaml | 2 +- src/Views/CherryPick.axaml | 3 +- src/Views/ColorPicker.cs | 2 +- src/Views/CommandLogTime.cs | 2 +- src/Views/CommitBaseInfo.axaml | 6 ++-- src/Views/CommitMessagePresenter.cs | 3 +- src/Views/CommitMessageTextBox.axaml | 3 +- src/Views/CommitStatusIndicator.cs | 2 +- src/Views/ConfigureWorkspace.axaml | 6 ++-- src/Views/Conflict.axaml | 8 ++--- .../ConventionalCommitMessageBuilder.axaml | 4 +-- src/Views/DeleteMultipleBranches.axaml.cs | 1 - src/Views/FileHistories.axaml.cs | 2 +- src/Views/FilterModeSwitchButton.axaml.cs | 2 -- src/Views/Histories.axaml | 2 +- src/Views/Histories.axaml.cs | 6 ++-- src/Views/Hotkeys.axaml | 4 +-- src/Views/Launcher.axaml | 4 +-- src/Views/LauncherPageSwitcher.axaml | 2 +- src/Views/LauncherPageSwitcher.axaml.cs | 1 - src/Views/LauncherTabBar.axaml | 6 ++-- src/Views/LauncherTabBar.axaml.cs | 4 +-- src/Views/MoveRepositoryNode.axaml.cs | 2 -- src/Views/NameHighlightedTextBlock.cs | 9 ++--- src/Views/Preferences.axaml.cs | 2 +- src/Views/Repository.axaml | 2 +- src/Views/Repository.axaml.cs | 4 +-- src/Views/RepositoryToolbar.axaml | 3 +- src/Views/RepositoryToolbar.axaml.cs | 1 - src/Views/Reset.axaml | 2 +- src/Views/RevisionFileContentViewer.axaml | 1 - src/Views/RevisionFileContentViewer.axaml.cs | 1 - src/Views/RevisionFileTreeView.axaml.cs | 4 +-- src/Views/RevisionFiles.axaml | 2 +- src/Views/SelfUpdate.axaml.cs | 1 - src/Views/SubmodulesView.axaml | 2 +- src/Views/TagsView.axaml | 7 ++-- src/Views/TagsView.axaml.cs | 1 - src/Views/TextDiffView.axaml.cs | 14 +++----- src/Views/ViewLogs.axaml | 6 ++-- src/Views/Welcome.axaml | 2 +- src/Views/Welcome.axaml.cs | 12 ++----- src/Views/WelcomeToolbar.axaml | 1 - src/Views/WelcomeToolbar.axaml.cs | 1 - src/Views/WorkingCopy.axaml | 4 +-- src/Views/WorkspaceSwitcher.axaml | 3 +- src/Views/WorkspaceSwitcher.axaml.cs | 1 - 89 files changed, 161 insertions(+), 243 deletions(-) diff --git a/.editorconfig b/.editorconfig index 22c741b9..56725e7b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -100,7 +100,7 @@ dotnet_naming_symbols.private_internal_fields.applicable_kinds = field dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal dotnet_naming_style.camel_case_underscore_style.required_prefix = _ -dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case +dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case # use accessibility modifiers dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion diff --git a/src/App.axaml.cs b/src/App.axaml.cs index b5868ca1..94bcb7ef 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -301,7 +301,7 @@ namespace SourceGit return await clipboard.GetTextAsync(); } } - return default; + return null; } public static string Text(string key, params object[] args) @@ -323,8 +323,7 @@ namespace SourceGit icon.Height = 12; icon.Stretch = Stretch.Uniform; - var geo = Current?.FindResource(key) as StreamGeometry; - if (geo != null) + if (Current?.FindResource(key) is StreamGeometry geo) icon.Data = geo; return icon; @@ -682,8 +681,7 @@ namespace SourceGit } var name = sb.ToString(); - var idx = name.IndexOf('#'); - if (idx >= 0) + if (name.Contains('#')) { if (!name.Equals("fonts:Inter#Inter", StringComparison.Ordinal) && !name.Equals("fonts:SourceGit#JetBrains Mono", StringComparison.Ordinal)) diff --git a/src/Commands/Blame.cs b/src/Commands/Blame.cs index 4fa8b317..1fc51fa4 100644 --- a/src/Commands/Blame.cs +++ b/src/Commands/Blame.cs @@ -51,7 +51,7 @@ namespace SourceGit.Commands private void ParseLine(string line) { - if (line.IndexOf('\0', StringComparison.Ordinal) >= 0) + if (line.Contains('\0', StringComparison.Ordinal)) { _result.IsBinary = true; _result.LineInfos.Clear(); diff --git a/src/Commands/Command.cs b/src/Commands/Command.cs index 9bfa1c15..975922fc 100644 --- a/src/Commands/Command.cs +++ b/src/Commands/Command.cs @@ -194,7 +194,7 @@ namespace SourceGit.Commands private void HandleOutput(string line, List errs) { - line = line ?? string.Empty; + line ??= string.Empty; Log?.AppendLine(line); // Lines to hide in error message. diff --git a/src/Commands/Commit.cs b/src/Commands/Commit.cs index 17410bc9..1585e7e3 100644 --- a/src/Commands/Commit.cs +++ b/src/Commands/Commit.cs @@ -34,6 +34,6 @@ namespace SourceGit.Commands return succ; } - private string _tmpFile = string.Empty; + private readonly string _tmpFile; } } diff --git a/src/Commands/LFS.cs b/src/Commands/LFS.cs index e621ed7d..18d2ba93 100644 --- a/src/Commands/LFS.cs +++ b/src/Commands/LFS.cs @@ -10,7 +10,7 @@ namespace SourceGit.Commands [GeneratedRegex(@"^(.+)\s+([\w.]+)\s+\w+:(\d+)$")] private static partial Regex REG_LOCK(); - class SubCmd : Command + private class SubCmd : Command { public SubCmd(string repo, string args, Models.ICommandLog log) { diff --git a/src/Commands/QueryCommitsForInteractiveRebase.cs b/src/Commands/QueryCommitsForInteractiveRebase.cs index 615060a5..9f238319 100644 --- a/src/Commands/QueryCommitsForInteractiveRebase.cs +++ b/src/Commands/QueryCommitsForInteractiveRebase.cs @@ -90,6 +90,6 @@ namespace SourceGit.Commands private List _commits = []; private Models.InteractiveCommit _current = null; - private string _boundary = ""; + private readonly string _boundary; } } diff --git a/src/Commands/QueryFileSize.cs b/src/Commands/QueryFileSize.cs index 9016d826..30af7715 100644 --- a/src/Commands/QueryFileSize.cs +++ b/src/Commands/QueryFileSize.cs @@ -16,9 +16,6 @@ namespace SourceGit.Commands public long Result() { - if (_result != 0) - return _result; - var rs = ReadToEnd(); if (rs.IsSuccess) { @@ -29,7 +26,5 @@ namespace SourceGit.Commands return 0; } - - private readonly long _result = 0; } } diff --git a/src/Commands/UnstageChangesForAmend.cs b/src/Commands/UnstageChangesForAmend.cs index c930f136..19def067 100644 --- a/src/Commands/UnstageChangesForAmend.cs +++ b/src/Commands/UnstageChangesForAmend.cs @@ -23,13 +23,11 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.OriginalPath); - _patchBuilder.Append("\n"); } else if (c.Index == Models.ChangeState.Added) { _patchBuilder.Append("0 0000000000000000000000000000000000000000\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } else if (c.Index == Models.ChangeState.Deleted) { @@ -37,7 +35,6 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } else { @@ -46,8 +43,9 @@ namespace SourceGit.Commands _patchBuilder.Append(c.DataForAmend.ObjectHash); _patchBuilder.Append("\t"); _patchBuilder.Append(c.Path); - _patchBuilder.Append("\n"); } + + _patchBuilder.Append("\n"); } } diff --git a/src/Models/AvatarManager.cs b/src/Models/AvatarManager.cs index 2edcb619..fa07975d 100644 --- a/src/Models/AvatarManager.cs +++ b/src/Models/AvatarManager.cs @@ -38,7 +38,7 @@ namespace SourceGit.Models [GeneratedRegex(@"^(?:(\d+)\+)?(.+?)@.+\.github\.com$")] private static partial Regex REG_GITHUB_USER_EMAIL(); - private object _synclock = new object(); + private readonly Lock _synclock = new(); private string _storePath; private List _avatars = new List(); private Dictionary _resources = new Dictionary(); @@ -144,8 +144,7 @@ namespace SourceGit.Models if (_defaultAvatars.Contains(email)) return null; - if (_resources.ContainsKey(email)) - _resources.Remove(email); + _resources.Remove(email); var localFile = Path.Combine(_storePath, GetEmailHash(email)); if (File.Exists(localFile)) @@ -179,8 +178,7 @@ namespace SourceGit.Models lock (_synclock) { - if (!_requesting.Contains(email)) - _requesting.Add(email); + _requesting.Add(email); } return null; @@ -200,10 +198,7 @@ namespace SourceGit.Models if (image == null) return; - if (_resources.ContainsKey(email)) - _resources[email] = image; - else - _resources.Add(email, image); + _resources[email] = image; _requesting.Remove(email); diff --git a/src/Models/Commit.cs b/src/Models/Commit.cs index 9a7933c8..f0f4b39b 100644 --- a/src/Models/Commit.cs +++ b/src/Models/Commit.cs @@ -19,7 +19,7 @@ namespace SourceGit.Models public class Commit { // As retrieved by: git mktree chunks, Dictionary hashes, string data, int start) { - int hash; - if (hashes.TryGetValue(data, out hash)) + if (hashes.TryGetValue(data, out var hash)) { chunks.Add(new Chunk(hash, start, data.Length)); } diff --git a/src/Models/User.cs b/src/Models/User.cs index 066ab747..0b4816fe 100644 --- a/src/Models/User.cs +++ b/src/Models/User.cs @@ -26,11 +26,7 @@ namespace SourceGit.Models public override bool Equals(object obj) { - if (obj == null || !(obj is User)) - return false; - - var other = obj as User; - return Name == other.Name && Email == other.Email; + return obj is User other && Name == other.Name && Email == other.Email; } public override int GetHashCode() diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index ccdc645f..a3cfc329 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -246,7 +246,7 @@ namespace SourceGit.Models private long _updateStashes = 0; private long _updateTags = 0; - private object _lockSubmodule = new object(); + private readonly Lock _lockSubmodule = new(); private List _submodules = new List(); } } diff --git a/src/Native/Windows.cs b/src/Native/Windows.cs index adca05f3..8042ac47 100644 --- a/src/Native/Windows.cs +++ b/src/Native/Windows.cs @@ -128,7 +128,7 @@ namespace SourceGit.Native Microsoft.Win32.RegistryView.Registry64); var git = reg.OpenSubKey("SOFTWARE\\GitForWindows"); - if (git != null && git.GetValue("InstallPath") is string installPath) + if (git?.GetValue("InstallPath") is string installPath) { return Path.Combine(installPath, "bin", "git.exe"); } @@ -181,7 +181,7 @@ namespace SourceGit.Native break; case "cmd": - return "C:\\Windows\\System32\\cmd.exe"; + return @"C:\Windows\System32\cmd.exe"; case "wt": var wtFinder = new StringBuilder("wt.exe", 512); if (PathFindOnPath(wtFinder, null)) @@ -199,8 +199,8 @@ namespace SourceGit.Native finder.VSCode(FindVSCode); finder.VSCodeInsiders(FindVSCodeInsiders); finder.VSCodium(FindVSCodium); - finder.Fleet(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\Programs\\Fleet\\Fleet.exe"); - finder.FindJetBrainsFromToolbox(() => $"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\\JetBrains\\Toolbox"); + finder.Fleet(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\Programs\Fleet\Fleet.exe"); + finder.FindJetBrainsFromToolbox(() => $@"{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}\JetBrains\Toolbox"); finder.SublimeText(FindSublimeText); finder.TryAdd("Visual Studio", "vs", FindVisualStudio, GenerateCommandlineArgsForVisualStudio); return finder.Founded; diff --git a/src/Resources/Styles.axaml b/src/Resources/Styles.axaml index 42d9dc3e..15704775 100644 --- a/src/Resources/Styles.axaml +++ b/src/Resources/Styles.axaml @@ -16,7 +16,7 @@ 12 - + @@ -38,7 +38,7 @@ - + @@ -206,7 +206,7 @@ - + - + - + - + - + @@ -737,7 +737,7 @@ - + @@ -956,7 +956,7 @@ - + - + - +