Skip to content

Commit 7b0fac6

Browse files
committed
code cleanup
1 parent d8371e1 commit 7b0fac6

34 files changed

+145
-175
lines changed

src/GitTools.Testing/Fixtures/SequenceDiagram.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,9 @@ public void BranchToFromTag(string branchName, string fromTag, string onBranch,
103103
/// <summary>
104104
/// Append a merge to the sequence diagram
105105
/// </summary>
106-
public void Merge(string @from, string to) => this.diagramBuilder.AppendLineFormat("{0} -> {1}: merge", GetParticipant(@from), GetParticipant(to));
106+
public void Merge(string from, string to) => this.diagramBuilder.AppendLineFormat("{0} -> {1}: merge", GetParticipant(from), GetParticipant(to));
107107

108-
private string GetParticipant(string branch)
109-
{
110-
if (this.participants.ContainsKey(branch))
111-
return this.participants[branch];
112-
113-
return branch;
114-
}
108+
private string GetParticipant(string branch) => this.participants.ContainsKey(branch) ? this.participants[branch] : branch;
115109

116110
/// <summary>
117111
/// Ends the sequence diagram

src/GitTools.Testing/GitTestExtensions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ public static Tag MakeATaggedCommit(this IRepository repository, string tag)
4242
{
4343
var commit = repository.MakeACommit();
4444
var existingTag = repository.Tags.SingleOrDefault(t => t.FriendlyName == tag);
45-
if (existingTag != null)
46-
return existingTag;
47-
return repository.Tags.Add(tag, commit);
45+
return existingTag != null ? existingTag : repository.Tags.Add(tag, commit);
4846
}
4947

50-
public static Commit CreatePullRequestRef(this IRepository repository, string from, string to, int prNumber = 2, bool normalise = false, bool allowFastFowardMerge = false)
48+
public static Commit CreatePullRequestRef(this IRepository repository, string from, string to, int prNumber = 2, bool normalise = false, bool allowFastForwardMerge = false)
5149
{
5250
Commands.Checkout(repository, repository.Branches[to].Tip);
53-
if (allowFastFowardMerge)
51+
if (allowFastForwardMerge)
5452
{
5553
repository.Merge(repository.Branches[from], Generate.SignatureNow());
5654
}

src/GitTools.Testing/Internal/DirectoryHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public static void DeleteDirectory(string directoryPath)
4040

4141
if (!Directory.Exists(directoryPath))
4242
{
43-
Trace.WriteLine(
44-
string.Format("Directory '{0}' is missing and can't be removed.",
45-
directoryPath));
43+
Trace.WriteLine($"Directory '{directoryPath}' is missing and can't be removed.");
4644

4745
return;
4846
}

src/GitTools.Testing/Internal/ProcessHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public ChangeErrorMode(ErrorModes mode)
179179
{
180180
this.oldMode = SetErrorMode((int)mode);
181181
}
182-
catch (Exception ex) when (ex is EntryPointNotFoundException || ex is DllNotFoundException)
182+
catch (Exception ex) when (ex is EntryPointNotFoundException or DllNotFoundException)
183183
{
184184
this.oldMode = (int)mode;
185185
}
@@ -192,7 +192,7 @@ void IDisposable.Dispose()
192192
{
193193
SetErrorMode(this.oldMode);
194194
}
195-
catch (Exception ex) when (ex is EntryPointNotFoundException || ex is DllNotFoundException)
195+
catch (Exception ex) when (ex is EntryPointNotFoundException or DllNotFoundException)
196196
{
197197
// NOTE: Mono doesn't support DllImport("kernel32.dll") and its SetErrorMode method, obviously. @asbjornu
198198
}

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ private static IEnumerable<TestCaseData> OverrideconfigWithInvalidOptionTestData
381381
};
382382
yield return new TestCaseData("unknown-option=25")
383383
{
384-
ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsuported 'key'."
384+
ExpectedResult = "Could not parse /overrideconfig option: unknown-option=25. Unsupported 'key'."
385385
};
386386
yield return new TestCaseData("update-build-number=1")
387387
{

src/GitVersion.App/ArgumentParser.cs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private IEnumerable<string> ResolveFiles(string workingDirectory, ISet<string> a
150150
}
151151
}
152152

153-
private void ParseTargetPath(Arguments arguments, string name, string[] values, string value, bool parseEnded)
153+
private void ParseTargetPath(Arguments arguments, string name, IReadOnlyList<string> values, string value, bool parseEnded)
154154
{
155155
if (name.IsSwitch("targetpath"))
156156
{
@@ -282,7 +282,7 @@ private static bool ParseSwitches(Arguments arguments, string name, string[] val
282282
return false;
283283
}
284284

285-
private static bool ParseConfigArguments(Arguments arguments, string name, string[] values, string value)
285+
private static bool ParseConfigArguments(Arguments arguments, string name, IReadOnlyList<string> values, string value)
286286
{
287287
if (name.IsSwitch("config"))
288288
{
@@ -297,16 +297,15 @@ private static bool ParseConfigArguments(Arguments arguments, string name, strin
297297
return true;
298298
}
299299

300-
if (name.IsSwitch("showConfig"))
301-
{
302-
arguments.ShowConfig = value.IsTrue() || !value.IsFalse();
303-
return true;
304-
}
300+
if (!name.IsSwitch("showConfig"))
301+
return false;
302+
303+
arguments.ShowConfig = value.IsTrue() || !value.IsFalse();
304+
return true;
305305

306-
return false;
307306
}
308307

309-
private static bool ParseRemoteArguments(Arguments arguments, string name, string[] values, string value)
308+
private static bool ParseRemoteArguments(Arguments arguments, string name, IReadOnlyList<string> values, string value)
310309
{
311310
if (name.IsSwitch("dynamicRepoLocation"))
312311
{
@@ -391,7 +390,7 @@ private static void ParseEnsureAssemblyInfo(Arguments arguments, string value)
391390
}
392391
}
393392

394-
private static void ParseOutput(Arguments arguments, string[] values)
393+
private static void ParseOutput(Arguments arguments, IEnumerable<string> values)
395394
{
396395
foreach (var v in values)
397396
{
@@ -417,9 +416,9 @@ private static void ParseVerbosity(Arguments arguments, string value)
417416
}
418417
}
419418

420-
private static void ParseOverrideConfig(Arguments arguments, string[] values)
419+
private static void ParseOverrideConfig(Arguments arguments, IReadOnlyCollection<string> values)
421420
{
422-
if (values == null || values.Length == 0)
421+
if (values == null || values.Count == 0)
423422
return;
424423

425424
var parser = new OverrideConfigOptionParser();
@@ -436,17 +435,14 @@ private static void ParseOverrideConfig(Arguments arguments, string[] values)
436435
var optionKey = keyAndValue[0].ToLowerInvariant();
437436
if (!OverrideConfigOptionParser.SupportedProperties.Contains(optionKey))
438437
{
439-
throw new WarningException($"Could not parse /overrideconfig option: {keyValueOption}. Unsuported 'key'.");
440-
}
441-
else
442-
{
443-
parser.SetValue(optionKey, keyAndValue[1]);
438+
throw new WarningException($"Could not parse /overrideconfig option: {keyValueOption}. Unsupported 'key'.");
444439
}
440+
parser.SetValue(optionKey, keyAndValue[1]);
445441
}
446442
arguments.OverrideConfig = parser.GetConfig();
447443
}
448444

449-
private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, string[] values)
445+
private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, IReadOnlyCollection<string> values)
450446
{
451447
if (value.IsTrue())
452448
{
@@ -456,7 +452,7 @@ private static void ParseUpdateAssemblyInfo(Arguments arguments, string value, s
456452
{
457453
arguments.UpdateAssemblyInfo = false;
458454
}
459-
else if (values != null && values.Length > 1)
455+
else if (values != null && values.Count > 1)
460456
{
461457
arguments.UpdateAssemblyInfo = true;
462458
foreach (var v in values)

src/GitVersion.App/HelpWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ private string ArgumentList()
3434
using var argumentsMarkdownStream = GetType().Assembly.GetManifestResourceStream("GitVersion.arguments.md");
3535
using var sr = new StreamReader(argumentsMarkdownStream);
3636
var argsMarkdown = sr.ReadToEnd();
37-
var codeBlockStart = argsMarkdown.IndexOf("```") + 3;
38-
var codeBlockEnd = argsMarkdown.LastIndexOf("```") - codeBlockStart;
37+
var codeBlockStart = argsMarkdown.IndexOf("```", StringComparison.Ordinal) + 3;
38+
var codeBlockEnd = argsMarkdown.LastIndexOf("```", StringComparison.Ordinal) - codeBlockStart;
3939
return argsMarkdown.Substring(codeBlockStart, codeBlockEnd).Trim();
4040
}
4141
}

src/GitVersion.App/QuotedStringHelpers.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public static class QuotedStringHelpers
1010
/// </summary>
1111
/// <param name="input">String we want to split.</param>
1212
/// <param name="splitChar">Character used for splitting.</param>
13-
/// <returns>Array of splitted string parts</returns>
13+
/// <returns>Array of split string parts</returns>
1414
/// <remarks>
1515
/// If there is opening quotes character without closing quotes,
1616
/// closing quotes are implicitly assumed at the end of the input string.
@@ -25,7 +25,7 @@ public static string[] SplitUnquoted(string input, char splitChar)
2525
if (input == null)
2626
return Array.Empty<string>();
2727

28-
var splitted = new List<string>();
28+
var split = new List<string>();
2929
bool isPreviousCharBackslash = false;
3030
bool isInsideQuotes = false;
3131

@@ -42,17 +42,17 @@ public static string[] SplitUnquoted(string input, char splitChar)
4242
default:
4343
if (current == splitChar && !isInsideQuotes)
4444
{
45-
splitted.Add(input.Substring(startIndex, i - startIndex));
45+
split.Add(input.Substring(startIndex, i - startIndex));
4646
startIndex = i + 1;
4747
}
4848
break;
4949
}
5050
isPreviousCharBackslash = current == '\\';
5151
}
5252

53-
splitted.Add(input.Substring(startIndex, input.Length - startIndex));
53+
split.Add(input.Substring(startIndex, input.Length - startIndex));
5454

55-
return splitted.Where(argument => !argument.IsNullOrEmpty()).ToArray();
55+
return split.Where(argument => !argument.IsNullOrEmpty()).ToArray();
5656
}
5757

