Skip to content

Commit 23a093d

Browse files
committed
cleanup analyzers warnings
1 parent 6b77e33 commit 23a093d

File tree

74 files changed

+183
-222
lines changed

Some content is hidden

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

74 files changed

+183
-222
lines changed

src/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<RepositoryUrl>https://github.com/GitTools/GitVersion</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
2020

21-
<NoWarn>1591,8618</NoWarn>
21+
<NoWarn>1591,8618,SYSLIB10</NoWarn>
2222
<WarningsAsErrors>$(WarningsAsErrors);RS0016;RS0017;RS0022;RS0024;RS0025;RS0026;RS0027</WarningsAsErrors>
2323

2424
<DebugType>embedded</DebugType>

src/GitVersion.App.Tests/ArgumentParserTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,23 @@ public void NoPathAndLogfileShouldUseCurrentDirectoryTargetDirectory()
5757
public void HelpSwitchTest()
5858
{
5959
var arguments = this.argumentParser.ParseArguments("-h");
60-
Assert.IsNull(arguments.TargetPath);
61-
Assert.IsNull(arguments.LogFilePath);
60+
Assert.Multiple(() =>
61+
{
62+
Assert.That(arguments.TargetPath, Is.Null);
63+
Assert.That(arguments.LogFilePath, Is.Null);
64+
});
6265
arguments.IsHelp.ShouldBe(true);
6366
}
6467

6568
[Test]
6669
public void VersionSwitchTest()
6770
{
6871
var arguments = this.argumentParser.ParseArguments("-version");
69-
Assert.IsNull(arguments.TargetPath);
70-
Assert.IsNull(arguments.LogFilePath);
72+
Assert.Multiple(() =>
73+
{
74+
Assert.That(arguments.TargetPath, Is.Null);
75+
Assert.That(arguments.LogFilePath, Is.Null);
76+
});
7177
arguments.IsVersion.ShouldBe(true);
7278
}
7379

src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,31 @@ public override string ToString()
3131
{
3232
var arguments = new StringBuilder();
3333

34-
arguments.Append($" /targetpath \"{this.WorkingDirectory}\"");
34+
arguments.Append(" /targetpath \"").Append(this.WorkingDirectory).Append('\"');
3535

3636
if (!this.exec.IsNullOrWhiteSpace())
3737
{
38-
arguments.Append($" /exec \"{this.exec}\"");
38+
arguments.Append(" /exec \"").Append(this.exec).Append('\"');
3939
}
4040

4141
if (!this.execArgs.IsNullOrWhiteSpace())
4242
{
43-
arguments.Append($" /execArgs \"{this.execArgs}\"");
43+
arguments.Append(" /execArgs \"").Append(this.execArgs).Append('\"');
4444
}
4545

4646
if (!this.projectFile.IsNullOrWhiteSpace())
4747
{
48-
arguments.Append($" /proj \"{this.projectFile}\"");
48+
arguments.Append(" /proj \"").Append(this.projectFile).Append('\"');
4949
}
5050

5151
if (!this.projectArgs.IsNullOrWhiteSpace())
5252
{
53-
arguments.Append($" /projargs \"{this.projectArgs}\"");
53+
arguments.Append(" /projargs \"").Append(this.projectArgs).Append('\"');
5454
}
5555

5656
if (!this.LogFile.IsNullOrWhiteSpace())
5757
{
58-
arguments.Append($" /l \"{this.LogFile}\"");
58+
arguments.Append(" /l \"").Append(this.LogFile).Append('\"');
5959
}
6060

6161
arguments.Append(this.additionalArguments);

src/GitVersion.App.Tests/Helpers/ProgramFixture.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,4 @@ public VersionVariables? OutputVariables
9393
return VersionVariables.FromJson(json);
9494
}
9595
}
96-
9796
}

