Skip to content

Commit 729ef8d

Browse files
committed
Clean up more analyzer warnings
1 parent c407371 commit 729ef8d

File tree

82 files changed

+223
-225
lines changed

Some content is hidden

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

82 files changed

+223
-225
lines changed

Diff for: LibGit2Sharp.Tests/CommitFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToABlob()
406406
{
407407
AssertEnumerationOfCommits(
408408
repo => new CommitFilter { IncludeReachableFrom = repo.Tags["point_to_blob"] },
409-
new string[] { });
409+
Array.Empty<string>());
410410
}
411411

412412
[Fact]
@@ -421,7 +421,7 @@ public void CanEnumerateCommitsFromATagWhichPointsToATree()
421421

422422
AssertEnumerationOfCommitsInRepo(repo,
423423
r => new CommitFilter { IncludeReachableFrom = tag },
424-
new string[] { });
424+
Array.Empty<string>());
425425
}
426426
}
427427

Diff for: LibGit2Sharp.Tests/DiffTreeToTreeFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace LibGit2Sharp.Tests
99
{
1010
public class DiffTreeToTreeFixture : BaseFixture
1111
{
12-
private static readonly string subBranchFilePath = String.Join("/", "1", "branch_file.txt");
12+
private static readonly string subBranchFilePath = string.Join("/", "1", "branch_file.txt");
1313

1414
[Fact]
1515
public void ComparingATreeAgainstItselfReturnsNoDifference()
@@ -27,7 +27,7 @@ public void ComparingATreeAgainstItselfReturnsNoDifference()
2727
using (var patch = repo.Diff.Compare<Patch>(tree, tree))
2828
{
2929
Assert.Empty(patch);
30-
Assert.Equal(String.Empty, patch);
30+
Assert.Equal(string.Empty, patch);
3131
}
3232
}
3333
}

Diff for: LibGit2Sharp.Tests/FetchFixture.cs

+14-14
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void CanFetchIntoAnEmptyRepository(string url)
4242
}
4343

4444
// Perform the actual fetch
45-
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
45+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
4646

4747
// Verify the expected
4848
expectedFetchState.CheckUpdatedReferences(repo);
@@ -62,7 +62,7 @@ public void CanFetchIntoAnEmptyRepositoryWithCredentials()
6262
repo.Network.Remotes.Add(remoteName, Constants.PrivateRepoUrl);
6363

6464
// Perform the actual fetch
65-
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
65+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
6666
{
6767
CredentialsProvider = Constants.PrivateRepoCredentials
6868
}, null);
@@ -98,7 +98,7 @@ public void CanFetchAllTagsIntoAnEmptyRepository(string url)
9898
}
9999

100100
// Perform the actual fetch
101-
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions
101+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions
102102
{
103103
TagFetchMode = TagFetchMode.All,
104104
OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler
@@ -179,7 +179,7 @@ public void FetchRespectsConfiguredAutoTagSetting(TagFetchMode tagFetchMode, int
179179
r => r.TagFetchMode = tagFetchMode);
180180

181181
// Perform the actual fetch.
182-
Commands.Fetch(repo, remoteName, new string[0], null, null);
182+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), null, null);
183183

184184
// Verify the number of fetched tags.
185185
Assert.Equal(expectedTagCount, repo.Tags.Count());
@@ -197,7 +197,7 @@ public void CanFetchAllTagsAfterAnInitialClone()
197197

