Skip to content

Commit f4eca45

Browse files
committed
code_style: remove all IDE warnings
1 parent 24ca3ea commit f4eca45

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+1466
-1382
lines changed

src/App.axaml.cs

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,32 @@ public static AppBuilder BuildAvaloniaApp()
8989

9090
public static readonly SimpleCommand OpenPreferenceCommand = new SimpleCommand(() =>
9191
{
92+
var toplevel = GetTopLevel() as Window;
93+
if (toplevel == null)
94+
return;
95+
9296
var dialog = new Views.Preference();
93-
dialog.ShowDialog(GetTopLevel() as Window);
97+
dialog.ShowDialog(toplevel);
9498
});
9599

96100
public static readonly SimpleCommand OpenHotkeysCommand = new SimpleCommand(() =>
97101
{
102+
var toplevel = GetTopLevel() as Window;
103+
if (toplevel == null)
104+
return;
105+
98106
var dialog = new Views.Hotkeys();
99-
dialog.ShowDialog(GetTopLevel() as Window);
107+
dialog.ShowDialog(toplevel);
100108
});
101109

102110
public static readonly SimpleCommand OpenAboutCommand = new SimpleCommand(() =>
103111
{
112+
var toplevel = GetTopLevel() as Window;
113+
if (toplevel == null)
114+
return;
115+
104116
var dialog = new Views.About();
105-
dialog.ShowDialog(GetTopLevel() as Window);
117+
dialog.ShowDialog(toplevel);
106118
});
107119