src/GitVersion.App.Tests/PullRequestInBuildAgentTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public async Task VerifyTravisCIPullRequest(string pullRequestRef)
131131
[TestCaseSource(nameof(PrMergeRefs))]
132132
public async Task VerifyBitBucketPipelinesPullRequest(string pullRequestRef)
133133
{
134-
135134
var env = new Dictionary<string, string>
136135
{
137136
{ BitBucketPipelines.EnvironmentVariableName, "MyWorkspace" },

src/GitVersion.App.Tests/UpdateWixVersionFileTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void WixVersionFileCreationTest()
2121
fixture.MakeACommit();
2222

2323
GitVersionHelper.ExecuteIn(fixture.RepositoryPath, arguments: " /updatewixversionfile");
24-
Assert.IsTrue(File.Exists(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName)));
24+
Assert.That(File.Exists(PathHelper.Combine(fixture.RepositoryPath, this.wixVersionFileName)), Is.True);
2525
}
2626

2727
[Test]

src/GitVersion.App/ArgumentParser.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public Arguments ParseArguments(string[] commandLineArguments)
4747
return args;
4848
}
4949

50-
var firstArgument = commandLineArguments.First();
50+
var firstArgument = commandLineArguments[0];
5151

5252
if (firstArgument.IsInit())
5353
{
@@ -188,7 +188,7 @@ private void ParseTargetPath(Arguments arguments, string? name, IReadOnlyList<st
188188
// If we've reached through all argument switches without a match, we can relatively safely assume that the first argument isn't a switch, but the target path.
189189
if (parseEnded)
190190
{
191-
if (name != null && name.StartsWith("/"))
191+
if (name?.StartsWith("/") == true)
192192
{
193193
if (Path.DirectorySeparatorChar == '/' && name.IsValidPath())
194194
{
@@ -223,7 +223,7 @@ private static bool ParseSwitches(Arguments arguments, string? name, IReadOnlyLi
223223

224224
if (name.IsSwitch("diag"))
225225
{
226-
if (value == null || value.IsTrue())
226+
if (value?.IsTrue() != false)
227227
{
228228
arguments.Diag = true;
229229
}
@@ -327,7 +327,6 @@ private static bool ParseConfigArguments(Arguments arguments, string? name, IRea
327327

328328
arguments.ShowConfiguration = value.IsTrue() || !value.IsFalse();
329329
return true;
330-
331330
}
332331

333332
private static bool ParseRemoteArguments(Arguments arguments, string? name, IReadOnlyList<string>? values, string? value)
@@ -579,7 +578,7 @@ private static NameValueCollection CollectSwitchesAndValuesFromArguments(IList<s
579578
string? currentKey = null;
580579
var argumentRequiresValue = false;
581580

582-
for (var i = 0; i < namedArguments.Count; i += 1)
581+
for (var i = 0; i < namedArguments.Count; ++i)
583582
{
584583
var arg = namedArguments[i];
585584

src/GitVersion.BuildAgents.Tests/Agents/BitBucketPipelinesTests.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void SetEnvironmentVariableForTest()
2222
this.environment.SetEnvironmentVariable(BitBucketPipelines.EnvironmentVariableName, "MyWorkspace");
2323
}
2424

25-
2625
[Test]
2726
public void CanNotApplyToCurrentContextWhenEnvironmentVariableNotSet()
2827
{
@@ -114,7 +113,6 @@ public void GetCurrentBranchShouldHandlePullRequests()
114113
result.ShouldBeNull();
115114
}
116115

117-
118116
[Test]
119117
public void WriteAllVariablesToTheTextWriter()
120118
{

src/GitVersion.BuildAgents.Tests/Agents/GitHubActionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public void GetSetParameterMessage()
106106
var result = this.buildServer.GenerateSetParameterMessage("GitVersion_Something", "1.0.0");
107107

108108
// Assert
109-
result.ShouldContain(s => true, 0);
109+
result.ShouldContain(_ => true, 0);
110110
}
111111

112112
[Test]

src/GitVersion.BuildAgents/Agents/BitBucketPipelines.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void WriteIntegration(Action<string?> writer, VersionVariables v
4545
public override string? GetCurrentBranch(bool usingDynamicRepos)
4646
{
4747
var branchName = EvaluateEnvironmentVariable(BranchEnvironmentVariableName);
48-
if (branchName != null && branchName.StartsWith("refs/heads/"))
48+
if (branchName?.StartsWith("refs/heads/") == true)
4949
{
5050
return branchName;
5151
}

src/GitVersion.BuildAgents/Agents/GitLabCi.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ internal class GitLabCi : BuildAgentBase
1414

1515
protected override string EnvironmentVariable => EnvironmentVariableName;
1616

17-
1817
public override string GenerateSetVersionMessage(VersionVariables variables) => variables.FullSemVer;
1918

2019
public override string[] GenerateSetParameterMessage(string name, string value) => new[]
@@ -36,5 +35,4 @@ public override void WriteIntegration(Action<string?> writer, VersionVariables v
3635

3736
File.WriteAllLines(this.file, GenerateBuildLogOutput(variables));
3837
}
39-
4038
}

src/GitVersion.BuildAgents/Agents/Jenkins.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,4 @@ public override void WriteIntegration(Action<string?> writer, VersionVariables v
4545
writer($"Outputting variables to '{this.file}' ... ");
4646
File.WriteAllLines(this.file, GenerateBuildLogOutput(variables));
4747
}
48-
4948
}

src/GitVersion.Core.Tests/Configuration/ConfigurationProviderTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
214214
configuration.AssemblyInformationalFormat.ShouldBe("{Major}.{Minor}.{Patch}");
215215
}
216216

217-
218217
[Test]
219218
public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
220219
{
@@ -253,9 +252,9 @@ public void VerifyAliases()
253252
{
254253
var configuration = typeof(GitVersionConfiguration);
255254
var propertiesMissingAlias = configuration.GetProperties()
256-
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null)
257-
.Where(p => p.GetCustomAttribute<JsonIgnoreAttribute>() == null)
258-
.Where(p => p.GetCustomAttribute<JsonPropertyNameAttribute>() == null)
255+
.Where(p => p.GetCustomAttribute<ObsoleteAttribute>() == null
256+
&& p.GetCustomAttribute<JsonIgnoreAttribute>() == null
257+
&& p.GetCustomAttribute<JsonPropertyNameAttribute>() == null)
259258
.Select(p => p.Name);
260259

261260
propertiesMissingAlias.ShouldBeEmpty();

src/GitVersion.Core.Tests/Core/GitVersionToolDirectoryTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public void SetUp()
1717
{
1818
this.workDirectory = PathHelper.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
1919
this.gitDirectory = Repository.Init(this.workDirectory).TrimEnd(Path.DirectorySeparatorChar);
20-
Assert.NotNull(this.gitDirectory);
20+
Assert.That(this.gitDirectory, Is.Not.Null);
2121
}
2222

2323
[TearDown]
@@ -44,7 +44,6 @@ public void FindsGitDirectory()
4444
}
4545
}
4646

47-
4847
[Test]
4948
public void FindsGitDirectoryInParent()
5049
{

src/GitVersion.Core.Tests/DocumentationTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public void ConfigurationDocumentationIsUpToDate()
3737
}
3838
}
3939

40-
4140
[Test]
4241
public void VariableDocumentationIsUpToDate()
4342
{
@@ -85,7 +84,7 @@ private static DirectoryInfo GetDocsDirectory()
8584
currentDirectory = currentDirectory.Parent;
8685
}
8786

88-
if (currentDirectory == null || !currentDirectory.Name.Equals("docs", StringComparison.Ordinal))
87+
if (currentDirectory?.Name.Equals("docs", StringComparison.Ordinal) != true)
8988
{
9089
throw new DirectoryNotFoundException("Couldn't find the 'docs' directory.");
9190
}

src/GitVersion.Core.Tests/Helpers/ExecutableHelper.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ public static class ExecutableHelper
88

99
public static string GetDotNetExecutable() => "dotnet";
1010

11-
public static string GetExecutableArgs(string args)
12-
{
13-
args = $"{PathHelper.Combine(GetExeDirectory(), "gitversion.dll")} {args}";
14-
return args;
15-
}
11+
public static string GetExecutableArgs(string args) => $"{PathHelper.Combine(GetExeDirectory(), "gitversion.dll")} {args}";
1612

1713
public static string GetTempPath() => PathHelper.Combine(GetCurrentDirectory(), "TestRepositories", Guid.NewGuid().ToString());
1814

src/GitVersion.Core.Tests/IntegrationTests/CreatingAFeatureBranchFromAReleaseBranchScenario.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ public void ShouldTreatTheMergeFromReleaseToDevelopLikeTheReleaseBranchHasNeverB
518518
fixture.Repository.DumpGraph();
519519
}
520520

521-
522521
[Test]
523522
public void ShouldOnlyTrackTheCommitsOnDevelopBranchForNextReleaseWhenReleaseHasBeenShippedToProduction()
524523
{

src/GitVersion.Core.Tests/IntegrationTests/DocumentationSamples.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ public void GitFlowSupportMinorRelease()
297297
Console.WriteLine(fixture.SequenceDiagram.GetDiagram());
298298
}
299299

300-
301300
[Test]
302301
public void GitHubFlowFeatureBranch()
303302
{

src/GitVersion.Core.Tests/IntegrationTests/HotfixBranchScenarios.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void PatchOlderReleaseExample()
9999
fixture.Repository.MakeACommit();
100100
fixture.AssertFullSemver("1.1.1-fix.1+3");
101101

102-
fixture.Repository.CreatePullRequestRef("feature/fix", "hotfix-1.1.1", normalise: true, prNumber: 8);
102+
fixture.Repository.CreatePullRequestRef("feature/fix", "hotfix-1.1.1", prNumber: 8, normalise: true);
103103
fixture.AssertFullSemver("1.1.1-PullRequest8.4");
104104
Commands.Checkout(fixture.Repository, "hotfix-1.1.1");
105105
fixture.Repository.MergeNoFF("feature/fix", Generate.SignatureNow());

src/GitVersion.Core.Tests/IntegrationTests/MainlineDevelopmentMode.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public void VerifyPullRequestsActLikeContinuousDelivery()
118118
fixture.AssertFullSemver("1.0.2-foo.0", configuration);
119119
fixture.MakeACommit();
120120
fixture.MakeACommit();
121-
fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, normalise: true, prNumber: 8);
121+
fixture.Repository.CreatePullRequestRef("feature/foo", MainBranch, prNumber: 8, normalise: true);
122122
fixture.AssertFullSemver("1.0.2-PullRequest8.3", configuration);
123123
}
124124

@@ -153,7 +153,7 @@ public void SupportBranches()
153153
fixture.AssertFullSemver("1.0.5-foo.1", configuration);
154154
fixture.MakeACommit();
155155
fixture.AssertFullSemver("1.0.5-foo.2", configuration);
156-
fixture.Repository.CreatePullRequestRef("feature/foo", "support/1.0", normalise: true, prNumber: 7);
156+
fixture.Repository.CreatePullRequestRef("feature/foo", "support/1.0", prNumber: 7, normalise: true);
157157
fixture.AssertFullSemver("1.0.5-PullRequest7.3", configuration);
158158
}
159159

src/GitVersion.Core.Tests/IntegrationTests/PullRequestScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void CanCalculatePullRequestChangesFromRemoteRepo()
4444
Commands.Checkout(fixture.Repository, fixture.Repository.CreateBranch("feature/Foo"));
4545
fixture.Repository.MakeACommit();
4646

47-
4847
fixture.Repository.CreatePullRequestRef("feature/Foo", MainBranch, normalise: true);
4948

5049
fixture.Repository.DumpGraph();

src/GitVersion.Core.Tests/IntegrationTests/ReleaseBranchScenarios.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,9 @@ public void CommitBeetweenMergeReleaseToDevelopShouldNotResetCount()
459459
fixture.AssertFullSemver("2.0.0-beta.4", configuration);
460460
}
461461

462-
public static void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
462+
[Test]
463+
[Ignore("Needs investigation")]
464+
public void ReleaseBranchShouldUseBranchNameVersionDespiteBumpInPreviousCommit()
463465
{
464466
using var fixture = new EmptyRepositoryFixture();
465467
fixture.Repository.MakeATaggedCommit("1.0");

src/GitVersion.Core.Tests/IntegrationTests/WorktreeScenarios.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,4 @@ public void UseWorktreeRepositoryForVersion()
2626
using var worktreeFixture = new LocalRepositoryFixture(new Repository(worktreePath));
2727
worktreeFixture.AssertFullSemver("1.0.0");
2828
}
29-
3029
}