198198
using (var repo = new Repository(clonedRepoPath))
199199
{
200-
Commands.Fetch(repo, "origin", new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
200+
Commands.Fetch(repo, "origin", Array.Empty<string>(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
201201
}
202202
}
203203

@@ -223,17 +223,17 @@ public void FetchHonorsTheFetchPruneConfigurationEntry()
223223

224224
// No pruning when the configuration entry isn't defined
225225
Assert.Null(clonedRepo.Config.Get<bool>("fetch.prune"));
226-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
226+
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
227227
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
228228

229229
// No pruning when the configuration entry is set to false
230230
clonedRepo.Config.Set<bool>("fetch.prune", false);
231-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
231+
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
232232
Assert.Equal(5, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
233233

234234
// Auto pruning when the configuration entry is set to true
235235
clonedRepo.Config.Set<bool>("fetch.prune", true);
236-
Commands.Fetch(clonedRepo, "origin", new string[0], null, null);
236+
Commands.Fetch(clonedRepo, "origin", Array.Empty<string>(), null, null);
237237
Assert.Equal(4, clonedRepo.Branches.Count(b => b.IsRemote && b.FriendlyName != "origin/HEAD"));
238238
}
239239
}
@@ -248,10 +248,10 @@ public void CannotFetchWithForbiddenCustomHeaders()
248248
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
249249

250250
const string knownHeader = "User-Agent: mygit-201";
251-
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
251+
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
252252
using (var repo = new Repository(clonedRepoPath))
253253
{
254-
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
254+
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
255255
}
256256
}
257257

@@ -265,10 +265,10 @@ public void CanFetchWithCustomHeaders()
265265
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
266266

267267
const string knownHeader = "X-Hello: mygit-201";
268-
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
268+
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
269269
using (var repo = new Repository(clonedRepoPath))
270270
{
271-
Commands.Fetch(repo, "origin", new string[0], options, null);
271+
Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null);
272272
}
273273
}
274274

@@ -282,10 +282,10 @@ public void CannotFetchWithMalformedCustomHeaders()
282282
string clonedRepoPath = Repository.Clone(url, scd.DirectoryPath);
283283

284284
const string knownHeader = "Hello world";
285-
var options = new FetchOptions { CustomHeaders = new String[] { knownHeader } };
285+
var options = new FetchOptions { CustomHeaders = new string[] { knownHeader } };
286286
using (var repo = new Repository(clonedRepoPath))
287287
{
288-
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", new string[0], options, null));
288+
Assert.Throws<LibGit2SharpException>(() => Commands.Fetch(repo, "origin", Array.Empty<string>(), options, null));
289289
}
290290
}
291291

Diff for: LibGit2Sharp.Tests/FilterBranchFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void CanRewriteTreesByInjectingTreeEntry()
234234

235235
AssertSucceedingButNotError();
236236

237-
Assert.Equal(new Commit[0],
237+
Assert.Equal(Array.Empty<Commit>(),
238238
repo.Commits
239239
.QueryBy(new CommitFilter {IncludeReachableFrom = repo.Branches})
240240
.Where(c => c["README"] != null

Diff for: LibGit2Sharp.Tests/FilterFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ private FileInfo CheckoutFileForSmudge(string repoPath, string branchName, strin
396396
return expectedPath;
397397
}
398398

399-
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, String content)
399+
private static FileInfo CommitFileOnBranch(Repository repo, string branchName, string content)
400400
{
401401
var branch = repo.CreateBranch(branchName);
402402
Commands.Checkout(repo, branch.FriendlyName);

Diff for: LibGit2Sharp.Tests/MetaFixture.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
8383
var typesWithDebuggerDisplayAndInvalidImplPattern = new List<Type>();
8484

8585
IEnumerable<Type> libGit2SharpTypes = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
86-
.Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Any());
86+
.Where(t => t.GetTypeInfo().GetCustomAttributes(typeof(DebuggerDisplayAttribute), false).Length != 0);
8787

8888
foreach (Type type in libGit2SharpTypes)
8989
{
@@ -110,7 +110,7 @@ public void TypesInLibGit2DecoratedWithDebuggerDisplayMustFollowTheStandardImplP
110110
}
111111
}
112112

113-
if (typesWithDebuggerDisplayAndInvalidImplPattern.Any())
113+
if (typesWithDebuggerDisplayAndInvalidImplPattern.Count != 0)
114114
{
115115
Assert.Fail(Environment.NewLine + BuildMissingDebuggerDisplayPropertyMessage(typesWithDebuggerDisplayAndInvalidImplPattern));
116116
}
@@ -131,7 +131,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
131131
continue;
132132

133133
var nonVirtualMethodNamesForType = GetNonVirtualPublicMethodsNames(type).ToList();
134-
if (nonVirtualMethodNamesForType.Any())
134+
if (nonVirtualMethodNamesForType.Count != 0)
135135
{
136136
nonTestableTypes.Add(type, nonVirtualMethodNamesForType);
137137
continue;
@@ -165,7 +165,7 @@ public void TypesInLibGit2SharpMustBeExtensibleInATestingContext()
165165
}
166166
}
167167