108120
public static readonly SimpleCommand CheckForUpdateCommand = new SimpleCommand(() =>
@@ -127,7 +139,7 @@ public static void SendNotification(string context, string message)
127139
public static void SetLocale(string localeKey)
128140
{
129141
var app = Current as App;
130-
var targetLocale = app.Resources[localeKey] as ResourceDictionary;
142+
var targetLocale = app?.Resources[localeKey] as ResourceDictionary;
131143
if (targetLocale == null || targetLocale == app._activeLocale)
132144
return;
133145

@@ -141,6 +153,8 @@ public static void SetLocale(string localeKey)
141153
public static void SetTheme(string theme, string themeOverridesFile)
142154
{
143155
var app = Current as App;
156+
if (app == null)
157+
return;
144158

145159
if (theme.Equals("Light", StringComparison.OrdinalIgnoreCase))
146160
app.RequestedThemeVariant = ThemeVariant.Light;
@@ -179,6 +193,7 @@ public static void SetTheme(string theme, string themeOverridesFile)
179193
}
180194
catch
181195
{
196+
// ignore
182197
}
183198
}
184199
else
@@ -189,18 +204,18 @@ public static void SetTheme(string theme, string themeOverridesFile)
189204

190205
public static async void CopyText(string data)
191206
{
192-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
207+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
193208
{
194-
if (desktop.MainWindow.Clipboard is { } clipbord)
209+
if (desktop.MainWindow?.Clipboard is { } clipbord)
195210
await clipbord.SetTextAsync(data);
196211
}
197212
}
198213

199214
public static async Task<string> GetClipboardTextAsync()
200215
{
201-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
216+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
202217
{
203-
if (desktop.MainWindow.Clipboard is { } clipboard)
218+
if (desktop.MainWindow?.Clipboard is { } clipboard)
204219
{
205220
return await clipboard.GetTextAsync();
206221
}
@@ -210,7 +225,7 @@ public static async Task<string> GetClipboardTextAsync()
210225

211226
public static string Text(string key, params object[] args)
212227
{
213-
var fmt = Current.FindResource($"Text.{key}") as string;
228+
var fmt = Current?.FindResource($"Text.{key}") as string;
214229
if (string.IsNullOrWhiteSpace(fmt))
215230
return $"Text.{key}";
216231

@@ -226,16 +241,21 @@ public static Avalonia.Controls.Shapes.Path CreateMenuIcon(string key)
226241
icon.Width = 12;
227242
icon.Height = 12;
228243
icon.Stretch = Stretch.Uniform;
229-
icon.Data = Current.FindResource(key) as StreamGeometry;
244+
245+
var geo = Current?.FindResource(key) as StreamGeometry;
246+
if (geo != null)
247+
icon.Data = geo;
248+
230249
return icon;
231250
}
232251

233252
public static TopLevel GetTopLevel()
234253
{
235-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
254+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
236255
{
237256
return desktop.MainWindow;
238257
}
258+
239259
return null;
240260
}
241261

@@ -297,9 +317,9 @@ public static ViewModels.Repository FindOpenedRepository(string repoPath)
297317

298318
public static void Quit()
299319
{
300-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
320+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
301321
{
302-
desktop.MainWindow.Close();
322+
desktop.MainWindow?.Close();
303323
desktop.Shutdown();
304324
}
305325
}
@@ -360,7 +380,7 @@ private static void ShowSelfUpdateResult(object data)
360380
{
361381
Dispatcher.UIThread.Post(() =>
362382
{
363-
if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
383+
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime { MainWindow: not null } desktop)
364384
{
365385
var dialog = new Views.SelfUpdate()
366386
{
@@ -384,11 +404,11 @@ private static bool TryLaunchedAsRebaseTodoEditor(string[] args, out int exitCod
384404
if (!filename.Equals("git-rebase-todo", StringComparison.OrdinalIgnoreCase))
385405
return true;
386406

387-
var dirInfo = new DirectoryInfo(Path.GetDirectoryName(file));
407+
var dirInfo = new DirectoryInfo(Path.GetDirectoryName(file)!);
388408
if (!dirInfo.Exists || !dirInfo.Name.Equals("rebase-merge", StringComparison.Ordinal))
389409
return true;
390410

391-
var jobsFile = Path.Combine(dirInfo.Parent.FullName, "sourcegit_rebase_jobs.json");
411+
var jobsFile = Path.Combine(dirInfo.Parent!.FullName, "sourcegit_rebase_jobs.json");
392412
if (!File.Exists(jobsFile))
393413
return true;
394414

@@ -437,16 +457,16 @@ private static bool TryLaunchedAsRebaseMessageEditor(string[] args, out int exit
437457
if (!filename.Equals("COMMIT_EDITMSG", StringComparison.OrdinalIgnoreCase))
438458
return true;
439459

440-
var jobsFile = Path.Combine(Path.GetDirectoryName(file), "sourcegit_rebase_jobs.json");
460+
var jobsFile = Path.Combine(Path.GetDirectoryName(file)!, "sourcegit_rebase_jobs.json");
441461
if (!File.Exists(jobsFile))
442462
return true;
443463

444464
var collection = JsonSerializer.Deserialize(File.ReadAllText(jobsFile), JsonCodeGen.Default.InteractiveRebaseJobCollection);
445-
var doneFile = Path.Combine(Path.GetDirectoryName(file), "rebase-merge", "done");
465+
var doneFile = Path.Combine(Path.GetDirectoryName(file)!, "rebase-merge", "done");
446466
if (!File.Exists(doneFile))
447467
return true;
448468

449-
var done = File.ReadAllText(doneFile).Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
469+
var done = File.ReadAllText(doneFile).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
450470
if (done.Length > collection.Jobs.Count)
451471
return true;
452472

@@ -460,7 +480,7 @@ private static bool TryLaunchedAsRebaseMessageEditor(string[] args, out int exit
460480
private bool TryLaunchedAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
461481
{
462482
var args = desktop.Args;
463-
if (args.Length <= 1 || !args[0].Equals("--core-editor", StringComparison.Ordinal))
483+
if (args == null || args.Length <= 1 || !args[0].Equals("--core-editor", StringComparison.Ordinal))
464484
return false;
465485

466486
var file = args[1];
@@ -474,7 +494,7 @@ private bool TryLaunchedAsCoreEditor(IClassicDesktopStyleApplicationLifetime des
474494
private bool TryLaunchedAsAskpass(IClassicDesktopStyleApplicationLifetime desktop)
475495
{
476496
var args = desktop.Args;
477-
if (args.Length != 1 || !args[0].StartsWith("Enter passphrase", StringComparison.Ordinal))
497+
if (args == null || args.Length != 1 || !args[0].StartsWith("Enter passphrase", StringComparison.Ordinal))
478498
return false;
479499

480500
desktop.MainWindow = new Views.Askpass(args[0]);
@@ -485,7 +505,10 @@ private void TryLaunchedAsNormal(IClassicDesktopStyleApplicationLifetime desktop
485505
{
486506
Native.OS.SetupEnternalTools();
487507

488-
var startupRepo = desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]) ? desktop.Args[0] : null;
508+
string startupRepo = null;
509+
if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0]))
510+
startupRepo = desktop.Args[0];
511+
489512
_launcher = new ViewModels.Launcher(startupRepo);
490513
desktop.MainWindow = new Views.Launcher() { DataContext = _launcher };
491514

src/Commands/Command.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public class ReadToEndResult
1919
{
2020
public bool IsSuccess { get; set; }
2121
public string StdOut { get; set; }
22-
public string StdErr { get; set; }
2322
}
2423

2524
public enum EditorType
@@ -51,7 +50,7 @@ public bool Exec()
5150
start.StandardErrorEncoding = Encoding.UTF8;
5251

5352
// Force using this app as SSH askpass program
54-
var selfExecFile = Process.GetCurrentProcess().MainModule.FileName;
53+
var selfExecFile = Process.GetCurrentProcess().MainModule!.FileName;
5554
if (!OperatingSystem.IsLinux())
5655
start.Environment.Add("DISPLAY", "required");
5756
start.Environment.Add("SSH_ASKPASS", selfExecFile); // Can not use parameter here, because it invoked by SSH with `exec`
@@ -199,20 +198,18 @@ public ReadToEndResult ReadToEnd()
199198
{
200199
proc.Start();
201200
}
202-
catch (Exception e)
201+
catch
203202
{
204203
return new ReadToEndResult()
205204
{
206205
IsSuccess = false,
207206
StdOut = string.Empty,
208-
StdErr = e.Message,
209207
};
210208
}
211209

212210
var rs = new ReadToEndResult()
213211
{
214212
StdOut = proc.StandardOutput.ReadToEnd(),
215-
StdErr = proc.StandardError.ReadToEnd(),
216213
};
217214

218215
proc.WaitForExit();
@@ -226,8 +223,5 @@ protected virtual void OnReadline(string line) { }
226223

227224
[GeneratedRegex(@"\d+%")]
228225
private static partial Regex REG_PROGRESS();
229-
230-
[GeneratedRegex(@"Enter\s+passphrase\s*for\s*key\s*['""]([^'""]+)['""]\:\s*", RegexOptions.IgnoreCase)]
231-
private static partial Regex REG_ASKPASS();
232226
}
233227
}

src/Commands/Config.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,15 @@ public Dictionary<string, string> ListAll()
2323
var rs = new Dictionary<string, string>();
2424
if (output.IsSuccess)
2525
{
26-
var lines = output.StdOut.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
26+
var lines = output.StdOut.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
2727
foreach (var line in lines)
2828
{
2929
var idx = line.IndexOf('=', StringComparison.Ordinal);
3030
if (idx != -1)
3131
{
3232
var key = line.Substring(0, idx).Trim();
3333
var val = line.Substring(idx + 1).Trim();
34-
if (rs.ContainsKey(key))
35-
{
36-
rs[key] = val;
37-
}
38-
else
39-
{
40-
rs.Add(key, val);
41-
}
34+
rs[key] = val;
4235
}
4336
}
4437
}

src/Commands/Fetch.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,7 @@ public static void AddRepository(string repo)
125125

126126
lock (_lock)
127127
{
128-
if (_jobs.ContainsKey(repo))
129-
{
130-
_jobs[repo] = job;
131-
}
132-
else
133-
{
134-
_jobs.Add(repo, job);
135-
}
128+
_jobs[repo] = job;
136129
}
137130
}
138131

src/Commands/GitFlow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static bool Init(string repo, List<Models.Branch> branches, string master
6464
return init.Exec();
6565
}
6666

67-
public static string Prefix(string repo, string type)
67+
public static string GetPrefix(string repo, string type)
6868
{
6969
return new Config(repo).Get($"gitflow.prefix.{type}");
7070
}

src/Commands/LFS.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void Prune(Action<string> outputHandler)
8282
var rs = cmd.ReadToEnd();
8383
if (rs.IsSuccess)
8484
{
85-
var lines = rs.StdOut.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
85+
var lines = rs.StdOut.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
8686
foreach (var line in lines)
8787
{
8888
var match = REG_LOCK().Match(line);

src/Commands/QueryCommits.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ public QueryCommits(string repo, string limits, bool needFindHead = true)
5353
_current.Subject = line;
5454
nextPartIdx = -1;
5555
break;
56-
default:
57-
break;
5856
}
5957

6058
nextPartIdx++;
@@ -97,6 +95,9 @@ private void ParseDecorators(string data)
9795
foreach (var sub in subs)
9896
{
9997
var d = sub.Trim();
98+
if (d.EndsWith("/HEAD", StringComparison.Ordinal))
99+
continue;
100+
100101
if (d.StartsWith("tag: refs/tags/", StringComparison.Ordinal))
101102
{
102103
_current.Decorators.Add(new Models.Decorator()
@@ -105,10 +106,6 @@ private void ParseDecorators(string data)
105106
Name = d.Substring(15),
106107
});
107108
}
108-
else if (d.EndsWith("/HEAD", StringComparison.Ordinal))
109-
{
110-
continue;
111-
}
112109
else if (d.StartsWith("HEAD -> refs/heads/", StringComparison.Ordinal))
113110
{
114111
_current.IsMerged = true;
@@ -159,10 +156,10 @@ private void ParseDecorators(string data)
159156

160157
private void MarkFirstMerged()
161158
{
162-
Args = $"log --since=\"{_commits[_commits.Count - 1].CommitterTimeStr}\" --format=\"%H\"";
159+
Args = $"log --since=\"{_commits[^1].CommitterTimeStr}\" --format=\"%H\"";
163160

164161
var rs = ReadToEnd();
165-
var shas = rs.StdOut.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
162+
var shas = rs.StdOut.Split('\n', StringSplitOptions.RemoveEmptyEntries);
166163
if (shas.Length == 0)
167164
return;
168165

src/Commands/QueryLocalChanges.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected override void OnReadline(string line)
5252
change.Set(Models.ChangeState.None, Models.ChangeState.Copied);
5353
break;
5454
case "M":
55-
change.Set(Models.ChangeState.Modified, Models.ChangeState.None);
55+
change.Set(Models.ChangeState.Modified);
5656
break;
5757
case "MM":
5858
change.Set(Models.ChangeState.Modified, Models.ChangeState.Modified);
@@ -61,7 +61,7 @@ protected override void OnReadline(string line)
6161
change.Set(Models.ChangeState.Modified, Models.ChangeState.Deleted);
6262
break;
6363
case "A":
64-
change.Set(Models.ChangeState.Added, Models.ChangeState.None);
64+
change.Set(Models.ChangeState.Added);
6565
break;
6666
case "AM":
6767
change.Set(Models.ChangeState.Added, Models.ChangeState.Modified);
@@ -70,10 +70,10 @@ protected override void OnReadline(string line)
7070
change.Set(Models.ChangeState.Added, Models.ChangeState.Deleted);
7171
break;
7272
case "D":
73-
change.Set(Models.ChangeState.Deleted, Models.ChangeState.None);
73+
change.Set(Models.ChangeState.Deleted);
7474
break;
7575
case "R":
76-
change.Set(Models.ChangeState.Renamed, Models.ChangeState.None);
76+
change.Set(Models.ChangeState.Renamed);
7777
break;
7878
case "RM":
7979
change.Set(Models.ChangeState.Renamed, Models.ChangeState.Modified);
@@ -82,7 +82,7 @@ protected override void OnReadline(string line)
8282
change.Set(Models.ChangeState.Renamed, Models.ChangeState.Deleted);
8383
break;
8484
case "C":
85-
change.Set(Models.ChangeState.Copied, Models.ChangeState.None);
85+
change.Set(Models.ChangeState.Copied);
8686
break;
8787
case "CM":
8888
change.Set(Models.ChangeState.Copied, Models.ChangeState.Modified);

0 commit comments

Comments
 (0)