src/GitVersion.Core.Tests/VersionCalculation/EffectiveBranchConfigurationFinderTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void When_getting_configurations_of_a_branch_with_tag_alpha_Given_branch_
115115
// Act
116116
var actual = unitUnderTest.GetConfigurations(developBranchMock, configuration).ToArray();
117117

118-
119118
// Assert
120119
actual.ShouldHaveSingleItem();
121120
actual[0].Branch.ShouldBe(mainBranchMock);

src/GitVersion.Core.Tests/VersionCalculation/VariableProviderTests.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public void ProvidesVariablesInContinuousDeliveryModeForPreRelease()
4444
semVer.BuildMetaData.ShortSha = "commitShortSha";
4545
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
4646

47-
4847
var configuration = new TestEffectiveConfiguration();
4948

5049
var vars = this.variableProvider.GetVariablesFor(semVer, configuration, false);
@@ -115,9 +114,7 @@ public void ProvidesVariablesInContinuousDeploymentModeForStable()
115114
semVer.BuildMetaData.ShortSha = "commitShortSha";
116115
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
117116

118-
var configuration = new TestEffectiveConfiguration(
119-
label: "ci", versioningMode: VersioningMode.ContinuousDeployment
120-
);
117+
var configuration = new TestEffectiveConfiguration(versioningMode: VersioningMode.ContinuousDeployment, label: "ci");
121118