168-
if (nonTestableTypes.Any())
168+
if (nonTestableTypes.Count != 0)
169169
{
170170
Assert.Fail(Environment.NewLine + BuildNonTestableTypesMessage(nonTestableTypes));
171171
}
@@ -193,7 +193,7 @@ private static bool MustBeMockable(Type type)
193193
public void EnumsWithFlagsHaveMutuallyExclusiveValues()
194194
{
195195
var flagsEnums = typeof(IRepository).GetTypeInfo().Assembly.GetExportedTypes()
196-
.Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Any());
196+
.Where(t => t.GetTypeInfo().IsEnum && t.GetTypeInfo().GetCustomAttributes(typeof(FlagsAttribute), false).Length != 0);
197197

198198
var overlaps = from t in flagsEnums
199199
from int x in Enum.GetValues(t)
@@ -277,7 +277,7 @@ public void GetEnumeratorMethodsInLibGit2SharpMustBeVirtualForTestability()
277277
(!m.IsVirtual || m.IsFinal))
278278
.ToList();
279279

280-
if (nonVirtualGetEnumeratorMethods.Any())
280+
if (nonVirtualGetEnumeratorMethods.Count != 0)
281281
{
282282
var sb = new StringBuilder();
283283

@@ -306,7 +306,7 @@ public void NoPublicTypesUnderLibGit2SharpCoreNamespace()
306306
.Where(t => t.FullName != "LibGit2Sharp.Core.LeaksContainer")
307307
.ToList();
308308

309-
if (types.Any())
309+
if (types.Count != 0)
310310
{
311311
var sb = new StringBuilder();
312312

Diff for: LibGit2Sharp.Tests/NetworkFixture.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void CanMergeFetchedRefs()
249249
Assert.False(repo.RetrieveStatus().Any());
250250
Assert.Equal(repo.Lookup<Commit>("refs/remotes/origin/master~1"), repo.Head.Tip);
251251

252-
Commands.Fetch(repo, repo.Head.RemoteName, new string[0], null, null);
252+
Commands.Fetch(repo, repo.Head.RemoteName, Array.Empty<string>(), null, null);
253253

254254
MergeOptions mergeOptions = new MergeOptions()
255255
{
@@ -276,7 +276,7 @@ public void CanPruneRefs()
276276
using (var repo = new Repository(clonedRepoPath))
277277
{
278278
repo.Network.Remotes.Add("pruner", clonedRepoPath2);
279-
Commands.Fetch(repo, "pruner", new string[0], null, null);
279+
Commands.Fetch(repo, "pruner", Array.Empty<string>(), null, null);
280280
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);
281281

282282
// Remove the branch from the source repository
@@ -286,11 +286,11 @@ public void CanPruneRefs()
286286
}
287287

288288
// and by default we don't prune it
289-
Commands.Fetch(repo, "pruner", new string[0], null, null);
289+
Commands.Fetch(repo, "pruner", Array.Empty<string>(), null, null);
290290
Assert.NotNull(repo.Refs["refs/remotes/pruner/master"]);
291291

292292
// but we do when asked by the user
293-
Commands.Fetch(repo, "pruner", new string[0], new FetchOptions { Prune = true }, null);
293+
Commands.Fetch(repo, "pruner", Array.Empty<string>(), new FetchOptions { Prune = true }, null);
294294
Assert.Null(repo.Refs["refs/remotes/pruner/master"]);
295295
}
296296
}

Diff for: LibGit2Sharp.Tests/ReferenceFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ public void CanHandleInvalidArguments()
894894
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(null));
895895
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(null, repo.Commits.Take(2)));
896896
Assert.Throws<ArgumentNullException>(() => repo.Refs.ReachableFrom(repo.Refs, null));
897-
Assert.Empty(repo.Refs.ReachableFrom(new Commit[] { }));
897+
Assert.Empty(repo.Refs.ReachableFrom(Array.Empty<Commit>()));
898898
}
899899
}
900900
}

