Skip to content

Commit d404f6d

Browse files
authored
code_style: general cleanup (#1428)
1 parent ae46728 commit d404f6d

Some content is hidden

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

48 files changed

+123
-240
lines changed

.editorconfig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ dotnet_style_predefined_type_for_member_access = true:suggestion
7171

7272
# name all constant fields using PascalCase
7373
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
74-
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
74+
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
7575
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
7676

77-
dotnet_naming_symbols.constant_fields.applicable_kinds = field
77+
dotnet_naming_symbols.constant_fields.applicable_kinds = field
7878
dotnet_naming_symbols.constant_fields.required_modifiers = const
7979

8080
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
8181

8282
# private static fields should have s_ prefix
8383
dotnet_naming_rule.private_static_fields_should_have_prefix.severity = suggestion
84-
dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
84+
dotnet_naming_rule.private_static_fields_should_have_prefix.symbols = private_static_fields
8585
dotnet_naming_rule.private_static_fields_should_have_prefix.style = private_static_prefix_style
8686

87-
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
87+
dotnet_naming_symbols.private_static_fields.applicable_kinds = field
8888
dotnet_naming_symbols.private_static_fields.required_modifiers = static
8989
dotnet_naming_symbols.private_static_fields.applicable_accessibilities = private
9090

@@ -93,7 +93,7 @@ dotnet_naming_style.private_static_prefix_style.capitalization = camel_case
9393

9494
# internal and private fields should be _camelCase
9595
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
96-
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
96+
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
9797
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
9898

9999
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field

src/App.axaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ private static bool TryLaunchAsRebaseMessageEditor(string[] args, out int exitCo
521521
private bool TryLaunchAsCoreEditor(IClassicDesktopStyleApplicationLifetime desktop)
522522
{
523523
var args = desktop.Args;
524-
if (args == null || args.Length <= 1 || !args[0].Equals("--core-editor", StringComparison.Ordinal))
524+
if (args is not { Length: > 1 } || !args[0].Equals("--core-editor", StringComparison.Ordinal))
525525
return false;
526526

527527
var file = args[1];

src/Commands/QueryBranches.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,12 @@ public QueryBranches(string repo)
4848
if (remoteHeads.TryGetValue(b.Upstream, out var upstreamHead))
4949
{
5050
b.IsUpstreamGone = false;
51-
52-
if (b.TrackStatus == null)
53-
b.TrackStatus = new QueryTrackStatus(WorkingDirectory, b.Head, upstreamHead).Result();
51+
b.TrackStatus ??= new QueryTrackStatus(WorkingDirectory, b.Head, upstreamHead).Result();
5452
}
5553
else
5654
{
5755
b.IsUpstreamGone = true;
58-
59-
if (b.TrackStatus == null)
60-
b.TrackStatus = new Models.BranchTrackStatus();
56+
b.TrackStatus ??= new Models.BranchTrackStatus();
6157
}
6258
}
6359
}

src/Commands/QueryTags.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public QueryTags(string repo)
2424
var records = rs.StdOut.Split(_boundary, StringSplitOptions.RemoveEmptyEntries);
2525
foreach (var record in records)
2626
{
27-
var subs = record.Split('\0', StringSplitOptions.None);
27+
var subs = record.Split('\0');
2828
if (subs.Length != 6)
2929
continue;
3030

src/Commands/SaveRevisionFile.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Run(string repo, string revision, string file, string saveTo)
2222
}
2323
}
2424

25-
private static bool ExecCmd(string repo, string args, string outputFile, Stream input = null)
25+
private static void ExecCmd(string repo, string args, string outputFile, Stream input = null)
2626
{
2727
var starter = new ProcessStartInfo();
2828
starter.WorkingDirectory = repo;
@@ -45,18 +45,14 @@ private static bool ExecCmd(string repo, string args, string outputFile, Stream
4545
proc.StandardInput.Write(new StreamReader(input).ReadToEnd());
4646
proc.StandardOutput.BaseStream.CopyTo(sw);
4747
proc.WaitForExit();
48-
var rs = proc.ExitCode == 0;
4948
proc.Close();
50-
51-
return rs;
5249
}
5350
catch (Exception e)
5451
{
5552
Dispatcher.UIThread.Invoke(() =>
5653
{
5754
App.RaiseException(repo, "Save file failed: " + e.Message);
5855
});
59-
return false;
6056
}
6157
}
6258
}