5858
/// <summary>

src/GitVersion.Core.Tests/BuildAgents/AzurePipelinesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void MissingEnvShouldNotBlowUp()
5151
{
5252
this.environment.SetEnvironmentVariable(key, null);
5353

54-
var semver = "0.0.0-Unstable4";
54+
const string semver = "0.0.0-Unstable4";
5555
var vars = new TestableVersionVariables(fullSemVer: semver);
5656
var vsVersion = this.buildServer.GenerateSetVersionMessage(vars);
5757
vsVersion.ShouldBe(semver);

src/GitVersion.Core.Tests/BuildAgents/DroneTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void GetCurrentBranchShouldUseSourceBranchFromCiCommitRefSpecInCaseOfPull
8686
const string droneSourceBranch = "droneSourceBranch";
8787
const string droneDestinationBranch = "droneDestinationBranch";
8888

89-
var ciCommitRefSpec = $"{droneSourceBranch}:{droneDestinationBranch}";
89+
const string ciCommitRefSpec = $"{droneSourceBranch}:{droneDestinationBranch}";
9090

9191
this.environment.SetEnvironmentVariable("DRONE_PULL_REQUEST", "1");
9292
this.environment.SetEnvironmentVariable("DRONE_SOURCE_BRANCH", "");
@@ -125,7 +125,7 @@ public void GetCurrentBranchShouldUseDroneBranchInCaseOfPullRequestAndEmptyDrone
125125
const string droneSourceBranch = "droneSourceBranch";
126126
const string droneDestinationBranch = "droneDestinationBranch";
127127

128-
var ciCommitRefSpec = $"{droneSourceBranch};{droneDestinationBranch}";
128+
const string ciCommitRefSpec = $"{droneSourceBranch};{droneDestinationBranch}";
129129

130130
this.environment.SetEnvironmentVariable("DRONE_PULL_REQUEST", "1");
131131
this.environment.SetEnvironmentVariable("DRONE_SOURCE_BRANCH", "");

0 commit comments

Comments
 (0)