Diff for: LibGit2Sharp.Tests/RemoveFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void RemovingFileWithBadParamsThrows()
182182
{
183183
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, string.Empty));
184184
Assert.Throws<ArgumentNullException>(() => Commands.Remove(repo, (string)null));
185-
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, new string[] { }));
185+
Assert.Throws<ArgumentException>(() => Commands.Remove(repo, Array.Empty<string>()));
186186
Assert.Throws<ArgumentNullException>(() => Commands.Remove(repo, new string[] { null }));
187187
}
188188
}

Diff for: LibGit2Sharp.Tests/RepositoryFixture.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,13 @@ public void CanFetchFromRemoteByName()
212212
}
213213

214214
// Perform the actual fetch
215-
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
215+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { OnUpdateTips = expectedFetchState.RemoteUpdateTipsHandler }, null);
216216

217217
// Verify the expected state
218218
expectedFetchState.CheckUpdatedReferences(repo);
219219

220220
// Now fetch the rest of the tags
221-
Commands.Fetch(repo, remoteName, new string[0], new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
221+
Commands.Fetch(repo, remoteName, Array.Empty<string>(), new FetchOptions { TagFetchMode = TagFetchMode.All }, null);
222222

223223
// Verify that the "nearly-dangling" tag is now in the repo.
224224
Tag nearlyDanglingTag = repo.Tags["nearly-dangling"];

Diff for: LibGit2Sharp.Tests/StageFixture.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public void StagingFileWithBadParamsThrows()
265265
{
266266
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, string.Empty));
267267
Assert.Throws<ArgumentNullException>(() => Commands.Stage(repo, (string)null));
268-
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, new string[] { }));
268+
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, Array.Empty<string>()));
269269
Assert.Throws<ArgumentException>(() => Commands.Stage(repo, new string[] { null }));
270270
}
271271
}
@@ -362,7 +362,7 @@ public void IgnoredFilesAreOnlyStagedIfTheyreInTheRepo(string filename, FileStat
362362
using (var repo = new Repository(path))
363363
{
364364
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
365-
String.Format("{0}\n", filename));
365+
string.Format("{0}\n", filename));
366366

367367
Commands.Stage(repo, filename);
368368
Assert.Equal(expected, repo.RetrieveStatus(filename));
@@ -384,7 +384,7 @@ public void CanStageConflictedIgnoredFiles(string filename, FileStatus expected)
384384
using (var repo = new Repository(path))
385385
{
386386
File.WriteAllText(Path.Combine(repo.Info.WorkingDirectory, ".gitignore"),
387-
String.Format("{0}\n", filename));
387+
string.Format("{0}\n", filename));
388388

389389
Commands.Stage(repo, filename);
390390
Assert.Equal(expected, repo.RetrieveStatus(filename));

Diff for: LibGit2Sharp.Tests/TestHelpers/Constants.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public static string BuildPath()
6161
if (Environment.GetEnvironmentVariables().Contains(LibGit2TestPath))
6262
{
6363
Trace.TraceInformation("{0} environment variable detected", LibGit2TestPath);
64-
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as String;
64+
tempPath = Environment.GetEnvironmentVariables()[LibGit2TestPath] as string;
6565
}
6666

67-
if (String.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
67+
if (string.IsNullOrWhiteSpace(tempPath) || !Directory.Exists(tempPath))
6868
{
6969
Trace.TraceInformation("Using default test path value");
7070
tempPath = Path.GetTempPath();

Diff for: LibGit2Sharp.Tests/UnstageFixture.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ public void UnstagingFileWithBadParamsThrows()
251251
{
252252
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, string.Empty));
253253
Assert.Throws<ArgumentNullException>(() => Commands.Unstage(repo, (string)null));
254-
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, new string[] { }));
254+
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, Array.Empty<string>()));
255255
Assert.Throws<ArgumentException>(() => Commands.Unstage(repo, new string[] { null }));
256256
}
257257
}

0 commit comments

Comments
 (0)