src/Models/AvatarManager.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ public static AvatarManager Instance
2626
{
2727
get
2828
{
29-
if (_instance == null)
30-
_instance = new AvatarManager();
31-
32-
return _instance;
29+
return _instance ??= new AvatarManager();
3330
}
3431
}
3532

src/Models/DiffResult.cs

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ public enum TextDiffLineType
1616
Deleted,
1717
}
1818

19-
public class TextInlineRange
19+
public class TextInlineRange(int p, int n)
2020
{
21-
public int Start { get; set; }
22-
public int End { get; set; }
23-
public TextInlineRange(int p, int n) { Start = p; End = p + n - 1; }
21+
public int Start { get; set; } = p;
22+
public int End { get; set; } = p + n - 1;
2423
}
2524

2625
public class TextDiffLine
@@ -556,7 +555,7 @@ private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffL
556555
}
557556
else if (test.Type == TextDiffLineType.Added)
558557
{
559-
if (i < start - 1)
558+
if (i < start - 1 || isOldSide)
560559
{
561560
if (revert)
562561
{
@@ -566,18 +565,7 @@ private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffL
566565
}
567566
else
568567
{
569-
if (isOldSide)
570-
{
571-
if (revert)
572-
{
573-
newCount++;
574-
oldCount++;
575-
}
576-
}
577-
else
578-
{
579-
newCount++;
580-
}
568+
newCount++;
581569
}
582570

583571
if (i == end - 1 && tailed)
@@ -655,9 +643,7 @@ public class ImageDiff
655643
public string NewImageSize => New != null ? $"{New.PixelSize.Width} x {New.PixelSize.Height}" : "0 x 0";
656644
}
657645

658-
public class NoOrEOLChange
659-
{
660-
}
646+
public class NoOrEOLChange;
661647

662648
public class FileModeDiff
663649
{

src/Models/ExternalTool.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ public ExternalToolsFinder()
107107
// Ignore
108108
}
109109

110-
if (_customPaths == null)
111-
_customPaths = new ExternalToolPaths();
110+
_customPaths ??= new ExternalToolPaths();
112111
}
113112

114113
public void TryAdd(string name, string icon, Func<string> finder, Func<string, string> execArgsGenerator = null)

src/Models/IpcChannel.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ namespace SourceGit.Models
88
{
99
public class IpcChannel : IDisposable
1010
{
11-
public bool IsFirstInstance
12-
{
13-
get => _isFirstInstance;
14-
}
11+
public bool IsFirstInstance { get; }
1512

1613
public event Action<string> MessageReceived;
1714

@@ -20,7 +17,7 @@ public IpcChannel()
2017
try
2118
{
2219
_singletonLock = File.Open(Path.Combine(Native.OS.DataDir, "process.lock"), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
23-
_isFirstInstance = true;
20+
IsFirstInstance = true;
2421
_server = new NamedPipeServerStream(
2522
"SourceGitIPCChannel" + Environment.UserName,
2623
PipeDirection.In,
@@ -32,7 +29,7 @@ public IpcChannel()
3229
}
3330
catch
3431
{
35-
_isFirstInstance = false;
32+
IsFirstInstance = false;
3633
}
3734
}
3835

@@ -97,7 +94,6 @@ private async void StartServer()
9794
}
9895

9996
private FileStream _singletonLock = null;
100-
private bool _isFirstInstance = false;
10197
private NamedPipeServerStream _server = null;
10298
private CancellationTokenSource _cancellationTokenSource = null;
10399
}

src/Models/Null.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
namespace SourceGit.Models
22
{
3-
public class Null
4-
{
5-
}
3+
public class Null;
64
}

0 commit comments

Comments
 (0)