122119
var vars = this.variableProvider.GetVariablesFor(semVer, configuration, false);
123120

@@ -212,7 +209,6 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranch()
212209
semVer.BuildMetaData.ShortSha = "commitShortSha";
213210
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
214211

215-
216212
var configuration = new TestEffectiveConfiguration();
217213

218214
var vars = this.variableProvider.GetVariablesFor(semVer, configuration, false);
@@ -237,7 +233,6 @@ public void ProvidesVariablesInContinuousDeliveryModeForFeatureBranchWithCustomA
237233
semVer.BuildMetaData.ShortSha = "commitShortSha";
238234
semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2014-03-06 23:59:59Z");
239235

240-
241236
var configuration = new TestEffectiveConfiguration(assemblyInformationalFormat: "{Major}.{Minor}.{Patch}+{CommitsSinceVersionSource}.Branch.{BranchName}.Sha.{ShortSha}");
242237

243238
var vars = this.variableProvider.GetVariablesFor(semVer, configuration, false);

src/GitVersion.Core/Agents/BuildAgentResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ private ICurrentBuildAgent ResolveInternal()
1919
{
2020
ICurrentBuildAgent instance = (ICurrentBuildAgent)this.buildAgents.Single(x => x.IsDefault);
2121

22-
foreach (var buildAgent in this.buildAgents.Where(x => x.IsDefault == false))
22+
foreach (var buildAgent in this.buildAgents.Where(x => !x.IsDefault))
2323
{
2424
try
2525
{

src/GitVersion.Core/BranchCommit.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public override int GetHashCode()
3333
{
3434
unchecked
3535
{
36-
return (Branch != null ? Branch.GetHashCode() : 0) * 397 ^ (Commit != null ? Commit.GetHashCode() : 0);
36+
return ((Branch?.GetHashCode()) ?? 0) * 397 ^ ((Commit?.GetHashCode()) ?? 0);
3737
}
3838
}
3939

0 commit comments

Comments
 (0)